
    %VjiG                    	   d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZ ddlZddlZddlZddlZddlmZ ddlmZ ddlmZ dd	lmZmZmZm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&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@ ddlAmBZBmCZC ddlDmEZE ddlFmGZGmHZH ddlImJZJmKZKmLZLmMZM 	 ddlNZOn# eP$ r dZOY nw xY w	 ddlQmRZR n# eP$ r dZRY nw xY werddlSmTZT  ejU        eV          ZWeXY                    ejZ        jZ        j[        ej\        j]        j^        ej\        j]        j_        ej\        jZ        j[        ej\        jZ        j`        eja        jb        eja        jc        ejd        je        jf        ejd        jg        jh        ejd        jg        ji        ejd        jg        jj        ejk        jl        jm        ej\        jn        jo        ej\        jn        jp        ej\        jn        jq        ej\        jn        jr        ej\        js        jt        eju        jk        jl        jm        ejv        jk        jl        jm        ejw        jx        jy        jz        g          Z{eXY                    ej|        g          Z}ej~        j        ejv        j        ejv        j        ej        j        ej        j        gZej        ej        j        eja        j        eja        j        ej~        j        ejv        j        ejv        j        ejA        j        ej        ej        ej        ej        ej        ej        ej        ej        ejw        j        j        j        ej        eja        j        ej\        j        ej        j        ej        j        gez   ZejA                                        r6e                    ejA        j        ejA        j        ejA        j        g           eXY                    e          ZeXY                    e          Zej        deXe
g e	f         ee         f         fd            ZeXY                    g d          Zeja        j        eja        j        eja        j        hZej        d             Z G d d e:          Z G d! d"e          Z G d# d$e          Z G d% d&e          Z G d' d(e          ZdS ))ak  
This module implements variable tracking for torch functions and operations during Dynamo tracing.

It provides classes to handle different types of torch operations:

TorchInGraphFunctionVariable: Handles torch.* functions that should be captured in the FX graph.
Provides special handling for constant folding, tensor methods, and torch function overrides.
Manages complex cases like out= variants and parameter construction.

TorchCtxManagerClassVariable: Handles torch context managers like torch.no_grad(), autocast, etc.
Provides implementations for entering/exiting these contexts during tracing.

DispatchKeySetVariable: Represents torch.DispatchKeySet for managing dispatch keys and
device-specific operations during tracing.

The module includes special handling for:
- Constant folding of pure functions
- Tensor method calls
- torch.nn.Parameter construction
- __torch_function__ overrides
- Context manager state tracking
- Device and dtype management

This is a core part of Dynamo's tracing system, translating torch operations into
traceable graph nodes while preserving correct semantics and handling edge cases.
    N)Sequence)AnyCallableOptionalTYPE_CHECKING)TracingContext)warning_once)"is_traceable_wrapper_subclass_type   )configgraph_break_hints	polyfills	variables)	PyCodegen)!can_convert_to_tracable_parameternew_parameter_placeholdertracable_create_parameter) get_registered_device_interfaces)raise_observed_exceptionunimplemented_v2)GuardBuilderinstall_guard)
AttrSourceCallFunctionNoArgsSourceSyntheticLocalSourceTorchSource)check_unspec_or_constant_argsguard_if_dynhas_torch_functionhashableproductproxy_args_kwargsunwrap_if_wrapper   )typestrVariableTracker)AutocastModeVariableProfilerContextVariableTorchFunctionDisableVariable)ConstDictVariable)DistributedVariableProcessGroupVariable)bind_args_cached)ListVariableTupleVariable)can_dispatch_torch_functiondispatch_torch_functionTensorWithTFOverrideVariableTorchFunctionModeStackVariable)_fsdp_param_group)InstructionTranslatorreturnc                     t           j        j        dt           j        j        dt           j        j        d t           j        j        j        dt           j        j        j	        dt           j
        j        dt           j        j        j        dt           j        j        dt           j        j        dt           j        j        dt           j        j        dt           j        j        j        j        diS )NFT)torchjitis_scripting
is_tracing_C_get_tracing_statefx_symbolic_traceis_fx_tracingis_fx_symbolic_tracingonnxis_in_onnx_export_dynamoexternal_utilsis_compiling_utilscompileris_dynamo_compilingis_exportingnnmodules
activation_is_make_fx_tracing     W/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/_dynamo/variables/torch.pytracing_state_functionsrR      s     			e#T . 7
$e$14!4#T*D#T#7 rP   )addsubmuldivsqrtc                  H   ddl m}  ddlm} t	          |                      |                                                                }t          j        t          j	        t          j
        t          j        t          j        t          j        h}|                    |           |S )Nr   )chain)get_overridable_functions)	itertoolsrY   torch.overridesrZ   setfrom_iterablevaluesr8   ones	ones_likezeros
zeros_likeemptyfullupdate)rY   get_overridable_functions_funcsmores       rQ   rZ   rZ      s    WWWWWW##$>$>$@$@$G$G$I$IJJKKE

%D 
LLLrP   c                   \     e Zd ZdZed             Zd fdZddZd	 Zd
 Z	ddZ
