
    קgp                         d dl Z d dlZd dlZd dlmZ d dlZd dlmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ  ej        e          Z G d d          Zd	 Zd
 Zd Zdej        fdZdej        fdZdS )    N)patchdisable)countersdefakeflatten_graph_inputs)aot_module_simplified)_disable_current_modesc                   6    e Zd ZddZdej        j        fdZdS )AotAutogradreturnNc                 "    d| _         || _        d S )Ncompiler_fn)__name__kwargs)selfr   s     Y/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/_dynamo/backends/common.py__init__zAotAutograd.__init__   s    %    gmc                   
 |rt                               d|           t          d |D                       rt          |||           S t	          | j                            d                    r | j        d                     | j        d<   t          d         dxx         dz  cc<   d}|r7t                               d           t          d         d	xx         dz  cc<   |S 
fd
}| j                            d          p| j        d         
|| j        d<   | j                            d          p| j        d         | j        d<   ddl	m
} ddlm} | j                            dd           |k    rt          dd          }nt          j                    }	  |            5  |5  t!          ||fi | j        }	t          d         dxx         dz  cc<   t#          |	          cd d d            cd d d            S # 1 swxY w Y   d d d            d S # 1 swxY w Y   d S # t$          $ r t          d         d	xx         dz  cc<    w xY w)Nz3aot_autograd-based backend ignoring extra kwargs %sc              3   Z   K   | ]&}t          |t          t          t          f          V  'd S N)
isinstancelisttupledict).0xs     r   	<genexpr>z'AotAutograd.__call__.<locals>.<genexpr>   s3      JJaz!dE4011JJJJJJr   decompositionsaot_autogradtotal   Fz5Unable to use AOT Autograd because graph has mutationnot_okc                  H    t           t                    | i |          S r   r   )argsr   bw_compilers     r   _wrapped_bw_compilerz2AotAutograd.__call__.<locals>._wrapped_bw_compiler1   s)    /7;//@@@AAAr   r(   fw_compilerinference_compilerr   )nop)enable_aot_loggingz%functorch.compile.config.debug_assertTok)logwarninganyr   callabler   getr   debugfunctorch.compiler,   torch._inductor.debugr-   r   
contextlibnullcontextr	   r   	Exception)r   r   example_inputsr   use_fallbackr)   r,   r-   patch_configcgr(   s             @r   __call__zAotAutograd.__call__   sZ    	WKKMvVVVJJ>JJJJJ 	'   DKOO$45566 	L,IDK8H,I,K,KDK() 	 )))Q.))) 	IIMNNN^$X...!3...I	B 	B 	B 	B 	B koom44RM8R%9M"KOO011OT[5O 	() 	*)))))<<<<<< ;??=$//366 !H$OOLL%133L	##%% # #| # #*2~MMMM(...!3...r{{# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #  	 	 	^$X...!3...	sZ   
H  "H%=G;"H.H  ;G?	?HG?	HH  HH  HH   'I)r   N)r   
__module____qualname__r   torchfxGraphModuler>    r   r   r   r      sH           658/ 6 6 6 6 6 6r   r   c                      t          di | S )NrD   )r   )r   s    r   r"   r"   P   s         r   c                 4    ddl m}m}m} |||d}| r||d<   |S )Nr   )default_decompositions#min_cut_rematerialization_partition
ts_compile)r*   r(   partition_fnr!   )r5   rG   rH   rI   )use_decompsrG   rH   rI   r   s        r   mem_efficient_fusion_kwargsrL   T   se              "!;	 F  :#9 Mr   c                 F     t          j                    fd            }|S )zg
    Decorator for backends that need real inputs.  We swap out fake
    tensors for zero tensors.
    c                     t                      5  t          t          t          |                    } | |fi |cd d d            S # 1 swxY w Y   d S r   )r
   r   mapr   )modelinputsr   fns      r   wrapperz(fake_tensor_unsupported.<locals>.wrappern   s    #%% 	/ 	/#ff--..F2eV..v..	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   ,A		AA)	functoolswraps)rR   rS   s   ` r   fake_tensor_unsupportedrV   h   s:     _R/ / / / /
 Nr   r   c                 B    | D ]}t          |d          r	|j        c S d S )Ndevice)hasattrrX   r:   r   s     r   device_from_inputsr[   w   s=      1h 	8OOO	 r   c                 B    | D ]}t          |d          r	|j        c S d S )Ndtype)rY   r]   rZ   s     r   dtype_from_inputsr^   }   s=      1g 	7NNN	 r   )r7   rT   loggingunittest.mockr   rA   torch._dynamor   torch._dynamo.utilsr   r   r   torch._functorch.aot_autogradr	   torch.utils._python_dispatchr
   	getLoggerr   r/   r   r"   rL   rV   rX   r[   r]   r^   rD   r   r   <module>rf      sE                   ! ! ! ! ! ! F F F F F F F F F F ? ? ? ? ? ? ? ? ? ? ? ? g!!; ; ; ; ; ; ; ;|! ! !  (  %,          r   