d Z xZS )BaseTorchVariablezHcommon base for all torch.* functions, classes, modules and other thingsc                 t    t          |                    t          j                              | ||          S Nsource)r   
make_guardr   FUNCTION_MATCHclsvaluero   s      rQ   create_with_sourcez$BaseTorchVariable.create_with_source   s6    f''(CDDEEEs5((((rP   r6   Nc                 H     t                      j        di | || _        d S )NrO   )super__init__rt   )selfrt   kwargs	__class__s      rQ   rx   zBaseTorchVariable.__init__   s+    ""6"""


rP   codegenr   c                    	 | j         j         d| j         j         }n'# t          $ r dt	          | j                    }Y nw xY wdt          j        dd|          z   }|                    |                    || j                              d S )N.
torch_obj___z[^a-zA-Z0-9_]+_)	rt   
__module____name__	ExceptionidrerT   extend_outputsetup_globally_cached)ry   r|   nameunique_var_names       rQ   reconstructzBaseTorchVariable.reconstruct   s    	1j+CCdj.ACCDD 	1 	1 	104:00DDD	1(93!E!EE))/4:FF	
 	
 	
 	
 	
s    !AAc                     | j         S Nrt   ry   s    rQ   as_proxyzBaseTorchVariable.as_proxy  
    zrP   c                     | j         S r   r   r   s    rQ   as_python_constantz$BaseTorchVariable.as_python_constant  r   rP   txr5   c                 j    t          | j        |          }t          j                            |          S r   )hasattrrt   r   ConstantVariablecreate)ry   r   r   results       rQ   call_obj_hasattrz"BaseTorchVariable.call_obj_hasattr
  s*    T**)00888rP   c                 V    | j         t          v rdS t          | j         dd           dk    S )NTr   math)rt   constant_fold_functionsgetattrr   s    rQ   can_constant_fold_throughz+BaseTorchVariable.can_constant_fold_through  s.    :0004tz<66&@@rP   r6   N)r|   r   r   r5   )r   r   __qualname____doc__classmethodru   rx   r   r   r   r   r   __classcell__r{   s   @rQ   rk   rk      s        RR) ) [)     
 
 
 
    9 9 9 9A A A A A A ArP   rk   c                   b     e Zd ZdZdefdZed             Zdddee	         dd	dd
f fdZ
 xZS )TorchCtxManagerClassVariablezLPoints to a context manager class in torch.* that dynamo has implementationsr6   c                     d| j          dS )NzTorchCtxManagerClassVariable()r   r   s    rQ   __repr__z%TorchCtxManagerClassVariable.__repr__  s    <tz<<<<rP   c                 n    t          |           } t          |           ot          |           o| t          v S r   )r#   callabler    supported_ctx_manager_classesr   s    rQ   is_matching_clsz,TorchCtxManagerClassVariable.is_matching_cls  s=     "%(( UOO  ;::	
rP   r   r5   argsrz   dict[str, VariableTracker]r&   c           
         ddl m}m}m}m}m}m}	m}
m}m	}m
}m}m} | j        t          j        u r{t!          |          dk    rRt#          |d         t$          j        j                  r-|	                    |d          }|                    |||          S |	                    |d          S | j        t          j        u r{t!          |          dk    rRt#          |d         t$          j        j                  r-|	                    |d          }|                    |||          S |	                    |d          S | j        t          j        u rCt!          |          dk    r0|	                    ||d                                         d          S | j        t          j        u rmt!          |          dk    rt!          |          dk    sJ t!          |          dk    r|d                                         nd}|
                    ||          S t7          j        | j                  rRt;          | j        t          j                  r3ddlm }  ||||j!        "                    d| j        d	i                     S | j        t          j#        j$        j%        t          j&        j#        j%        t          j'        j#        j%        fv rtQ          j        | j        ||          S | j        t          j)        j*        t          j)        j+        t          j,        j)        j*        t          j,        j)        j+        fv r)t[          t\          d
| j                   t_                      S | j        t          j0        j1        u s| j        t          j0        j2        u r2|s|rJ tg          j        || j        t          j0        j1        u           S | j        t          j4        j5        j6        u r+t!          |          dk    sJ |                    ||          S | j        t          j4        j7        j8        u r*t!          |          dk    sJ |                    |          S | j        t          j,        j9        j:        u r5t!          |          dk    sJ |                    |d |D                       S | j        t          j,        j9        j;        u r*t!          |          dk    sJ |                    |          S | j        t          j4        j7        j<        u r*t!          |          dk    sJ |                    |          S | j        t          j4        j7        j=        u r5t!          |          dk    sJ |                    |d |D                       S | j        t          j,        j>        j?        u rCt!          |          dk    sJ |                    ||d                                                   S t          b| j        t          jA        jB        u rJt!          |          dk    sJ |                    ||d         |d                                                   S | j        t          jC        jD        jE        jF        u rht          | j        || jH        ||          }|d                                         }|d                                         }|                    |||          S t                                          |||          S )Nr$   )!DisabledSavedTensorsHooksVariableDualLevelContextManager&FSDPParamGroupUseTrainingStateVariable&GradIncrementNestingCtxManagerVariable)GradInplaceRequiresGradCtxManagerVariableGradModeVariableInferenceModeVariable%JvpIncrementNestingCtxManagerVariableSDPAKernelVariableSetFwdGradEnabledContextManagerStreamVariable&VmapIncrementNestingCtxManagerVariabler   FT)initialized)wrap_fx_proxy_clscall_functionrO   z$Profiler function %s will be ignored)only_subclassr   c                 ,    g | ]}t          |          S rO   r   .0xs     rQ   
<listcomp>z>TorchCtxManagerClassVariable.call_function.<locals>.<listcomp>      ///Qa///rP   c                 ,    g | ]}t          |          S rO   r   r   s     rQ   r   z>TorchCtxManagerClassVariable.call_function.<locals>.<listcomp>  r   rP   backendsset_priority)J r   r   r   r   r   r   r   r   r   r   r   r   rt   r8   no_gradlen
isinstancer   	functionsBaseUserFunctionVariabler   r   enable_gradset_grad_enabledr   inference_modeinspectisclass
issubclassStreamtorch._dynamo.variables.builderr   outputcreate_proxyampautocast_modeautocastcudacpur'   profilerprofilerecord_functionautogradr	   logr(   r<   DisableTorchFunctionSubclassDisableTorchFunctionr)   
_functorchvmapvmap_increment_nestingeager_transformsjvp_increment_nesting
forward_ad_set_fwd_grad_enabled
dual_levelgrad_increment_nestingenable_inplace_requires_gradgraphdisable_saved_tensors_hooksr4   FSDPParamGroupuse_training_staterK   	attentionsdpa_kernel__wrapped__r-   ro   rw   )ry   r   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   ctxinf_moder   name_to_arg_mapr   r   r{   s                         rQ   r   z*TorchCtxManagerClassVariable.call_function*  s   	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 :&&4yyA~~*Q,E# #~ '--b%88((T6:::'..r5999Z5,,,4yyA~~*Q,E# #~ '--b$77((T6:::#**2t444Z5111c$ii1nn#**DG..00d +    Z5///t99>>c&kkQ&6&6&667:4yyA~~tAw113334H(//H===_TZ(( U	IZ
EL-Q-Q U	IIIIIII$$	&&#J	 	 	 	 ZI#,JN#IM"
 
 

 (.tz4HHHZ N"N*N#+N#3
 
 
 DdjQQQ*,,,J%(???zUX:::''''/6$*0U"U    Z5+0GGGt99>>>>9@@   Z5+<RRRt99>>>>8??CCCZ5>4JJJt99>>>>299//$///   Z5>4???t99>>>>*11"555Z5+<SSSt99>>>>9@@DDDJ%*;XXXt99>>>><CC//$///   Z5>/KKKt99>>>>4;;DG..00   )
/>QQQt99>>>>9@@DGT!W7799   Z58-9EEE.
BT6 O 'z2EEGGH*>:MMOOL%,,R<HHHww$$Rv666rP   )r   r   r   r   strr   staticmethodr   r   r&   r   r   r   s   @rQ   r   r     s        VV=# = = = = 
 
 \
C7#C7 'C7 -	C7
 
C7 C7 C7 C7 C7 C7 C7 C7 C7 C7rP   r   c                        e Zd ZdZdd fdZdefdZd Zee	j
        d                         Zdd	d
ee         ddddfdZddZedd            Zedd            Zd Zd Zd Z xZS )TorchInGraphFunctionVariablez@Points to a torch function/method that should be put in FX graphNr6   c                 p     t                      j        |fi | ddlm} | ||          }|| _        d S )Nr   )is_nonstrict_trace_callable)rw   rx   trace_rulesr  nonstrict_traceable)ry   rt   r  rz   r  r{   s        rQ   rx   z%TorchInGraphFunctionVariable.__init__  sY    ))&)))======&"="=e"D"D#6   rP   c                 (    d| j          d| j         dS )NzTorchInGraphFunctionVariable(z, nonstrict_traceable=r   )rt   r  r   s    rQ   r   z%TorchInGraphFunctionVariable.__repr__  s!    ltzllQUQillllrP   c                     | j         S r   r   r   s    rQ   get_functionz)TorchInGraphFunctionVariable.get_function  r   rP   c                    ?@ABCDEFGH i FFfd} ddl m} ddlm?m@mAmBmCmDm	E ddl
mGmH  | t                       	 	 dF?fd	            } | t           	 	 dFd
            } | t          j        j        j                  	 	 dFd            } | t          j        j        j        j                  dFd            } | t.          j                  dFd            } | t          j                  dFd            } | t          j        t          j        j                  dF?DEfd            } | t          j        t          j                  dF?Dfd            }	 | t          j                  dF?Dfd            }
 | t          j                  dFd            } | t@           dFDfd            } | t          j!        j"        j#        j$        t          j!        j"        j#        j%        t          j!        j"        j#        j&        t          j!        j"        j#        j'        t          j!        j"        j#        j(                  dFd            } | t          j)                  ?Afd            } | t          j*                  	 dG	 dF@fd            } | t          j+                  ?@fd            } | t          j,        j-                  ?fd            } | t          j,        j.                  ?fd            } | t          j        j/        t          j        j0        t          j        j1                  dF?fd            } | td          3                    d ti                      D                        dFBfd            } | t          j5                  dFDHfd            } | t          j6        j7                  dFd            } | t          j8        j9        j:                  	 	 dF?Dfd             } | t          j#        j;        j<                  dFd!            } | t          j!        j=                  dFd"            } | t          j        j>        j?        t          j        j>        j?        j@                  dHd$            } | t          j        j>        jA        t          j        j>        jA        j@                  dHd%            } | t          jB                  dFd&            } | t          jC                  Dfd'            } | t          jD                  	 	 dFd(            } | t          jE                  dFDfd)            } | t          jF                  dF?fd*            }  | |          dFGfd+            }!t          jH                    rMdd,lImJ}"mK}#mL}$mM}%mN}& dd-lOmP}'  | |"|#|$|&|%          	 	 dF?fd.            }( | |'jQ                  dFGfd/            }) | t          jR        jS                  	 dHd#d0	 dFd1            }* | t          j!        jT        jU                  dFd2            }+ | t          jV        jW        jX        jY                  dF?Cfd3            }, | t          jV        jW        jX        jZ                  dF?Cfd4            }- | t          jV        jW        jX        j[                  dF?Cfd5            }. | t          jV        jW        jX        j\                  dF?Cfd6            }/ | t          jV        jW        jX        j]                  dF?Cfd7            }0 | t          jV        jW        jX        j^                  dF?Cfd8            }1 | t          jV        jW        jX        j_                  dFCfd9            }2 | t          jV        jW        jX        j`                  dFCfd:            }3 | t          jV        jW        jX        ja                  dF?Cfd;            }4 | t          j,        jb        jc                  	 	 dFd<            }5 | t          j,        jd        je                  	 	 dFEfd=            }6 | t          jd        jf        jg                  	 	 dFd>            }7 | t          jh                  dFCDfd?            }8 | t          j,        ji                  	 	 dFd@            }9 | t          j,        jj                  	 	 dF?fdA            }: | t          j,        jk                  	 	 dF?fdB            }; | t          j,        jl                  dFdC            }< | t          jm        j                  dD             }= | t          jn                  	 	 dF?fdE            }>FS )IzBuild a dict from function -> method to handle it so that we are O(1)
        in terms of the number of function with special handling.c                  D      fd}t           d                   sJ |S )Nc                 8    D ]}|vs
J |            | |<   | S r   rO   )handlerfnfnshandlerss     rQ   	_registerzOTorchInGraphFunctionVariable._get_handlers.<locals>.register.<locals>._register  s;     + +BX---r---#*HRLLrP   r   )r   )r  r  r  s   ` rQ   registerz<TorchInGraphFunctionVariable._get_handlers.<locals>.register  sB          CF#####rP   r   )
SDPAParamsr$   )r   DeterministicAlgorithmsVariabler   StreamContextVariableSymNodeVariableTensorVariableUserDefinedObjectVariable)wrap_fx_proxyr   r   r5   c                 L   |s|rJ | j         t          j        j        t          j        j        j        t          j        j        t          j        j        t          j        j        fv r|	                                 
                    t                      | j                            S r   )rt   r8   rG   rF   rD   rE   rH   rI   rJ   mark_inconsistent_side_effectsr   rR   ry   r   r   rz   r   s       rQ   handle_tracing_state_functionszRTorchInGraphFunctionVariable._get_handlers.<locals>.handle_tracing_state_functions  s     *F***z),9+2+   11333#**+B+D+DTZ+PQQQrP   c                    |rJ | j         t          j        j        fv rt	          |          dk    sJ t          |d         t          j                  sJ |d         j        j	        j
        d         }|                      |          }t          |t          j        j                  rj|t          j                            t          j        j        j                  z
  t          j                            t          j        j        j                  z
  }t"                              |          S |rJ t"                              |                                            S )Nr$   r   example_value)rt   r8   r<   _dispatch_keysr   r   r   r  proxynodemeta_subclasses
FakeTensorDispatchKeySetDispatchKeyPythonPythonTLSSnapshotDispatchKeySetVariabler   )ry   r   r   rz   r  dkss         rQ   !handle_dispatch_key_set_functionszUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_dispatch_key_set_functions  s    :zeh57774yyA~~~~!$q'9+CDDDDD $Q 2 7 Hjj// mU->-IJJ (11%(2F2MNNO(11!H0B   .44S999x-44TZZ\\BBBrP   c                 d    t          j        |t          j                                                  S r   )r&   buildr8   	overridesget_default_nowrap_functionsry   r   r   rz   s       rQ   #handle_get_default_nowrap_functionszWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_default_nowrap_functions  s,     #(EO@@BB  rP   c                 j    |                     t          j        |t          j                  ||          S r   )inline_user_function_returnr&   r,  r   accumulate_gradr/  s       rQ   handle_accumulate_grad_zKTorchInGraphFunctionVariable._get_handlers.<locals>.handle_accumulate_grad_  s1    11%b)*CDDdF  rP   c                     t          ||          s4|                    t          j        |t          j                  ||          S d S r   )r   r2  r&   r,  r   radiansr/  s       rQ   handle_radianszBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_radians  sM    0v>> 55#)"i.?@@$   rP   c                 \    t          dddg t          j        t          j                   d S )Nz:Encountered torch.is_inference_mode_enabled during tracingr   z2torch.is_inference_mode_enabled() is not supportedgb_typecontextexplanationhints)r   r   FUNDAMENTALINFERENCE_MODE)ry   r   s     rQ    handle_is_inference_mode_enabledzTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_inference_mode_enabled%  sG    TP&2&5	     rP   c                     t          |          s=| j        t          j        j        u r:t          |          r*t          |j        d          r                    d          S                     d          S )N__torch_function__TF)r   rt   r8   r-  is_tensor_liker   r   )ry   r   argr   r  r  s      rQ   handle_is_tensorzDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_tensor1  sy    #~.. 6
eo<<<s$=>> =CI';<< = (..t444'..u555rP   c                 4   |}t          |          r|j        }| j        t          j        u r                    |j        j                  S | j        t          j        u r                    |j        j                  S t          d| j                   d S d S )Nzcalling )r   dtypert   r8   is_floating_pointr   
is_complexAssertionError)ry   r   input	input_argr   r  s       rQ   handle_is_floating_pointzLTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_floating_point<  s    
 I)^44 B9T:!888+229?3TUUUZ5#333+229?3MNNN()@DJ)@)@AAAB B9T9TrP   c                     t          |          r;|                                r'                    t          |j                            S t          |          r|                    |dg i           S d S )Nnumel)r   
valid_sizer   r!   sizecall_method)ry   r   rK  r   r  s      rQ   handle_numelz@TorchInGraphFunctionVariable._get_handlers.<locals>.handle_numelJ  s|    %00 >U5E5E5G5G >'..wuz/B/BCCCE>22 >((Wb"===> >rP   c                     t          |          dk    r|d         S t          dd| d| ddgt          j                   d S )	Nr$   r   z torch.compile call with > 1 argsargs=	, kwargs=zNAttempted to call `torch.compile` with > 1 args. Dynamo does not support this.z5Remove the torch.compile call or its additional args.r9  )r   r   r   SUPPORTABLEr/  s       rQ   handle_torch_compilezHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_compileR  sg    4yyA~~Aw:777v77lK&2	     rP   c                 X    t          |          sJ |                    |dg i           S NrQ  )r   rR  )ry   r   rK  r  s      rQ   handle_tensor_size_rewriteszOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_tensor_size_rewritesb  s3    e^44444$$RR888rP   c                 0    |                      |||          S r   )_call_ntupler/  s       rQ   handle_ntuplezATorchInGraphFunctionVariable._get_handlers.<locals>.handle_ntupleg  s     $$Rv666rP   c                 x    t          j                                       t          j                              S r   )r   _guards_singletonr   r8   is_grad_enabled)ry   r   r   r   s     rQ   handle_is_grad_enabledzJTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_grad_enabledq  s2    *<===#**5+@+B+BCCCrP   Fc                     |r:|                                 r&t          dd| d| ddgt          j                                       ||                                           S )NzCAttempted to use torch.use_deterministic_algorithms(warn_only=True)zmode=z, warn_only=Dynamo does not support this.zKRemove param warn_only in function call torch.use_deterministic_algorithms.r9  )r   r   r   rW  r   )ry   r   mode	warn_onlyr  s       rQ   #handle_use_deterministic_algorithmszWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_use_deterministic_algorithmsv  s      	Y99;; 	 aADAAiAA ?e*6	    399"d>U>U>W>WXXXrP   c                 x    t          j                                       t          j                              S r   )r   r`  r   r8   $are_deterministic_algorithms_enabled)ry   r   r   r  s     rQ   +handle_are_deterministic_algorithms_enabledz_TorchInGraphFunctionVariable._get_handlers.<locals>.handle_are_deterministic_algorithms_enabled  s2    9KLLL#**5+U+W+WXXXrP   c                 t    t          t          j                                       |j        j                  S r   )r   r)   r`  r   symbolic_torch_function_statetorch_function_subclass_enabledry   r   r   s     rQ    handle_is_torch_function_enabledzTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_enabled  s8    6HIII $**0P  rP   c                 v    t          t          j                                       |j        j                   S r   )r   r)   r`  r   rl  torch_function_mode_enabledrn  s     rQ   %handle_is_torch_function_all_disabledzYTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_all_disabled  s9    6HIII#**4PP  rP   c                     t          |          dk    r6t          |d         t                    r|d                             |          n|}                    t          d |D                                 S )Nr$   r   c              3   4   K   | ]}t          |          V  d S r   )r   r   s     rQ   	<genexpr>z`TorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_function.<locals>.<genexpr>  s+      99a&q))999999rP   )r   r   r/   unpack_var_sequencer   any)ry   r   r   elemsr   s       rQ   handle_has_torch_functionzMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_function  s|     t99>>ja-&H&H> Q++B/// 
 $**99599999  rP   c              3   *   K   | ]\  }}|j         V  d S r   )stream)r   r   device_interfaces      rQ   ru  z=TorchInGraphFunctionVariable._get_handlers.<locals>.<genexpr>  s>        'A' !'     rP   c                 0                         ||          S r   )r   )ry   r   r{  r  s      rQ   handle_device_interface_streamzRTorchInGraphFunctionVariable._get_handlers.<locals>.handle_device_interface_stream  s     )//F;;;rP   c                    t           j        s!t          ddt           j         ddg           t          s t          dddd	gt          j                    | |j        j        d
t          j	        gt          |i           R  d           S )NzEcall `torch.from_numpy` with `torch._dynamo.config.trace_numpy=False`ztrace_numpy=zcAttempted to call `torch.from_numpy` with config `torch._dynamo.config.trace_numpy` set to `False`.z4Change `torch._dynamo.config.trace_numpy` to `True`.r9  z)`torch.from_numpy` with NumPy unavailabler   z@Attempted to call `torch.numpy` but NumPy could not be imported.z9Check NumPy version and installation in your environment.r   )
target_clsr   r  r  )r   trace_numpyr   npr   
USER_ERRORr   r   r8   	as_tensorr"   )ry   r   r   r  r   s      rQ   handle_from_numpyzETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_numpy  s    %  c?6+=??M O
 
 
 
  	 G bS*5	    %$),bi,#O 'tR00  
 #	 	 	 	rP   c                     |S r   rO   )ry   r   the_type	the_values       rQ   handle_jit_annotatezGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_jit_annotate  s    rP   c                     |r
J d            t          |          s
J d            t          j        d|j        |j                  }                    t          j        j                            |                    S )Nz%Expect 1 input to cudnn.is_acceptablez2Expect input to cudnn.is_acceptable to be a tensorr   )rG  device)	r   r8   tensorrG  r  r   r   cudnnis_acceptable)ry   r   r  extra
tensor_inpr   r  s        rQ   handle_cudnn_is_acceptablezNTorchInGraphFunctionVariable._get_handlers.<locals>.handle_cudnn_is_acceptable  s     EEEEE9fn55  D 5 av|FMRRRJ#**$22:>>  rP   c                 6    t          j        j        |g|R i |S r   )r   BackwardHookVariabler   r/  s       rQ   handle_backward_hookzHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_backward_hook  s&    18MdMMMfMMMrP   c                 $     | j         |g|R i |S r   )call_nn_parameterr/  s       rQ   handle_parameterzDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_parameter  s%    )4)">t>>>v>>>rP   Nc                 <    ||                     |d|gi           S d S rZ  rR  self_r   ry   dims       rQ   handle_sym_sizezCTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_size  s,     ''FSE2>>> rP   c                 <    ||                     |d|gi           S d S )Nstrider  r  s       rQ   handle_sym_stridezETorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_stride  s*    ''HseR@@@ rP   c                    t          |          dk    rd|v rt          |          dk    rt          t          j                                      |g |dd          i           }t          t          j                                      |||d         gi           }t          t          j                                      ||d         |gi           S d S d S d S )N   rt   r$   r   )r   r   r8   rV   r   rU   rS   )ry   r   r   rz   r   s        rQ   handle_addcdivzBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_addcdiv  s    4yyA~~'V"3"3Fq8H8H 6ei@@NN$qrr(R  6ei@@NN12  4EI>>LLa&)2   ~"3"38H8HrP   c                     t          |          rit          t          j        j        j                                      ||gi           }t          t          j                                      |||g|          S d S r   )r   r   r8   opsaten_local_scalar_denser   re   )ry   r   rQ  
fill_valuerz   r   r  s         rQ   handle_fullz?TorchInGraphFunctionVariable._get_handlers.<locals>.handle_full  s}    *n55 5IN6 -ZL"55  4EJ??MMv  	 rP   c                     t          |          dk    rQt          |d         t                    s8|s8|                    t	          j        |t          j                  ||          S d S d S d S )Nr  r   )r   r   r.   r2  r&   r,  r   foreach_lerp_inplace)r   r   r   rz   s       rQ   "handle_inplace_foreach_lerp_scalarzVTorchInGraphFunctionVariable._get_handlers.<locals>.handle_inplace_foreach_lerp_scalar  sj     4yyA~~ja,&G&G~PV~55#)"i.LMM   ~~~~~rP   c                     t          |          dk    rLt          |d                   r8|s8|                    t          j        |t
          j                  ||          S d S d S d S )Nr   r   )r   r   r2  r&   r,  r   foreach_pow_scalar)r   r   r   rz   r  s       rQ   handle_foreach_pow_scalarzMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_foreach_pow_scalar#  sj     4yyA~~*T!Wn"E"E~f~55#)"i.JKK   ~~~~~rP   c                     |                                 r|                                s.t          |t          j                  r|                                r d           S d S d S r   )is_python_constantr   r   r   r  evaluate_expr)ry   r   	conditionmessager   s       rQ   handle_assertzATorchInGraphFunctionVariable._get_handlers.<locals>.handle_assert.  sz    ,,.. .93O3O3Q3Q .9i&?@@.++--. ('---	. . . .rP   c           
      ~     | |j         j        dt          j        j        gt          ||          R  |          S )Nr   )r  
param_vars)r   r   r8   r<   _SDPAParamsr"   )ry   r   r   rz   r  s       rQ   handle_sdpa_paramszFTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sdpa_params6  s\     =,bi,#H( 'tV44  
     rP   )_get_group_size_by_name_get_group_tag_rank_not_in_group$_resolve_group_name_by_ranks_and_tagget_process_group_ranks)DTensorc                    t          |          dk    r t          |d         t          f          sJ nat          |          dk    r4t          |d         t                    rt          |d                   sJ nt	          d| d| j                   d |D             } | j        | }t          j        ||          S )Nr$   r   r   zInvalid group value (z) for constant pg function c                 6    g | ]}|                                 S rO   r   )r   rD  s     rQ   r   znTorchInGraphFunctionVariable._get_handlers.<locals>.handle_constant_processgroup_functions.<locals>.<listcomp>h  s$     J J Jc!7!7!9!9 J J JrP   )r   r   r,   r.   rJ  rt   r&   r,  )ry   r   r   args_as_valueinvocation_resultr   s        rQ   &handle_constant_processgroup_functionszZTorchInGraphFunctionVariable._get_handlers.<locals>.handle_constant_processgroup_functionsL  s     t99>>%d1g0DFV/WXXXXXXYY!^^%d1g|<< Q!1B B     )1 1 1$(J1 1   !K JT J J J$.DJ$>!
 ',R1BCCCrP   c           
      ,    d |dd          D             d                                  D             fddD             }d fd	}d j        j        z   |_         | |j        j        d|gt          |d	         g|          R  
          S )Nc                 6    g | ]}|                                 S rO   r  r   s     rQ   r   zYTorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local.<locals>.<listcomp>t  s$     J J JA!5!5!7!7 J J JrP   r$   c                 F    i | ]\  }}|d v	||                                 S )shaper  r  r   kvs      rQ   
<dictcomp>zYTorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local.<locals>.<dictcomp>u  s@     # # #1 333 q++--333rP   c                 *    i | ]}|v ||         S rO   rO   )r   r  rz   s     rQ   r  zYTorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local.<locals>.<dictcomp>z  s+     ( ( (%&fAvayrP   r  c                 0     j         | gR i ||dS )Nr  r   )r   r  r  r  kwargs_as_valuery   s      rQ   fn_with_prim_typeszaTorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local.<locals>.fn_with_prim_types~  sK    %4:)  -<DIRX    rP   zprim r   r   r   r  )NN)itemsrt   r   r   r   r"   )	ry   r   r   rz   kwargs_to_be_proxiedr  r  r  r  s	   `  `  @@rQ   handle_from_localzETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_localp  s    !K Jabb J J J# # &# # #
( ( ( (*=( ( ($        /6
8K.K"+$}0")0'* +!!WI0   
 
 
 
rP   )layoutc                
   ddl m} |rE|                                t          j        k    r#t          dd| ddgt          j                   t          ||          s%t          dd	| dd
gt          j	                   d S d S )Nr$   )BaseListVariablez%Attempted to use strided NestedTensorzlayout=rd  zChange layout=torch.jagged.r9  z4Attempted to use `nested_tensor` with non-list inputztensor_list=z'Change `nested_tensor` with list input.)
listsr  r   r8   stridedr   r   rW  r   r  )ry   r   tensor_listr  r   rz   r  s          rQ   handle_nested_tensorzHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_nested_tensor  s     0///// 	&3355FF C.f.. ?5*6	    k+;<< 	 R8;88 ?A*5	     	 	rP   c                 "   t          |          t          |          z   dk    sKt          |          dk    rT|d                                         r<|d                                         dk    r t          dd| d| ddg	           d S d S d S d S )
Nr$   r   zOAttempted to use `torch.nn.functional.one_hot` with data-dependent output shaperU  rV  rd  zuExplicitly set the `num_classes` param of the function call `torch.nn.functional.one_hot` to something other than -1.r9  )r   r  r   r   r/  s       rQ   handle_one_hotzBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_one_hot  s    4yy3v;;&!++D		QG..00 G..00B66 m;D;;6;; ?T	     	 66rP   c                     t          |          rKt          j                            t          j        j        j                            |j	                            S t          |          r|S d S r   )
r   r   r   r   r8   r>   experimentalsymbolic_shapesguard_size_oblivioussym_numry   r   exprr   r  s      rQ   handle_guard_size_obliviouszOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_size_oblivious  sv    $00 	 !188H)9NN   
 D"233  rP   c                     t          |          rKt          j                            t          j        j        j                            |j	                            S t          |          r|S d S r   )
r   r   r   r   r8   r>   r  r  guard_or_truer  r  s      rQ   handle_guard_or_truezHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_or_true  sq    $00  !188H)9GGUU   D"233  rP   c                     t          |          rKt          j                            t          j        j        j                            |j	                            S t          |          r|S d S r   )
r   r   r   r   r8   r>   r  r  guard_or_falser  r  s      rQ   handle_guard_or_falsezITorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_or_false  sq    $00  !188H)9HHVV   D"233  rP   c                     t          |          rKt          j                            t          j        j        j                            |j	                            S t          |          r|S d S r   )
r   r   r   r   r8   r>   r  r  statically_known_falser  r  s      rQ   handle_statically_known_falsezQTorchInGraphFunctionVariable._get_handlers.<locals>.handle_statically_known_false  st    $00  188H)9PP   
 D"233  rP   c                 8   t          |          r|j        }n<t          |          r|j        }n$t          j        j                            d          t          j        	                    t          j
        j        j                            |                    S )Nzbranch not supported)r   r  rt   r8   rD   excUnsupportedr   r   r   r>   r  r  guard_scalarry   r   r  valr   r  s       rQ   r  z@TorchInGraphFunctionVariable._get_handlers.<locals>.guard_scalar  s    $00 LlD"233 Ljm'334JKKK-44%5BB3GG  rP   c                     t          |          rKt          j                            t          j        j        j                            |j	                            S t          |          r|S d S r   )
r   r   r   r   r8   r>   r  r  statically_known_truer  r  s      rQ   handle_statically_known_truezPTorchInGraphFunctionVariable._get_handlers.<locals>.handle_statically_known_true  st    $00  188H)9OO   
 D"233  rP   c                     t          fd|D                       r=                    |t          j        j        j        j        d |D              d           S d S )Nc              3   8   K   | ]}t          |          V  d S r   r   r   r   r  s     rQ   ru  zUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_and.<locals>.<genexpr>
  -      AAa:a11AAAAAArP   c              3   >   K   | ]}|                                 V  d S r   r   r   s     rQ   ru  zUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_and.<locals>.<genexpr>  *      661!**,,666666rP   r  )allr   r8   r>   r  r  sym_andry   r   termsr  s      rQ   handle_sym_andzBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_and  s{    AAAA5AAAAA &--H)9A66666 ! .    rP   c                     t          fd|D                       r=                    |t          j        j        j        j        d |D              d           S d S )Nc              3   8   K   | ]}t          |          V  d S r   r  r  s     rQ   ru  zTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_or.<locals>.<genexpr>  r  rP   c              3   >   K   | ]}|                                 V  d S r   r  r   s     rQ   ru  zTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_or.<locals>.<genexpr>  r  rP   r  )r  r   r8   r>   r  r  sym_orr  s      rQ   handle_sym_orzATorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_or  s{    AAAA5AAAAA &--H)9@66666 ! .    rP   c                     t          |          r|j        }nt          |          r|j        }nd S t          j                            t          j        j        j	        
                    |                    S r   )r   r  rt   r   r   r   r8   r>   r  r  has_static_valuer  s       rQ   handle_has_static_valuezKTorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_static_value  ss    $00 lD"233 j-44%5FFsKK  rP   c                 Z    ddl m} t          |                              |g ||          S )Nr   )_unsafe_set_version_counter)tensor_version_opr  r   r   )ry   r   r   rz   r  s        rQ   !handle_unsafe_set_version_counterzUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_unsafe_set_version_counter+  sA     HGGGGG/+ mB$001rP   c                 \     t           j        j                                                  S r   )r8   r<   r   peek_interpreter_stack)ry   r   r   rz   r  s       rQ   'handle_functorch_peek_interpreter_stackz[TorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_peek_interpreter_stack5  s.     -,#::<<  rP   c                 ~    |d         j         }t          t          j        j                            |                    S Nr   )rt   FuncTorchInterpreterVariabler8   r   pyfunctorchcoerce_cinterpreter)ry   r   r   rz   cinterpreters        rQ   0handle_functorch_pyfunctorch_coerce_cinterpreterzdTorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_pyfunctorch_coerce_cinterpreter?  s8      7=L/ ,@@NN  rP   c                     fdd }|r	|d         }nd|v r|d         }t          |          s@ |          r7t          t          j        j                                      |g ||          S d S d S )Nc                     t          | f          rdS t          | t          t          f          r t          fd| j        D                       S dS )NTc              3   .   K   | ]} |          V  d S r   rO   )r   ycheck_any_unspecs     rQ   ru  ztTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspec.<locals>.<genexpr>O  s/      DDq//22DDDDDDrP   F)r   r.   r/   rw  r  )r   r  r  r#  s    rQ   r#  zaTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspecJ  sb    a./!BCC !4L-#@AA !DDDDAGDDDDDD !5rP   r   data)r   r   r8   _refsr  r   )ry   r   r   rz   data_argr#  r  r  s        @rQ   handle_torch_tensorzGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensorH  s    	! 	! 	! 	! 	! 	! 	! H *76!!!&> h77 <L<LX<V<V  4EK4FGGUU$     rP   c                     |s|rJ |j         j        s t          ddddgt          j                   t          j        |           |j                                         S )Nz5Attempted to pop from empty torch function mode stackr   zTCalled `torch._C._pop_torch_function_stack` when torch function mode stack is empty.z0Do not pop from empty torch function mode stack.r9  )rl  
mode_stackr   r   r  r3   register_mutationpop_torch_function_moder/  s       rQ   handle_pop_torch_functionzMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_pop_torch_functionc  s~     *F***3> 	 S vJ*5	    +<R@@@3KKMMMrP   c                     t          |          dk    r|rJ t          j        |           |j                            |d                                        d           S Nr$   r   )r   r3   r*  rl  push_torch_function_moder   r  s       rQ   handle_push_torch_functionzNTorchInGraphFunctionVariable._get_handlers.<locals>.handle_push_torch_functionu  s]     t99>>&>>0*<R@@@,EEd1gNNN#**4000rP   c                 h    |s|rJ                      t          |j        j                            S r   )r   r   rl  r)  r  s       rQ   handle_len_torch_functionzMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_len_torch_function~  s?     *F***#**B4?@@  rP   c                     t          |          dk    r|rJ |d                                         }|dk    r|t          |j        j                  k     sJ |j        j        |         S r.  )r   r   rl  r)  )ry   r   r   rz   inds        rQ   handle_get_stack_atzGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_stack_at  sg    t99>>&>>0q',,..C!88c"*J*U&V&V V V VV3>sCCrP   c                    t          |          t          |          z   dk    s|r)d|vr%t          dd| d| dg t          j                   	 |r|d                                         }n|r|d                                         }nd }t          j        |          }n=# t          $ r0}t          d	d| d| d
g t          j        |           Y d }~nd }~ww xY w|@t          | j	                  }t          |                    t          j                             t          t                      |j                            dd          d                   }t%          j        |||          S )Nr$   r  z*improper torch.get_device_module argumentsrU  rV  z<torch.get_device_module accepts 1 optional argument `device`r9  r   z.bad device argument to torch.get_device_modulezAExpected valid string/torch.device argument ('cpu', 'cuda', etc.)r:  r;  r<  r=  from_excr~   )maxsplitr  )r   r   r   r  r   r8   get_device_moduler   r   ro   r   rp   r   ID_MATCHr   r   r   rsplitr&   r,  )	ry   r   r   rz   r  moduleero   
new_sources	            rQ   handle_get_device_modulezLTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_device_module  s   4yy3v;;&**v*(&:P:P H;D;;6;; ^*5	    "#H-@@BBFF "!!W7799FF!F088    L;D;;6;; c9-89         ~1$+>>f//0EFFGGG#v55cA5FFrJ J #(VZ@@@s   AB! !
C+&CCc                    t          j        |           |d                                         r/|d                                         t          j        |           nt          j        |                               d           S r  )r3   r*  r  r   clear_default_device!register_device_context_insertionr   r  s       rQ   handle_set_default_devicezMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_set_default_device  s~     +<R@@@Aw))++ UQ0J0J0L0L0T.CBGGGG.PQSTTT#**4000rP   r   )Fr   )otorch.backends.cudar  r   r   r  r   r  r  r  r  builderr  r   rR   dispatch_key_set_functionsr8   r-  r.  r   r  inductoraccumulate_grad_defaultr   r6  is_inference_mode_enabled	is_tensorrC  rH  rI  rO  compile!REWRITE_OPS_TO_TENSOR_SIZE_METHODrK   rL   utils_single_pair_triple
_quadruple_ntuplera  use_deterministic_algorithmsri  r<   _is_torch_function_enabled_is_torch_function_all_disabledr   has_torch_function_variadichas_torch_function_unarydictfromkeysr   
from_numpyr9   annotater   r  r  hooksBackwardHook	Parameterr  sym_sizeint
sym_strideaddcdivre   _foreach_lerp__foreach_pow_assertr+   is_available"torch.distributed.distributed_c10dr  r  r  r  r  torch.distributed.tensorr  
from_localnestednested_tensor
functionalone_hotr>   r  r  r  r  r  r  r  r  r  r  r  	_autogradr  r   r  r  r  r  _pop_torch_function_stack_push_on_torch_function_stack_len_torch_function_stack_get_function_stack_atr:  set_default_device)Ir  r  r  r*  r0  r4  r7  r@  rE  rM  rS  rX  r[  r^  rb  rg  rj  ro  rr  ry  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r,  r0  r2  r5  r@  rD  r   r  r   r  r  r  r  r  r  r   sI                                                                  @@@@@@@@@@rQ   _get_handlersz*TorchInGraphFunctionVariable._get_handlers  s   
 	 	 	 	 	 	322222	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	>=======	*,,	-	R-	R 	R 	R 	R 	R 
.	-	R 
-	.	C-	C 	C 	C 
/	.	C6 
%/>J	K	K		-		 		 		 
L	K		 
%)$5=	>	>	 	 	 
?	>	
 
$,			 	 	 
 		 
%1	2	2		 		 		 
3	2		 
%/5?#A	B	B	6 	6 	6 	6 	6 	6 	6 
C	B	6 
#

 

	B 	B 	B 	B 	B 	B	

 

	B 
%+			> 	> 	> 	> 	> 	> 
		> 
%-	 	 	 	 	 
!	 	 
4	5	9 	9 	9 	9 	9 
6	5	9 
H"*H"(H"*H"-H"*

 

	7 	7 	7

 

	7 
%'	(	(	D 	D 	D 	D 	D 
)	(	D 
%4	5	5?D	Y-	Y 	Y 	Y 	Y 	Y 
6	5	Y 
%<	=	=	Y 	Y 	Y 	Y 	Y 
>	=	Y 
%(5	6	6	 	 	 	 
7	6	 
%(:	;	;	 	 	 	 
<	;	 
O.O7O4

 


	 	 	 	 	

 


	 
]]  +K+M+M    

	< 	< 	< 	< 	<

 

	< 
%"	#	# 	  	  	  	  	  	 
$	# 	D 
%)$	%	%	 	 	 
&	%	 
%.&4	5	5	-	 	 	 	 	 	 
6	5	" 
%+#0	1	1	N 	N 	N 
2	1	N 
%($	%	%	? 	? 	? 
&	%	? 
%).)59>+B+F	G	G	? 	? 	? 
H	G	?
 
%).+UY^-F-J	K	K	A 	A 	A 
L	K	A 
%-	 	 	 	 	 
!	 	 
%*			 	 	 	 
		 
%&	'	'	*	 	 	 
(	'	 
%$	%	%	 	 	 	 	 
&	%	 
%-	 	 	. 	. 	. 	. 	. 
!	 	. 
*				 		 		 		 		 
			 +-- N	              988888X'"'4 D1D D D D D D: Xg())     *)B 
%,,	-	- 	
 	 	'	 	 	 
.	-	> 
%(%-	.	.	 	 	 
/	.	  
%('7L	M	M
	 
	 
	 
	 
	 
	 
N	M
	 
%('7E	F	F	 	 	 	 	 	 
G	F	 
%('7F	G	G	 	 	 	 	 	 
H	G	 
%('7N	O	O	 	 	 	 	 	 
P	O	 
%('7D	E	E		 		 		 		 		 		 
F	E		 
%('7M	N	N	 	 	 	 	 	 
O	N	 
%('7?	@	@	 	 	 	 	 
A	@	 
%('7>	?	?	 	 	 	 	 
@	?	 
%('7H	I	I
	 
	 
	 
	 
	 
	 
J	I
	 
%($@	A	A	1-	1 	1 	1 
B	A	1 
%(%<	=	=	-	 	 	 	 	 
>	=	 
%".B	C	C	-	 	 	 
D	C	 
%,			 	 	 	 	 	 
 		4 
%(4	5	5	N-	N 	N 	N 
6	5	N" 
%(8	9	9	1-	1 	1 	1 	1 	1 
:	9	1 
%(4	5	5	-	 	 	 	 	 
6	5	 
%(1	2	2	D 	D 	D 
3	2	D 
%)5	6	6#	A #	A 
7	6#	AJ 
%*	+	+	1-	1 	1 	1 	1 	1 
,	+	1$ rP   r   r5   r   rz   r   r&   c                   234 ddl m}m2m} ddlm} | j        r,dd lmc m	} ddlm
}m}	 ddlm3 ddlm}
 ddlm} t%          j        |t%          j        ||          t)          j        ||          f          }t+          j        |
                              ||gi           }t1          |t$                    rt3          |j                  d	k    sJ |j        \  }}t1          |t6                    sJ |j        D ]R}|                                } |	|          s1|                                j        }t=          d
d| dddg           Sd |j        D             }	 |                                }n# |$ r}|j                                         }|j        }dd lm!c m"} |#                    |          r-t=          dd| d| dd| ddgtH          j%        |           n1t=          dd| d| dd| ddd| dgtH          j%        |           Y d }~nd }~ww xY w| j&        434fd} ||          \  }}|j'        (                    4j)         d|          }|j'        (                    4j)        d z   |          }tU          |          |j+        _*        tU          |          |j+        _*        ||g|R }|j'        ,                    d!||i           }	  |||          }n\# tZ          j.        j/        j0        tZ          j.        j/        j1        f$ r* t=          d"d#4j)         d$g tH          j%                   Y nw xY w|S | 2                    |||          rtg          || ||          S | 4                                rtk          ||          r
| j&        tl          v r@to          | j8                  }ts          |:                    tv          j<                             	 |=                     |                                 d% |D             i d& |                                D                       S # t|          t~          t          f$ rN} t          tU          |           |t          t          |j=        | jD                            '           Y d } ~ nd } ~ ww xY w| E                                r@| j&        j)        }!|rt1          |d         t*          j                  r|d         }"|"j8        t          tZ          jG        jH        |!          rt          tZ          jG        jH        |!          4t          4d(          rt          44J                                d                   rutZ          jK        jL        t          44J                                d                   jM        v r7t=          d)d*d+t          | j&                   d,g tH          j%        d-           | O                    |||          S | P                                Q                    | j&                  }#|#r |#| |g|R i |}$|$r|$S t          2fd.|D                       }%t          d/ |D                       }&t          | j&        d0d*          d1k    r| j&        j)        t          v ry|%rw|&rud2t          | j&                   d3}'t          W                    |'           t=          d4d5| j&         d6| d7| d8t          | j&                   d9g tH          j%                   | j&        }(|%rSd:| j&        j)         })t          | j&        d0d           d;k    r*t          tZ          |)          rt          tZ          |)          }(d }*d }+d<|v r|d<         }+t1          |+t$          t6          f          rZg }*|+j        D ]P},t1          |,t*          j                  r|,jX        j+        jY        d=         jZ        }-nd }-|*[                    |-           Qt1          |+t*          j                  r|+jX        j+        jY        d=         jZ        }* || |j'        j,        d!|(gt          ||          R  >          }.t1          |.|          rMd?|v rI|d?                                         r/t=          d@d5| j&         d6| d7| dAdBdCgtH          j%                   |*t1          |*t                    rt          |+j        |*          D ]\  }/}0|0t1          |/|          sJ |/jX        j+        jY        d=         }1|0|1jZ        k    rAt=          dDd5| j&         d6| d7| dE| j&         dF|0 dG|1jZ         d,g tH          j%                   tZ          j^        _                    |1          s-t=          dHdI| j&         d6| d7| dAg tH          j%                   nt1          |+|          sJ d=|+jX        j+        jY        v sJ |+jX        j+        jY        d=         }1|*|1jZ        k    rAt=          dJd5| j&         d6| d7| dE| j&         dF|* dG|1jZ         d,g tH          j%                   tZ          j^        _                    |1          s-t=          dKdI| j&         d6| d7| dAg tH          j%                   |.S )LNr$   )r   r  r  r  r   )func_to_graphableis_graphable_type)fake_tensor_tls)tree_flatten)#AsPythonConstantNotImplementedErrorr   z2Invalid input type for nonstrict_trace-ed functionzEncountered input of type <z>.zFor `nonstrict_trace`-ed functions, only basic types (e.g., torch.Tensor, int, float) or pytree containers of those are allowed as inputs. The provided argument contains an unsupported type.zUse one of the following to register the type with pytree:
* `torch.utils._pytree.register_constant`
* `torch.utils._pytree.register_dataclass`
* `torch.utils._pytree.register_pytree_node`r9  c                 6    g | ]}|                                 S rO   r  )r   flat_arg_vts     rQ   r   z>TorchInGraphFunctionVariable.call_function.<locals>.<listcomp>  s1     # # #+6$$&&# # #rP   zVInput marked with `pytree.register_constant` constructed in the `torch.compile` regionzInput=z, offending type <zWCalling a `nonstrict_trace`-ed function with an input that contains an object of type <z>, which was marked with `pytree.register_constant`. However, the object was constructed _inside_ the `torch.compile` region. This is not supported.zXConstruct the object _outside_ the `torch.compile` region, or submit an issue to GitHub.r7  z>Invalid use of pytree_flatten with nonstrict_trace-ed functionzCalling a `nonstrict_trace`-ed function where one of the inputs has been registered with a `pytree_flatten` that places an object of type <z> into the context.zLModifying the `pytree_flatten` to avoid placing the object into the context.zApply one of the following to <z>:
* `torch.utils._pytree.register_constant`
* `torch.utils._pytree.register_dataclass`
* `torch.utils._pytree.register_pytree_node`c                  ^    j         }d_         	  | i |}|_         n# |_         w xY w|S NT)allow_non_fake_inputs_override)r   rz   old_valresr{  r  s       rQ   
patched_fnz>TorchInGraphFunctionVariable.call_function.<locals>.patched_fn7  sS     *HAE>M"d-f--CELOBBWOBLLLL
s   ! 	*_spec_input_specr   z7Unsupported output type for nonstrict_trace-ed functionz
Function: zFor `nonstrict_trace`-ed functions, only basic types (e.g., torch.Tensor, int, list) are allowed as output. The result of this call contains an unsupported type.c                 6    g | ]}|                                 S rO   r  r   s     rQ   r   z>TorchInGraphFunctionVariable.call_function.<locals>.<listcomp>{  s$    ???Q!..00???rP   c                 >    i | ]\  }}||                                 S rO   r  r  s      rQ   r  z>TorchInGraphFunctionVariable.call_function.<locals>.<dictcomp>|  s*    PPPA1a2244PPPrP   )r   	overloadszInplace op on input tensorr   z6Attempted to trace an inplace view op on input tensor r~   z/Ensure you do not modify input tensor in place.c              3   8   K   | ]}t          |          V  d S r   r  r  s     rQ   ru  z=TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>  s-      &T&T!z!_'E'E&T&T&T&T&T&TrP   c              3   b   K   | ]*}t          |t          j        t          j        f          V  +d S r   )r   r   r   r  r   s     rQ   ru  z=TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>  sK       !
 !
 q95y7PQRR!
 !
 !
 !
 !
 !
rP   r   r8   zCalling z on only torch.SymInt arguments is not yet supported.
To support this behavior, we need to allow const-propping tensors that store symint data.
For now, dynamo will explicitly graph break when it encounters user code with this behavior.
zHAttempted to call torch in-graph function on only torch.SymInt argumentszfn=z, args=rV  zAttempted to call zc (that should be put in the FX graph) on only torch.SymInt arguments. Dynamo does not support this._sym_r   outr  r  requires_gradzAAttempted to use tensor creation function with requires_grad=Truerd  z.Create the tensor outside the compiled region.z Do not set `requires_grad=True`.z0Shape mismatch with out= list of tensor variantszShape mismatch when calling z% with `out=`. Provided `out=` shape: z. Actual shape: z?Attempted to call op with non-contiguous `out=` list of tensorszself.value=z'Shape mismatch with out= tensor variantz6Attempted to call op with non-contiguous `out=` tensor)`r   r   r  r  rF  r  r  "torch._higher_order_ops.flat_apply_higher_order_ops
flat_applyry  rz  torch._subclasses.fake_tensorr{  torch.utils._pytreer|  baser}  r/   r,  r*   r   UserFunctionVariabler   r   r   r  r.   python_typer   r   r   vtrO  _pytreeis_constant_classr   rW  rt   r   %register_static_attr_and_return_proxyr   typer   r   r8   rD   r  r  TorchRuntimeErrortorch_function_override_enabledr1   r   r   #constant_fold_functions_need_guardsr   ro   r   rp   r   EQUALS_MATCHr   OverflowError	TypeError
ValueErrorr   listmapr   is_tensor_methodr   r  r  r   r  Taginplace_viewtagsr%   call_tensor_methodrv  getrw  r  bin_opsr   r   warningr  r!  r  appendr"   zip_prims_commonis_contiguous)5ry   r   r   rz   r   r  r  r  ry  rz  r|  r}  packed_input_vtout_vtflat_args_vtsinput_spec_vtr  arg_type	type_nameproxified_flat_args
input_specr>  typpytreer  r   f_specf_spec_proxyinput_spec_proxyall_argsr  ro   r  r   
tensor_varspecial_handlerr   any_symints_or_symfloatsall_ints_or_floatsmsgfn_torch_sym_opsaved_out_shapesout_kwarg_vtr  r  tensor_variableout_tensor_vtsaved_out_shapefake_outr  r{  r  s5                                                     @@@rQ   r   z*TorchInGraphFunctionVariable.call_function  s    	HGGGGGGGGG******# Y	CCCCCCCCC        FEEEEE888888AAAAAA ,1](T224E4KBPV4W4WX O 3LAAOO_%r F fm44OV\9J9Ja9O9O9OO+1<(M=m\:::::  -2  &2244((22  + 7 7 9 9 FI$ T Ki K K K3
K   $# #:G:M# # #'*==??

6 % % %d&&((,	444444444++C00  $ x W W W) W W Wj(1j j j
 w.: "#     % ` W W W) W W WuV_u u u kKi K K K /: "#   +%N B
 
 
 
 
 
 *)*55IAv 9JJ;%%%v L  "yNNm+Z    &*&\\L")-j)9)9!&$&6M9LMMH I**?JRTUUE
 'r511 !-!3	    !U666h ;-9:       M//D&AA 	C*2tT6BBB))++ 	0M&1
 1
 	 z@@@1$+>>f//0IJJKKK'..-D++--??$???PPPPP    "9j9   (IIc"2"938DDEE           "" 	=:&D 
47I,DEE !!W
$0WUY^T5R5R0 66BK00#Bq(9:: "I2"2r||~~a'899>? ? )$@$&(wahimisatat(w(w(w#!2!># Q#	    **2tV<<<,,..224:>> 	$_T2??????F #&&T&T&T&Tt&T&T&T#T#T   !
 !
!
 !
 !
 
 

 DJb11W<<
#w..( /" /	TZ  C
 KKbHdjHHHHHH4TZ 4 4 4&2
 
 
 
 j# 	384:#688Ltz<66&@@W|F F@ e\22  F??!%=L ,(EFF 3#% &, 3 3B!"i&>?? % " 2? C I $$++E2222 ,	(@AA W#/#5#:#?#P#V '-(")( #400  
 
 
 77	6))'::<< * [HdjHHHHHH;D6 '2		 	 	 	 ' *D11 B69 &$7 7 $ $2M? '. !%m^DDDDD,27<_MH&(.88 )$V$T$*$T$TT$T$TF$T$T!mtz !m !m:I!m !m[c[i!m !m !m#!2!>#
 
 
 
 !.<<XFF 
 )$e$\$*$\$\T$\$\TZ$\$\(G#!2!>#	   ;$L ",?????&,*<*A*FFFFF'-27H#x~55 % I Pdj P P P P P Pj4: j j6Fj jX`Xfj j j.:
 
 
 
 *88BB 
 % X Xdj X X X XPV X X$C.:	    sF   "E7 7H"<BHH"K* *AMM&AP9 9RARRc                 ~   | j         t          j        j        j        j        u r|d                                         n| j         j        d         j        t          t                    sJ |rJ fd}| j         t          j        j        j        j        u rt          j        |          S  ||d                   S )z1inline behavior of torch.nn.modules.utils._ntupler   c                    |                                r4t          j        t          |                                                   S |                                 r`t          j                            t          j	        j
        j                                      |                                                     S t          dd|  ddg           d S )NzPAttempted to use `torch.nn.modules.utils._ntuple` with unsupported argument typezvalue=rd  z:Change use of _ntuple with argument as constant or tensor.r9  )has_unpack_var_sequencer   r/   r  rv  r  r   r   r8   rK   rL   rO  rT  r   r   )rt   countr   s    rQ   r^  z@TorchInGraphFunctionVariable._call_ntuple.<locals>.handle_ntupleb  s    ,,R00  .2226677   ))++  188H$*22599%:R:R:T:TUU   !n,U,, ?T	     rP   )rt   r8   rK   rL   rO  rT  r   __closure__cell_contentsr   rb  r   LambdaVariable)ry   r   r   rz   r^  r  s    `   @rQ   r]  z)TorchInGraphFunctionVariable._call_ntupleY  s    :)/777G..00EEJ*1-;E%%%%%%z	 	 	 	 	 	( :)/777+M::: =a)))rP   Tc           
      j   |j         r t          ddddgt          j                   t	          |t
          j                  rI	 |                                }n3# t          $ r& t          dd| ddgt          j	                   Y nw xY wt	          |t
          j
                  s#t          d	d
| ddgt          j	                   |j        r|                     |||          S t          j        r!t          dddddgt          j                   t	          |t                    st!          |j                  r,t          dt%          |          dg t          j                   t'                      s t          ddddgt          j                   	 t+          |                    |d                                                    }|                    |d                                          }|                    |d                                          }n;# t          $ r.}t          dd
| ddgt          j	        |           Y d}~nd}~ww xY w|j                            t2          ||||g          }|j        r|                    |dg i           }ddlm}	  |	||j                            dt>          |                                 |                                 fi           |j                   }
t	          |
t
          j
                  sJ tB          j"        j#        |
_        d!|
_$        |
S )"z>A call to torch.nn.Parameter() gets lifted to before the graphz3Attempted to use `torch.nn.Parameter()` with exportr   rd  z.Do not use `torch.nn.Parameter()` with export.r9  z=non-constant `requires_grad` argument to `torch.nn.Parameter`zrequires_grad=z$Change `requires_grad` to be a bool.z1`torch.nn.Parameter()` with unsupported data typezdata=z7Called `torch.nn.Parameter()` with non-Tensor argument.zBEnsure the argument to `torch.nn.Parameter()` is a `torch.Tensor`.z?Attempted to use `torch.nn.Parameter()` constructor with DynamozDynamo does not support thiszDTry to construct `torch.nn.Parameter()` outside the compiled region.z@If this is not possible, turn `graph_break_on_nn_param_ctor` offzDAttempted to use torch.nn.Parameter constructor with tensor subclassz:`torch.nn.Parameter`: cannot convert to traceable tracablez+convert_tracable_parameter is set to False.zDCheck usage of context manager: do_not_convert_to_tracable_parameterr  rG  r  z8`torch.nn.Parameter` with non-constant Tensor attributeszBEnsure the Tensor argument's shape, dtype, and device are correct.r7  Ndetachr$   rx  r   rn   F)%exportr   r   rW  r   r   r&   r   NotImplementedErrorr  r  ro   _nn_param_via_prefix_insertr   graph_break_on_nn_param_ctorr2   r
   
class_typer   r   	DIFFICULTtuplevar_getattrr   synthetic_graph_inputr   r  rR  rF  r  r   r   r   r8   rK   r`  has_grad_fn)rs   r   r$  r  r  rG  r  r>  placeholderr  r   s              rQ   r  z.TorchInGraphFunctionVariable.call_nn_parameter{  s
    9 		M;D&2	    mY%>?? 	 - @ @ B B& 	 	 	 [<]<< ?>*5	     	 $	 899 		K&UX&1	    ; 	L222t]KKK. 	Y:ZV '2		 	 	 	 .
 
 
	/@@
	 ^D		;&2	    122 		TIZ&0	   	$**2w77JJLLMME$$R11DDFFE%%b(33FFHHFF" 
	 
	 
	R&;X&1 	 	 	 	 	 	 	 	 	
	 i55%ufm'L
 
  	:##B"b99D******I"")+"6"6"8"89	  %
 
 
 &)":;;;;;!H. # s+   A -BBBH 
I'$IIc                    | j                                         }| j         j        J t          | j         j                                      fd            |j                    t          j        |                                         dd           	                    |           | j         j
                                                                       |                                j        }|j        dvr't!          dd|j         dg t"          j                   t'          |          }t(          j                            | j                             |                                j                  |	          }t1          j        | ||          }|                                }t7          j                    j        j                            |           |S )
Nc                  0                          dd          S )Nztorch.nnr`  )load_import_from)cgs   rQ   <lambda>zJTorchInGraphFunctionVariable._nn_param_via_prefix_insert.<locals>.<lambda>  s    !4!4Z!M!M rP   r   F)r  get_attrzAUnexpected type of data placeholder op for parameter constructionzdata_node.op=z/Data node op should be placeholder or get_attr.r9  )r  ) r   new_varroot_txr   add_push_nullro   r   r   r   storepregraph_bytecodeextendget_instructionsr   r   opr   r   r  r   r8   rK   r`  example_value_from_input_noder&   r,  realizer   r  guards_contextdynamo_guardsremove_guards_with_source)	r   r$  r  varname	data_nodero   r  r   r  s	           @rQ   r  z8TorchInGraphFunctionVariable._nn_param_via_prefix_insert  s    )##%% y ,,,ry())
MMMMNNN
4;
9%m44555
E"""

	#**2+>+>+@+@AAAMMOO(	<:::[6	66M&0	    &g..**I33DMMOO4HII' + 
 
 !&r=&AA!! 	+9SS	
 	
 	
 rP   c                 |    |d                              ||                                 j        |dd          |          S )Nr   r$   )rR  r  r   r/  s       rQ   r  z/TorchInGraphFunctionVariable.call_tensor_method&  s7    Aw""2t'8'8':':'CT!""XvVVVrP   c                 2   ddl m} t          j        |                                           oMt          |                                 d          o+|                                 j        t          j        j	        k    p|                                  |            v S )Nr   )get_tensor_method__objclass__)
r  r  r   ismethoddescriptorr  r   r  r8   r<   
TensorBase)ry   r  s     rQ   r  z-TorchInGraphFunctionVariable.is_tensor_method)  s    333333 &t'8'8':':;; H))++^<<H!!##0EH4GG8   $5$5$7$77		8rP   c                     |                                  t                      v pAt          |                                  t          j        j        t          j        j        f          ot          |||          S r   )r  rZ   r   r8   _ops
OpOverloadOpOverloadPacketr0   r/  s       rQ   r  z<TorchInGraphFunctionVariable.torch_function_override_enabled2  sk    #<#>#>> !!##&
(CD < *"dF;;	<rP   r   r   r   r  )r   r   r   r   rx   r   r   r  r   	functoolscacherv  r   r&   r   r]  r   r  r  r  r  r  r   r   s   @rQ   r   r     su       JJ7 7 7 7 7 7 7m# m m m m   _D D _ \DLN#N 'N -	N
 
N N N N` *  *  *  *D ~ ~ ~ [~@ ' ' ' \'RW W W8 8 8< < < < < < <rP   r   c                   ~     e Zd ZdZed             Zed             Zd Zde	e
         deee
f         ddf fd	Z xZS )
r(  zrepresents torch.DispatchKeySetc                     t          | fi |S r   )r(  )rt   rz   s     rQ   r   zDispatchKeySetVariable.create?  s    %e66v666rP   c                 t    t          |                    t          j                              | ||          S rm   )r   rp   r   DISPATCH_KEY_SET_MATCHrr   s      rQ   ru   z)DispatchKeySetVariable.create_with_sourceC  s6    f''(KLLMMMs5((((rP   c                 
    |dv S )N)hasrO   )ry   r   s     rQ   is_constant_fold_methodz.DispatchKeySetVariable.is_constant_fold_methodH  s    wrP   r   rz   r6   r&   c           	         |                      |          rpt          ||          r`t          | j        |          }t          j                             |d |D             i d |                                D                       S |dk    r+t	          j        | j        	                                          S t                                          ||||          S )Nc                 6    g | ]}|                                 S rO   r  r   s     rQ   r   z6DispatchKeySetVariable.call_method.<locals>.<listcomp>X  s$    ;;;a**,,;;;rP   c                 >    i | ]\  }}||                                 S rO   r  r  s      rQ   r  z6DispatchKeySetVariable.call_method.<locals>.<dictcomp>Y  s*    LLLTQq!..00LLLrP   highestPriorityTypeId)r  r   r   rt   r   r   r   r  EnumVariabler  rw   rR  )ry   r   r   r   rz   methodr{   s         rQ   rR  z"DispatchKeySetVariable.call_methodK  s     ''-- 	N2O&3
 3
 	N TZ..F-44;;d;;;LLV\\^^LLL    ,,,)$**J*J*L*LMMMww""2tT6:::rP   )r   r   r   r   r   r   r   ru   r  r  r&   rZ  r   rR  r   r   s   @rQ   r(  r(  <  s        ))7 7 \7 ) ) [)  ; ?#	;
 S/)*; 
; ; ; ; ; ; ; ; ; ;rP   r(  c                   b     e Zd ZdZed             Zdee         dee	ef         ddf fdZ
 xZS )r  z<represents torch._functorch.pyfunctorch.FuncTorchInterpreterc                 t    t          |                    t          j                              | ||          S rm   )r   rp   r   r;  rr   s      rQ   ru   z/FuncTorchInterpreterVariable.create_with_sourced  s6    f''(=>>???s5((((rP   r   rz   r6   r&   c                    |dk    r+t          j        | j                                                  S |dk    r<|                    t          j        | j        j        j                  | g|z   |          S |dv r:t           j        	                     t          | j        |                                S |dk    r&|s|rJ t           j        	                    |d           S t                                          ||||          S )Nkeyprocess)level
batch_size
randomnesslower)r   r  rt   r  r2  r  r  __func__r   r   r   0TemporarilyPopInterpreterStackCtxManagerVariablerw   rR  )ry   r   r   r   rz   r{   s        rQ   rR  z(FuncTorchInterpreterVariable.call_methodi  s    5==)$*..*:*:;;;Y11.tz/A/JKK  
 :::-445NWTZ5N5N5P5PQQQW__*F***MTTD   ww""2tT6:::rP   )r   r   r   r   r   ru   r  r&   rZ  r   rR  r   r   s   @rQ   r  r  a  s        FF) ) [); ?#	;
 S/)*; 
; ; ; ; ; ; ; ; ; ;rP   r  )r   r   r   loggingr   r   collections.abcr   typingr   r   r   r   torch._Cr8   torch._refstorch.fxtorch.nntorch._guardsr   torch._loggingr	   torch.utils._python_dispatchr
   r   r   r   r   r   r|   r   create_parameter_opr   r   r   r|  r   r  r   r   guardsr   r   ro   r   r   r   r   rO  r   r   r   r    r!   r"   r#   r  r%   r&   ctx_managerr'   r(   r)   dictsr*   distributedr+   r,   r   r-   r  r.   r/   torch_functionr0   r1   r2   r3   numpyr  ModuleNotFoundError#torch.distributed.fsdp._fully_shardr4   torch._dynamo.symbolic_convertr5   	getLoggerr   r   rZ  r[  r   r   r   r   r   r   r   r<   r   r   r   r   r   r   r   r   r   r   r   r   	grad_moder   r   r   r   r   r   r   r   rK   r   r   r   r   _shape_as_tensorrN  acceleratorcurrent_device_indexcurrent_deviceis_initializedxpur  rg  rG   _get_device_index_get_cublas_allow_tf32_is_any_autocast_enabledrh  get_device_propertiesget_autocast_dtypeget_autocast_gpu_dtypeget_default_dtypeis_autocast_cache_enabledis_autocast_cpu_enabledis_autocast_enabledrI  rH  rn  
_Reductionget_enumpromote_types_get_privateuse1_backend_name_is_checkpoint_validr   r  get_rankget_world_sizer  boolrR   r  r  _dispatch_tls_local_include_set_dispatch_tls_local_exclude_setrG  rZ   rk   r   r   r(  r  rO   rP   rQ   <module>rJ     s   6        				 $ $ $ $ $ $ 9 9 9 9 9 9 9 9 9 9 9 9        ( ( ( ( ( ( ' ' ' ' ' ' K K K K K K > > > > > > > > > > > >               
 @ ? ? ? ? ? < < < < < < < < 0 0 0 0 0 0 0 0                             + * * * * * * *         
 % $ $ $ $ $ B B B B B B B B ' ' ' ' ' ' . . . . . . . .              	BBBEEEEEEE     EDDDDDD g!! $'!7!,'/-%4)@)?)F	( , / ( 18	#,
$- 	&27! ! B %)MM% % ! 
*	J	J	I	I' # 
M	L"	H#	H%	"	J$	J	"		 		#	!				H"+		H*	N'	I#	I-. (/( 0 	!!## "",&,	
   '+mm4W&X&X #--(?@@  hr3w&7$&G!H    $ --<<<
=
= 
H	H,	H,    $#A #A #A #A #A #A #A #ALY7 Y7 Y7 Y7 Y7#4 Y7 Y7 Y7xI< I< I< I< I<#4 I< I< I<X,"; "; "; "; ";. "; "; ";J; ; ; ; ;#4 ; ; ; ; ;s$   C C%$C%)C0 0C:9C: