
    ȅi                       S r SSKrSSKrSSKrSSKrSSKrSSKJrJrJ	r	  SSK
Jr  SSKJrJrJrJrJr  SSKrSSKrSSKrSSKrSSKJs  Jr  SSKJr  SSKJr  SSKJr  SS	KJ r   SS
K!J"r"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)J*r*J+r+J,r,  SSK-J.r.  SSK/J0r0J1r1J2r2  SSK3J4r4  SSK5J6r6J7r7  SSK8J9r9J:r:  SSK;J<r<J=r=J>r>J?r?  SSKJ@r@JArAJBrBJCrCJDrDJErEJFrFJGrG  SSKHJIrIJJrJJKrK  SSKLJMrMJNrNJOrOJPrP  SSKQJRrR  SSKSJTrTJUrU  SSKVJWrWJXrX  SSKYJZrZJ[r[  SSK\J]r]J^r^J_r_J`r`   SSKarb SSKdJere  \(       a  SSKfJgrg  SS KJhrh  \" S!5      ri\" S"5      rj\R                  " \l5      rm\nR                  \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                  GR                   \GR                  GR                  GR                  \R                  GR                  GR
                  \R                  GR                  GR                  \R                  GR                  GR                  \R                  GR                  GR                  \R                  GR                  GR                  \GR                  GR                  GR                  GR                  \GR                  GR                  GR                  GR                  \GR                  GR                  GR                  \GR                  GR                  GR                  GR                   \GR"                  GR$                  GR&                  GR                   /5      r\nR                  \GR*                  /5      r\GR.                  GR0                  \GR.                  GR2                  \GR                  GR4                  \GR                  GR6                  \GR8                  GR4                  \GR8                  GR6                  /r\GR<                  \GR>                  GR@                  \R                  GRB                  \R                  GRD                  \GR.                  GRF                  \GR                  GRH                  \GR                  GRF                  \R                  GRF                  \GRJ                  \GRL                  \GRN                  \GRP                  \GRR                  \GRT                  \GRV                  \GRX                  \GR"                  GRZ                  GR\                  GR^                  \GR`                  \R                  GRb                  \R                  GRd                  \GR8                  GRH                  \GR8                  GRF                  /\-   r\R                  GRG                  5       (       aT  \GRi                  \R                  GR6                  \R                  GRj                  \R                  GRl                  /5        \nR                  \5      r\nR                  \5      r\GRn                  S#\n\/ \4   \\   4   4S$ j5       r\nR                  / S%Q5      r\R                  GRv                  \R                  GRx                  \R                  GRz                  1r\GRn                  S#\\S&\4      4S' j5       r " S( S)\K5      r " S* S+\5      r " S, S-\5      r " S. S/\5      r " S0 S1\5      rg! \c a    Srb GNf = f! \c a    Sre GNf = f)2ak  
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)CallableIterableSequence)nullcontext)AnyNoReturnOptionalTYPE_CHECKINGTypeVar)DispatchKeySet)ConstantVariable)StreamVariable)TorchFunctionModeVariable)Source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)GuardBuilderinstall_guard)
AttrSourceCallFunctionNoArgsSourceSyntheticLocalSourceTorchSource)check_unspec_or_constant_argsguard_if_dynhas_torch_functionhashableis_wrapper_or_member_descriptorproductproxy_args_kwargsunwrap_if_wrapper   )raise_type_error_exctypestrVariableTracker)AutocastModeVariableProfilerContextVariable%ProfilerRecordFunctionContextVariableTorchFunctionDisableVariable)ConstDictVariable)DistributedVariableProcessGroupVariable)bind_args_cachedNestedUserFunctionVariable)ListVariableTupleVariable)can_dispatch_torch_functiondispatch_torch_functionTensorWithTFOverrideVariableTorchFunctionModeStackVariable)_fsdp_param_group)InstructionTranslator)TreeSpecVTreturnc                  "   [         R                  R                  S[         R                  R                  S[         R                  R
                  S [         R                  R                  R                  S[         R                  R                  R                  S[         R                  R                  S[         R                  R                  R                  S[         R                  R                  S[         R                   R                  S[         R                   R"                  S[         R                   R$                  S[         R                  R&                  R(                  S[         R*                  R,                  R.                  R0                  S0$ )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
eval_frame_is_in_optimized_modulennmodules
activation_is_make_fx_tracing     W/home/james-whalen/.local/lib/python3.13/site-packages/torch/_dynamo/variables/torch.pytracing_state_functionsrd      s     					e##T  ..  77

$$e$$114!!4##T**D##T  88$ 	##77# rb   )addsubmuldivsqrt.c                  R   SSK Jn   SSKJn  [	        U R                  U" 5       R                  5       5      5      n[        R                  [        R                  [        R                  [        R                  [        R                  [        R                  1nUR                  U5        U$ )Nr   )chain)get_overridable_functions)	itertoolsrk   torch.overridesrl   setfrom_iterablevaluesrH   ones	ones_likezeros
zeros_likeemptyfullupdate)rk   get_overridable_functions_funcsmores       rc   rl   rl      sp    W##$>$@$G$G$IJKE



%D 
LLLrb   c                      ^  \ rS rSrSr\S\S\SS 4S j5       rS\S\SS4U 4S	 jjr	SS
 jr
S\4S jrS\4S jrSSS\S\4S jrS\4S jrSrU =r$ )BaseTorchVariable   zHcommon base for all torch.* functions, classes, modules and other thingsvaluesourcerF   c                    [         R                  " U5      (       a*  [        UR                  [        R
                  5      5        GO|[         R                  " U5      (       a*  [        UR                  [        R                  5      5        GO7[         R                  " U5      (       a)  [        UR                  [        R                  5      5        O[         R                  " U5      (       dC  [        U[        R                  R                  [        R                  R                  45      (       a)  [        UR                  [        R                   5      5        Ol[#        U5      (       d3  [        U[        R$                  R&                  R(                  5      (       a  O([        UR                  [        R*                  5      5        U " XS9$ Nr   )inspectisclassr!   
make_guardr    CLASS_MATCHismoduleMODULE_MATCH
isfunctionCLOSURE_MATCH	isbuiltin
isinstancerH   _ops
OpOverloadOpOverloadPacketBUILTIN_MATCHr*   rT   compiled_autogradOpFUNCTION_MATCHclsr   r   s      rc   create_with_source$BaseTorchVariable.create_with_source  s)   ??5!!&++L,D,DEFe$$&++L,E,EFG&&&++L,F,FGHu%%EJJ))5::+F+FG*
 *
 &++L,F,FGH,U33z5==22558
 8
 &++L,G,GHI5((rb   kwargsNc                 2   > [         TU ]  " S0 UD6  Xl        g )Nra   )super__init__r   )selfr   r   	__class__s      rc   r   BaseTorchVariable.__init__  s    "6"
rb   c                 >    U R                   R                   SU R                   R                   3nS[
        R                  " SSU5      -   nUR                  UR                  X0R                   5      5        g ! [         a    S[	        U R                   5       3n Njf = f)N.
torch_obj___z[^a-zA-Z0-9_]+_)	r   
__module____name__	Exceptionidrerf   extend_outputsetup_globally_cached)r   codegennameunique_var_names       rc   reconstructBaseTorchVariable.reconstruct  s    	1jj++,Adjj.A.A-BCD (93!EE))/::F	
  	14::/0D	1s   /A7 7"BBc                     U R                   $ Nr   r   s    rc   as_proxyBaseTorchVariable.as_proxy%      zzrb   c                     U R                   $ r   r   r   s    rc   as_python_constant$BaseTorchVariable.as_python_constant(  r   rb   txrB   r   c                 l    [        U R                  U5      n[        R                  R	                  U5      $ r   )hasattrr   r   r   create)r   r   r   results       rc   call_obj_hasattr"BaseTorchVariable.call_obj_hasattr+  s+     T*))0088rb   c                     U R                   [        ;   a  gU R                   [        R                  R                  L a  [
        R                  (       a  g[        U R                   SS 5      S:H  $ )NTr   math)r   constant_fold_functionsrH   autograd_profiler_enabledr   'constant_fold_autograd_profiler_enabledgetattrr   s    rc   can_constant_fold_through+BaseTorchVariable.can_constant_fold_through1  sP    ::00 JJ%..:::>> tzz<6&@@rb   r   )r   r   rF   N)r   r   __qualname____firstlineno____doc__classmethodr   r   r   r   r   r   r   strr   r   boolr   __static_attributes____classcell__r   s   @rc   r}   r}      s    R)s )F )?R ) )(c S T 
# C 9)9149	9A4 A Arb   r}   c                   p   ^  \ rS rSrSrS\4S jr\S\S\	4S j5       r
SSS	\\   S
SSS4U 4S jjrSrU =r$ )TorchCtxManagerClassVariableiK  zLPoints to a context manager class in torch.* that dynamo has implementationsrF   c                 "    SU R                    S3$ )NzTorchCtxManagerClassVariable()r   r   s    rc   __repr__%TorchCtxManagerClassVariable.__repr__N  s    .tzzl!<<rb   r   c                 r    [        U 5      n [        U 5      =(       a    [        U 5      =(       a	    U [        ;   $ r   )r-   callabler)   supported_ctx_manager_classesr   s    rc   is_matching_cls,TorchCtxManagerClassVariable.is_matching_clsQ  s6     "%( UO  ;::	
rb   r   rB   argsr   dict[str, VariableTracker]r1   c           
        > SSK JnJnJnJnJnJn	Jn
JnJ	nJ
nJnJnJn  U R                  [        R                   L aq  [#        U5      S:X  aP  [%        US   [&        R(                  R*                  5      (       a$  U
R-                  US5      nUR/                  XU5      $ U
R-                  US5      $ U R                  [        R0                  L aq  [#        U5      S:X  aP  [%        US   [&        R(                  R*                  5      (       a$  U
R-                  US5      nUR/                  XU5      $ U
R-                  US5      $ U R                  [        R2                  L a0  [#        U5      S:X  a!  U
R-                  XS   R5                  5       SS9$ U R                  [        R6                  L aV  [#        U5      S::  a  [#        U5      S:X  d   e[#        U5      S:X  a  US   R5                  5       OSnUR-                  UU5      $ U R                  [        R8                  R:                  R<                  [        R8                  R:                  R<                  R>                  4;   aB  [#        U5      S::  a  [#        U5      S:X  d   eU" US   R5                  5       U R@                  S9$ [B        RD                  " U R                  5      (       a_  [G        U R                  [        RH                  5      (       a6  SSK%J&n  U" UUURN                  RQ                  S	U R                  S
0 5      5      $ U R                  [        RR                  RT                  RV                  [        RX                  RR                  RV                  [        RZ                  RR                  RV                  4;   a!  [\        R,                  " U R                  X#5      $ U R                  [        R^                  R`                  [        Rb                  R^                  R`                  4;   a  [d        R,                  " U R                  X#S9$ U R                  [        R^                  Rf                  [        Rb                  R^                  Rf                  4;   a%  [i        [j        SU R                  5        [m        5       $ U R                  [        Rn                  Rp                  L d'  U R                  [        Rn                  Rr                  L aH  U(       d  U(       a   e[t        R,                  " XR                  [        Rn                  Rp                  L S9$ U R                  [        Rv                  Rx                  Rz                  L a#  [#        U5      S:X  d   eUR-                  UU5      $ U R                  [        Rv                  R|                  R~                  L a"  [#        U5      S:X  d   eUR-                  U5      $ U R                  [        Rb                  R                  R                  L a=  [#        U5      S:X  d   eUR-                  UU Vs/ s H  n[        U5      PM     sn5      $ U R                  [        Rb                  R                  R                  L a"  [#        U5      S:X  d   eUR-                  U5      $ U R                  [        Rv                  R|                  R                  L a"  [#        U5      S:X  d   eUR-                  U5      $ U R                  [        Rv                  R|                  R                  L a=  [#        U5      S:X  d   eU	R-                  UU Vs/ s H  n[        U5      PM     sn5      $ U R                  [        Rb                  R                  R                  L a3  [#        U5      S:X  d   eUR-                  XS   R5                  5       5      $ [        b^  U R                  [        R                  R                  L a7  [#        U5      S:X  d   eUR-                  XS   US   R5                  5       5      $ U R                  [        R                  R                  R                  R>                  L a\  [        U R                  UU R@                  UU5      nUS   R5                  5       nUS   R5                  5       nUR-                  UUU5      $ [        TU ]]  XU5      $ s  snf s  snf )Nr.   )!DisabledSavedTensorsHooksVariableDualLevelContextManager&FSDPParamGroupUseTrainingStateVariableFxTracebackAnnotateVariable&GradIncrementNestingCtxManagerVariable)GradInplaceRequiresGradCtxManagerVariableGradModeVariableInferenceModeVariable%JvpIncrementNestingCtxManagerVariableSDPAKernelVariableSetFwdGradEnabledContextManagerr   &VmapIncrementNestingCtxManagerVariabler   FT)initializedr   )wrap_fx_proxy_clscall_functionra   )funcrecord_argsrecord_kwargsz$Profiler function %s will be ignored)only_subclassr   backendsset_priority)P r   r   r   r   r   r   r   r   r   r   r   r   r   r   rH   no_gradlenr   r   	functionsBaseUserFunctionVariabler   r   enable_gradset_grad_enabledr   inference_moderN   	tracebackannotate__wrapped__r   r   r   
issubclassStreamtorch._dynamo.variables.builderr   outputcreate_proxyampautocast_modeautocastcudacpur2   profilerrecord_functionr   r4   profiler   logr3   rL   DisableTorchFunctionSubclassDisableTorchFunctionr5   
_functorchvmapvmap_increment_nestingeager_transformsjvp_increment_nesting
forward_ad_set_fwd_grad_enabledr'   
dual_levelgrad_increment_nestingenable_inplace_requires_gradgraphdisable_saved_tensors_hooksrA   FSDPParamGroupuse_training_stater]   	attentionsdpa_kernelr9   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ctxinf_moder   xname_to_arg_mapr   r   r   s                           rc   r   *TorchCtxManagerClassVariable.call_functiona  s   	
 	
 	
 	
  ::&4yA~*Q,,EE# # '--b%8((6::'..r599ZZ5,,,4yA~*Q,,EE# # '--b$7((6::#**2t44ZZ5111c$i1n#**G..0d +   ZZ5///t9>c&kQ&6667:4yA~tAw1134H(//H==ZZHH''HH''33
 
 t9>c&kQ&666.Q**,T[[  __TZZ((Z

ELL-Q-QI$		&&#JJ		 	 ZZII##,,JJNN##IIMM""
 
 (..tzz4HHZZNN**NN##33
 
 9??ZZT  ZZNN""NN##++
 
 DdjjQ*,,JJ%((???zzUXX:::''/66**0U0U"U  ZZ5++00GGGt9>!>9@@  ZZ5++<<RRRt9>!>8??CCZZ5>>44JJJt9>!>299*./$Qa$/  ZZ5>>44???t9>!>*11"55ZZ5++<<SSSt9>!>9@@DDJJ%**;;XXXt9>!><CC*./$Qa$/  ZZ5>>//KKKt9>!>4;;G..0  )

/>>QQQt9>!>9@@GT!W779  ZZ588--99EEE.

O 'z2EEGH*>:MMOL%,,R<HHw$Rv66U 0 0s   'c
;c
ra   )r   r   r   r   r   r   r   staticmethodr   r   r   r   r1   r   r   r   r   s   @rc   r   r   K  so    V=# = 
s 
t 
 
U7#U7 'U7 -	U7
 
U7 U7rb   r   c            
          ^  \ rS rSrSr S!S\S\4   S\S-  S\SS4U 4S	 jjjrS\	4S
 jr
S\S\4   4S jr\\R                  S\\S\4   \S\4   4   4S j5       5       rSSS\\   SSSS4S jrSSS\\   SSSS4S jrSSS\\   S\\	\4   S\4S jr\  S"SSS\S-  S\S\4S jj5       r\SSS\S\S\4S j5       rSSS\\   S\\	\4   S\4S jrS\4S jrSSS\\   S\\	\4   S\4S jrS\4S jrS\4S jr S\!S\4S jr"S r#U =r$$ )#TorchInGraphFunctionVariablei  z@Points to a torch function/method that should be put in FX graphNr   .nonstrict_traceabler   rF   c                 V   > [         TU ]  " U40 UD6  SSKJn  Uc  U" U5      nX l        g )Nr   )is_nonstrict_trace_callable)r   r   trace_rulesr,  r*  )r   r   r*  r   r,  r   s        rc   r   %TorchInGraphFunctionVariable.__init__  s1     	)&)=&"=e"D#6 rb   c                 <    SU R                    SU R                   S3$ )NzTorchInGraphFunctionVariable(z, nonstrict_traceable=r   )r   r*  r   s    rc   r   %TorchInGraphFunctionVariable.__repr__	  s%    .tzzl:PQUQiQiPjjkllrb   c                     U R                   $ r   r   r   s    rc   get_function)TorchInGraphFunctionVariable.get_function  r   rb   c                  !  ^F^G^H^I^J^K^L^M^N^O 0 mMS[         S[        4   S[         [         S[        4   /[         S[        4   4   4UM4S jjn SSKJn  SSKJmFJmGJmHJmIJ	mJJ
mKJmL  SS	KJmNJmO  U " [        5       6 S
SS[         S[         S[         4UF4S jj5       nU " ["        6 S
SS[         S[         S[         4S j5       nU " [$        R&                  R(                  R*                  5      S
SS[         S[         S[         4S j5       nU " [$        R,                  R.                  R0                  R2                  5      S
SS[         S[         S[         4S j5       nU " [4        R6                  5      S
SS[         S[         S[         S-  4S j5       n[9        [4        S5      (       a5  U " [4        R:                  5      S
SS[         S[         S[         S-  4S j5       nU " [$        R<                  5      S
SS[>        4S j5       nU " [$        R@                  [$        R&                  RB                  5      S
SS[         S[         4UFUL4S jj5       n	U " [$        RD                  [$        RF                  5      S
SS[        S[         S-  4UF4S jj5       n
U " [$        RH                  5      S
SS[        S[         S-  4UF4S jj5       nU " [$        RJ                  5      S
SS[         S[         S[         4S j5       nU " [$        RL                  RN                  5      S
SS[         S[         S[         4S j5       nU " [P        6 S
SS[         S[         4S j5       nU " [$        RR                  RT                  RV                  RX                  [$        RR                  RT                  RV                  RZ                  [$        RR                  RT                  RV                  R\                  [$        RR                  RT                  RV                  R^                  [$        RR                  RT                  RV                  R`                  5      S
SS[         S[         S[         4S j5       nU " [$        Rb                  5      S
SSTF4UFUH4S  jj5       nU " [$        Rd                  5       ShS
SS![        S"[f        S[         4UG4S# jjj5       nU " [$        Rh                  5      S
SSTF4UFUG4S$ jj5       nU " [$        Rj                  Rl                  5      S
SSTF4UF4S% jj5       nU " [$        Rj                  Rn                  5      S
SSTF4UF4S& jj5       nU " [$        Rj                  Rp                  5      S
SSTF4S' j5       nU " [$        R&                  Rr                  [$        R&                  Rt                  [$        R&                  Rv                  5      S
SS[         STF4UF4S( jj5       nU " [x        R{                  S) [}        5        5       5      6 S
SS*S+STI4UI4S, jj5       nU " [$        R~                  5      S
SS[         STK4UKUO4S- jj5       nU " [$        R                  R                  5      S
SS.[        S/[        S[        4S0 j5       nU " [$        R                  R                  R                  5      S
SS1[        S2[        STF4UF4S3 jj5       nU " [$        RV                  R                  R                  5      S
SS[         S[         S[         4S4 j5       nU " [$        RR                  R                  5      S
SS[         S[         S[         4S5 j5       nU " [$        R,                  R                  R                  [$        R,                  R                  R                  R                  5       SiS6[        S
SS7[        S-  S[         S-  4S8 jj5       nU " [$        R,                  R                  R                  [$        R,                  R                  R                  R                  5       SiS6[        S
SS7[        S-  S[         S-  4S9 jj5       nU " [$        R                  5      S
SS[         S[         S[         S-  4S: j5       nU " [$        R                  5      S
SS;[         S<[         S[         S[         S-  4
S= j5       n U " [$        R                  5      S>[        S
SS[         S[         S[         S-  4
S? j5       n!U " [$        R                  5      S>[        S
SS[         S[         S[         S-  4
S@ j5       n"U " [$        Rj                  R                  5      S>[        S
SS[         S[         S[         4
SA j5       n#U " [$        R                  5      S
SSB[         SC[         S[         S-  4UF4SD jj5       n$U " U5      S
SS[         S[         S[         4UN4SE jj5       n%[        R                  " 5       (       ah  SSFKUJVn&JWn'JXn(JYn)JZn*  SSGK[J\n+  U " U&U'U(U*U)5      S
SS[         S[         4SH j5       n,U " U+R                  5      S
SS[         S[         S[         4UFUN4SI jj5       n-U " [$        R                  R                  5       SiSSJ.S
SSK[         S-  S[         SL[        S-  S[         SS4SM jjj5       n.U " [$        RR                  R                  R                  5      S
SS[         S[         SS4SN j5       n/U " [$        R                  R                  R                  R                  5       SiS
SSO[         SP[        [            S[         S-  4UJ4SQ jjj5       n0U " [$        R                  R                  R                  R                  5      S
SSO[         S[         S-  4UJ4SR jj5       n1U " [$        R                  R                  R                  R                  5      S
SSO[         S[         S-  4UJ4SS jj5       n2U " [$        R                  R                  R                  R                  5      S
SSO[         S[         S-  4UJ4ST jj5       n3U " [$        R                  R                  R                  R                  5      S
SSO[         S[         S-  4UJ4SU jj5       n4U " [$        R                  R                  R                  R                  5      S
SSO[         S[         4UJ4SV jj5       n5U " [$        R                  R                  R                  R                  5      S
SSO[         S[         S-  4UJ4SW jj5       n6U " [$        R                  R                  R                  R                  5      S
SSX[         S[         S-  4UJ4SY jj5       n7U " [$        R                  R                  R                  R                  5      S
SSX[         S[         S-  4UJ4SZ jj5       n8U " [$        R                  R                  R                  R                  5      S
SSO[         S[         S-  4UJ4S[ jj5       n9U " [$        Rj                  R                  R                  5      S
SS[         S[         S[         4S\ j5       n:U " [$        Rj                  R                  R                  5      S
SS[         S[         STL4UL4S] jj5       n;U " [$        R                  R                  R                  5      S
SS[         S[         S[        4S^ j5       n<U " [$        R                  5      S
SS[         S[         S[         S-  4UJ4S_ jj5       n=U " [$        Rj                  R                  5      S
SS[         S[         S[        4S` j5       n>U " [$        Rj                  R                  5      S
SS[         S[         S[         4UF4Sa jj5       n?U " [$        Rj                  R                  5      S
SS[         S[         S[         4UF4Sb jj5       n@U " [$        Rj                  R                  5      S
SS[         S[         S[        4Sc j5       nAU " [$        R                  R*                  5      S
SS[         S[         S[         4Sd j5       nBU " [$        R                  R                  [$        GR                   R                  5      S
SS[         S[         SG[        4Se j5       nCU " [$        GR                  5      S
SS[         S[         S[         4UF4Sf jj5       nDU " [$        GR                  5      S
SS[         S[         S[         4UFUN4Sg jj5       nETM$ )jzBuild a dict from function -> method to handle it so that we are O(1)
in terms of the number of function with special handling.fns.rF   c                     >^  S[         S[        4   S[         S[        4   4U U4S jjn[        T S   5      (       d   eU$ )Nhandler.rF   c                 >   > T H  nUT;  d   U5       eU TU'   M     U $ r   ra   )r7  fnr5  handlerss     rc   	_registerOTorchInGraphFunctionVariable._get_handlers.<locals>.register.<locals>._register  s0    BX-1r1-#*HRL  rb   r   )r   r   r   )r5  r;  r:  s   ` rc   register<TorchInGraphFunctionVariable._get_handlers.<locals>.register  sJ    8CH#5 (38:L   CF####rb   r   )
SDPAParamsr.   )r   DeterministicAlgorithmsVariabler   StreamContextVariableSymNodeVariableTensorVariableUserDefinedObjectVariable)wrap_fx_proxyr   r   rB   r   r   c                   > U(       d  U(       a   eU R                   [        R                  R                  [        R                  R
                  R                  [        R                  R                  [        R                  R                  [        R                  R                  [        R                  R                  R                  4;   a  UR                  5         TR                  " [        5       U R                      5      $ r   )r   rH   rW   rV   rT   rU   rX   rY   rZ   r[   r\   mark_inconsistent_side_effectsr   rd   r   r   r   r   r   s       rc   handle_tracing_state_functionsRTorchInGraphFunctionVariable._get_handlers.<locals>.handle_tracing_state_functions/  s     F**zz)),,99++22++((@@	 	 113#**+B+DTZZ+PQQrb   c                    U(       a   eU R                   [        R                  R                  L Ga&  [	        U5      S:X  d   eUS   R                  5       (       d   eUS   R                  R                  R                  S   nU R                  U5      n[        U[        R                  R                  5      (       a  U[        R                  R                  [        R                  R                  R                  5      -
  [        R                  R                  [        R                  R                  R                  5      -
  n[         R#                  U5      $ U(       a   e[         R#                  U R                  5       5      $ )Nr.   r   example_value)r   rH   rL   _dispatch_keysr   	is_tensorproxynodemetar   _subclasses
FakeTensorr   DispatchKeyPythonPythonTLSSnapshotDispatchKeySetVariabler   )r   r   r   r   rL  dkss         rc   !handle_dispatch_key_set_functionsUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_dispatch_key_set_functionsE  s    :zzUXX4444yA~%~Aw((**** $Q 2 2 7 7 Hjj/ mU->->-I-IJJ((11%((2F2F2M2MNO((11!HH00BB  .44S99x-44TZZ\BBrb   c                 h    [         R                  " U[        R                  R	                  5       5      $ r   )r1   buildrH   	overridesget_default_nowrap_functionsr   r   r   r   s       rc   #handle_get_default_nowrap_functionsWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_default_nowrap_functionse  s)     #((EOO@@B rb   c                 l    UR                  [        R                  " U[        R                  5      X#5      $ r   )inline_user_function_returnr1   r\  r   accumulate_gradr_  s       rc   handle_accumulate_grad_KTorchInGraphFunctionVariable._get_handlers.<locals>.handle_accumulate_grad_t  s/     11%%b)*C*CDd rb   Nc                     [        X#5      (       d5  UR                  [        R                  " U[        R
                  5      X#5      $ g r   )r&   rc  r1   r\  r   radiansr_  s       rc   handle_radiansBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_radians  s?     1>>55#))"i.?.?@$  ?rb   fmac                     [        U5      S:w  d  U(       a  g [        S U 5       5      (       a2  Uu  pEn[        [        R                  5      nUR                  XXE/0 5      $ g )N   c              3   @   #    U  H  oR                  5       v   M     g 7fr   )rN  ).0args     rc   	<genexpr>QTorchInGraphFunctionVariable._get_handlers.<locals>.handle_fma.<locals>.<genexpr>  s     7$3}}$   )r   allr)  rH   addcmulr   )r   r   r   r   r$  yz
addcmul_fns           rc   
handle_fma>TorchInGraphFunctionVariable._get_handlers.<locals>.handle_fma  sX     t9>V7$777"GA!!=emm!LJ%33BA	2FF rb   c                 \    [        SSS/ [        R                  Q[        R                  QS9  g )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r   r   s     rc    handle_is_inference_mode_enabledTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_inference_mode_enabled  s6     TP&22&55	rb   rp  c                   > UR                  5       (       dS  U R                  [        R                  R                  L a>  [        UT5      (       a-  [        UR                  S5      (       a  TR                  " S5      $ TR                  " S5      $ )N__torch_function__TF)rN  r   rH   r]  is_tensor_liker   r   r   )r   r   rp  r   rD  s      rc   handle_is_tensorDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_tensor  sh     }}

eoo<<<s$=>>CII';<<'..t44'..u55rb   inputc                   > UnUR                  5       (       a  UR                  b  U R                  [        R                  L a&  TR
                  " UR                  R                  5      $ U R                  [        R                  L a&  TR
                  " UR                  R                  5      $ [        SU R                   35      eg )Nzcalling )rN  dtyper   rH   is_floating_pointr   
is_complexAssertionError)r   r   r  	input_argr   s       rc   handle_is_floating_pointLTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_floating_point  s     I""$$)D::!8!88+229??3T3TUUZZ5#3#33+229??3M3MNN(8DJJ<)@AArb   c                    > UR                  5       (       a:  UR                  5       (       a%  TR                  " [        UR                  5      5      $ UR                  5       (       a  UR                  US/ 0 5      $ g )Nnumel)rN  
valid_sizer   r+   sizecall_method)r   r   r  r   s      rc   handle_numel@TorchInGraphFunctionVariable._get_handlers.<locals>.handle_numel  sa       U%5%5%7%7'..wuzz/BCC""((Wb"==rb   c                 r    [        U5      S:X  a  US   $ [        SSU SU 3SS/[        R                  QS9  g )	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.r|  r   r   r   SUPPORTABLEr_  s       rc   handle_torch_compileHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_compile  sL     4yA~Aw:vYvh7lK&22	rb   c                 r    [        U5      S:X  a  US   $ [        SSU SU 3SS/[        R                  QS9  g )	Nr.   r   z,torch.library.wrap_triton call with > 1 argsr  r  zZAttempted to call `torch.library.wrap_triton` with > 1 args. Dynamo does not support this.zARemove the torch.library.wrap_triton call or its additional args.r|  r  r_  s       rc   handle_wrap_tritonFTorchInGraphFunctionVariable._get_handlers.<locals>.handle_wrap_triton  sL     4yA~AwFvYvh7xW&22	rb   c                 X    UR                  5       (       d   eUR                  US/ 0 5      $ Nr  )rN  r  )r   r   r  s      rc   handle_tensor_size_rewritesOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_tensor_size_rewrites  s.     ??$$$$$$RR88rb   c                 &    U R                  XU5      $ r   )_call_ntupler_  s       rc   handle_ntupleATorchInGraphFunctionVariable._get_handlers.<locals>.handle_ntuple  s     $$Rv66rb   c                 x   > [        TR                  5        TR                  " [        R                  " 5       5      $ r   )r!   _guards_singletonr   rH   is_grad_enabled)r   r   r   r   s     rc   handle_is_grad_enabledJTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_grad_enabled  s.     *<<=#**5+@+@+BCCrb   mode	warn_onlyc                    > U(       a8  UR                  5       (       a#  [        SSU SU 3SS/[        R                  QS9  TR	                  XR                  5       5      $ )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.r|  )r   r   r   r  r   )r   r   r  r  r@  s       rc   #handle_use_deterministic_algorithmsWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_use_deterministic_algorithms  sf    
 Y99;;a#D6i[A ?e*66	 399">U>U>WXXrb   c                 x   > [        TR                  5        TR                  " [        R                  " 5       5      $ r   )r!   r  r   rH   $are_deterministic_algorithms_enabled)r   r   r   r@  s     rc   +handle_are_deterministic_algorithms_enabled_TorchInGraphFunctionVariable._get_handlers.<locals>.handle_are_deterministic_algorithms_enabled/  s.     9KKL#**5+U+U+WXXrb   c                    > [        [        R                  5        TR                  " UR                  R
                  5      $ r   )r!   r5   r  r   symbolic_torch_function_statetorch_function_subclass_enabledr   r   r   s     rc    handle_is_torch_function_enabledTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_enabled6  s8     6HHI $**00PP rb   c                    > [        [        R                  5        TR                  " UR                  R
                  (       + 5      $ r   )r!   r5   r  r   r  torch_function_mode_enabledr  s     rc   %handle_is_torch_function_all_disabledYTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_all_disabledA  s9     6HHI#**44PPP rb   c                     [        [        R                  5        [        R                  " UUR
                  R                  =(       a    UR
                  R                  5       5      $ r   )r!   r5   r  r1   r\  r  r  in_torch_function_moder  s     rc   %handle_is_torch_function_mode_enabledYTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_mode_enabledJ  sR     6HHI #((00LL N44KKM rb   c                    > [        U5      S:X  a,  [        US   [        5      (       a  US   R                  U5      OUnTR                  " [        S U 5       5      5      $ )Nr.   r   c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r(   ro  r$  s     rc   rq  `TorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_function.<locals>.<genexpr>f  s     95a&q))5s   )r   r   r<   unpack_var_sequencer   any)r   r   r   elemsr   s       rc   handle_has_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_functionX  s_     t9>ja-&H&H Q++B/ 
 $**9599 rb   c              3   >   #    U  H  u  pUR                   v   M     g 7fr   )stream)ro  r   device_interfaces      rc   rq  =TorchInGraphFunctionVariable._get_handlers.<locals>.<genexpr>j  s       +M'A !''+Ms   r  r   c                 &   > TR                  X5      $ r   )r   )r   r   r  rA  s      rc   handle_device_interface_streamRTorchInGraphFunctionVariable._get_handlers.<locals>.handle_device_interface_streami  s     )//;;rb   c                 4  > [         R                  (       d  [        SS[         R                   3SS/S9  [        (       d  [        SSSS	/[        R
                  QS9  T" TUUR                  R                  " S
[        R                  /[        U0 5      Q76 S S9$ )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`.r|  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   rO  rL  )r   trace_numpyr   npr   
USER_ERRORr  r  rH   	as_tensorr,   )r   r   r   rC  r   s      rc   handle_from_numpyETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_numpyt  s     %%c*6+=+=*>?M O
 2G bS*55	 %)ii,,#OO 'tR0
 #	 	rb   the_type	the_valuec                     U$ r   ra   )r   r   r  r  s       rc   handle_jit_annotateGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_jit_annotate  s
     rb   tensorextrac                   > U(       a   S5       eUR                  5       (       d   S5       e[        R                  " SUR                  UR                  S9nTR
                  " [        R                  R                  R                  U5      5      $ )Nz%Expect 1 input to cudnn.is_acceptablez2Expect input to cudnn.is_acceptable to be a tensorr   )r  device)	rN  rH   r  r  r  r   r   cudnnis_acceptable)r   r   r  r  
tensor_inpr   s        rc   handle_cudnn_is_acceptableNTorchInGraphFunctionVariable._get_handlers.<locals>.handle_cudnn_is_acceptable  sy     EEE9##%% D% av||FMMRJ#**$$22:> rb   c                 J    [         R                  R                  " U/UQ70 UD6$ r   )r   BackwardHookVariabler   r_  s       rc   handle_backward_hookHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_backward_hook  s%     1188MdMfMMrb   c                 .    U R                   " U/UQ70 UD6$ r   )call_nn_parameterr_  s       rc   handle_parameterDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_parameter  s     ))">t>v>>rb   self_dimc                 4    Ub  UR                  USU/0 5      $ g r  r  r  r   r   r  s       rc   handle_sym_sizeCTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_size  s%    
 ''FSE2>>rb   c                 4    Ub  UR                  USU/0 5      $ g )Nstrider  r  s       rc   handle_sym_strideETorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_stride  s%     ''HseR@@rb   c                 b   [        U5      S:X  a  SU;   a  [        U5      S:X  a  [        [        R                  5      R	                  U/ USS  Q0 5      n[        [        R
                  5      R	                  XUS   /0 5      n[        [        R                  5      R	                  XS   U/0 5      $ g )Nrm  r   r.   r   )r   r)  rH   rh   r   rg   re   )r   r   r   r   r   s        rc   handle_addcdivBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_addcdiv  s     4yA~'V"3Fq8H 6eii@NN$qr(R 6eii@NN12 4EII>LLa&)2  rb   r  
fill_valuec                     UR                  5       (       a?  [        [        R                  5      R	                  X/U5      nUR                  USU/0 5      $ g )Nfill_)rN  r)  rH   rv   r   r  )r   r   r  r  r   empty_results         rc   handle_full?TorchInGraphFunctionVariable._get_handlers.<locals>.handle_full  sS     ##%%  <EKKHVV  $//Gj\2NNrb   r   c                     [         R                  (       d  g [        U5      S:X  aU  [        US   [        5      (       d=  U(       d6  UR                  [        R                  " U[        R                  5      UU5      $ g )Nrm  r   )
r   enable_dynamo_decompositionsr   r   r;   rc  r1   r\  r   foreach_lerp_inplacer   r   r   r   s       rc   "handle_inplace_foreach_lerp_scalarVTorchInGraphFunctionVariable._get_handlers.<locals>.handle_inplace_foreach_lerp_scalar  sb     664yA~ja,&G&GPV55#))"i.L.LM 
 rb   c                     [         R                  (       d  g [        U5      S:X  aU  US   R                  5       (       a=  U(       d6  UR	                  [
        R                  " U[        R                  5      UU5      $ g )Nr   r   )	r   r  r   rN  rc  r1   r\  r   foreach_pow_scalarr  s       rc   handle_foreach_pow_scalarMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_foreach_pow_scalar  se     66 4yA~$q'"3"3"5"5f55#))"i.J.JK 
 rb   c                 n    UR                  [        R                  " U[        R                  5      UU5      $ r   )rc  r1   r\  r   !group_tensors_by_device_and_dtyper  s       rc   (handle_group_tensors_by_device_and_dtype\TorchInGraphFunctionVariable._get_handlers.<locals>.handle_group_tensors_by_device_and_dtype!  s3     11%%b)*U*UV rb   	conditionmessagec                    > UR                  5       (       a  UR                  5       (       d4  [        U[        R                  5      (       a  UR                  5       (       a  T" S 5      $ g r   )is_python_constantr   r   r   rB  evaluate_expr)r   r   r  r  r   s       rc   handle_assertATorchInGraphFunctionVariable._get_handlers.<locals>.handle_assert.  sR     ,,..93O3O3Q3Q9i&?&?@@++--'--rb   c           
         > T" UUR                   R                  " S[        R                  R                  /[        X#5      Q76 US9$ )Nr   )rO  
param_vars)r  r  rH   rL   _SDPAParamsr,   )r   r   r   r   rE  s       rc   handle_sdpa_paramsFTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sdpa_params<  sK     !ii,,#HH(( 't4
   rb   )_get_group_size_by_name_get_group_tag_rank_not_in_group$_resolve_group_name_by_ranks_and_tagget_process_group_ranks)DTensorc                    [        U5      S:X  a3  [        US   [        5      (       d  US   R                  5       (       d   eO][        U5      S:X  a3  [        US   [        5      (       a  US   R                  5       (       d   eO[        SU SU R                   35      eU Vs/ s H  o3R                  5       PM     nnU R                  " U6 n[        R                  " X5      $ s  snf )Nr.   r   r   zInvalid group value (z) for constant pg function )
r   r   r8   r  r;   r  r   r   r1   r\  )r   r   r   rp  args_as_valueinvocation_results         rc   &handle_constant_processgroup_functionsZTorchInGraphFunctionVariable._get_handlers.<locals>.handle_constant_processgroup_functionsW  s     t9> #47,@AA755778 Y!^ #47L99 G668898 )/v 6$$(JJ<1  FJ JTc!7!7!9T J$(JJ$>!
 ',,RCC !Ks   $C$c           
        >^ ^^ UR                  S5      nUc  [        U5      S:  a  US   nUc  TR                  " S 5      nOJ[        U[        R
                  5      (       a+  [        R                  " [        5      R                  X/0 5      n[        U5      n[        U5      S:  a  XES'   OUR                  S5      b  XCS'   USS   Vs/ s H  ofR                  5       PM     snmUR                  5        VVs0 s H  u  pxUS;  d  M  XxR                  5       _M     snnmS Vs0 s H  owU;   d  M
  XsU   _M     n	n SS[        S[        S -  S[        S -  S	[        4UUU 4S
 jjjn
ST R                  R                  -   U
l        T" UUR                  R                   " SU
/[#        US   /U	5      Q76 S9$ s  snf s  snnf s  snf )N
placementsrm  r   r.   shaper   r$  r4  r   rF   c                 8   > TR                   " U /TQ70 TDXS.D6$ )Nr3  r   )r$  r4  r   r-  kwargs_as_valuer   s      rc   fn_with_prim_typesaTorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local.<locals>.fn_with_prim_types  s1      ::)-<DI rb   zprim r   r   r   rO  )NN)getr   r   r   r   rD  BuiltinVariabletupler   listr   itemsr   r   r   r  r  r,   )r   r   r   r   placements_vtnew_argsr$  kvkwargs_to_be_proxiedr7  r-  r6  r   rE  s   `          @@rc   handle_from_localETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local  s    !'

< 8 (SY!^$(GM ($4$;$;D$AMy/R/RSS$-$=$=e$D$R$ROR%M  :x=A%"/QKZZ-9+8<(AI!" NA!5!5!7 N !'# . 33 .A++-- .# +>(*=QfLAayL*= % (
 LP#&:>ADj  /6

8K8K.K"+$))00'* +!!WI0
 
+ !O#(s   	F68F;F;$	G1	G)layouttensor_listrF  c                   SSK Jn  U(       aD  UR                  [        R                  5      (       a   [        SSU 3SS/[        R                  QS9  [        X&5      (       d   [        SS	U 3SS
/[        R                  QS9  g )Nr.   )BaseListVariablez%Attempted to use strided NestedTensorzlayout=r  zChange layout=torch.jagged.r|  z4Attempted to use `nested_tensor` with non-list inputztensor_list=z'Change `nested_tensor` with list input.)
listsrI  is_constant_matchrH   stridedr   r   r  r   r  )r   r   rG  rF  r   r   rI  s          rc   handle_nested_tensorHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_nested_tensor  s     0&225==AAC%fX. ?5*66	 k<<R*;-8 ?A*55	 rb   c                     [        U5      [        U5      -   S:X  d(  [        U5      S:X  a,  US   R                  S5      (       a  [        SSU SU 3SS/S	9  g )
Nr.   r   zOAttempted to use `torch.nn.functional.one_hot` with data-dependent output shaper  r  r  zuExplicitly set the `num_classes` param of the function call `torch.nn.functional.one_hot` to something other than -1.r|  )r   rK  r   r_  s       rc   handle_one_hotBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_one_hot  sf     4y3v;&!+D	Q47#<#<R#@#@m#D66(; ?T	 rb   exprfallbackc                 >  > U(       a  UR                  5       OS n[        UT5      (       a[  [        R                  R	                  [
        R                  R                  R                  R                  UR                  U5      5      $ UR                  5       (       a  U$ g r   )r   r   r   r   r   rH   rN   experimentalsymbolic_shapes	size_hintsym_numr  )r   r   rS  rT  fallback_intrB  s        rc   handle_size_hintDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_size_hint  s~     =E8668$L$00 1188HH))99CCl 
 ((**rb   c                 
  > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ UR                  5       (       a  U$ g r   )r   r   r   r   rH   rN   rV  rW  guard_size_obliviousrY  r  r   r   rS  rB  s      rc   handle_guard_size_obliviousOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_size_oblivious  sk     $00 !1188HH))99NN 
 ((**rb   c                 
  > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ UR                  5       (       a  U$ g r   )r   r   r   r   rH   rN   rV  rW  guard_or_truerY  r  r_  s      rc   handle_guard_or_trueHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_or_true  sh     $00 !1188HH))99GGU  ((**rb   c                 
  > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ UR                  5       (       a  U$ g r   )r   r   r   r   rH   rN   rV  rW  guard_or_falserY  r  r_  s      rc   handle_guard_or_falseITorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_or_false$  sh     $00 !1188HH))99HHV  ((**rb   c                 
  > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ UR                  5       (       a  U$ g r   )r   r   r   r   rH   rN   rV  rW  statically_known_falserY  r  r_  s      rc   handle_statically_known_falseQTorchInGraphFunctionVariable._get_handlers.<locals>.handle_statically_known_false3  si     $00 1188HH))99PP 
 ((**rb   c                 J  > [        UT5      (       a  UR                  nO5UR                  5       (       a  UR                  5       nO[	        SSU 3S/ S9  [
        R                  R                  [        R                  R                  R                  R                  W5      5      $ )NzGtorch.fx.experimental.symbolic_shapes.guard_scalar branch not supportedzexpr: z6Expected `expr` to be a symbolic variable or constant.r|  )r   rY  r  r   r   r   r   r   rH   rN   rV  rW  guard_scalarr   r   rS  valrB  s       rc   ro  @TorchInGraphFunctionVariable._get_handlers.<locals>.guard_scalarB  s     $00ll((**--/e$TFO X	 --44%%55BB3G rb   c                 
  > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ UR                  5       (       a  U$ g r   )r   r   r   r   rH   rN   rV  rW  statically_known_truerY  r  r_  s      rc   handle_statically_known_truePTorchInGraphFunctionVariable._get_handlers.<locals>.handle_statically_known_trueV  si     $00 1188HH))99OO 
 ((**rb   termsc                    > [        U4S jU 5       5      (       aG  TR                  U[        R                  R                  R
                  R                  " S U 5       6 S S9$ g )Nc              3   <   >#    U  H  n[        UT5      v   M     g 7fr   r   ro  r$  rB  s     rc   rq  UTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_and.<locals>.<genexpr>i       A5a:a115   c              3   @   #    U  H  oR                  5       v   M     g 7fr   r   r  s     rc   rq  r|  m       61**,,rs  rY  )rt  r   rH   rN   rV  rW  sym_andr   r   rw  rB  s      rc   handle_sym_andBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_ande  sa     A5AAA&--HH))99AA66 ! .   rb   c                    > [        U4S jU 5       5      (       aG  TR                  U[        R                  R                  R
                  R                  " S U 5       6 S S9$ g )Nc              3   <   >#    U  H  n[        UT5      v   M     g 7fr   rz  r{  s     rc   rq  TTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_or.<locals>.<genexpr>w  r}  r~  c              3   @   #    U  H  oR                  5       v   M     g 7fr   r  r  s     rc   rq  r  {  r  rs  r  )rt  r   rH   rN   rV  rW  sym_orr  s      rc   handle_sym_orATorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_ors  sa     A5AAA&--HH))99@@66 ! .   rb   c                 .  > [        UT5      (       a  UR                  nO'UR                  5       (       a  UR                  5       nOg [        R
                  R                  [        R                  R                  R                  R                  U5      5      $ r   )r   rY  r  r   r   r   r   rH   rN   rV  rW  has_static_valuerp  s       rc   handle_has_static_valueKTorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_static_value  sr     $00ll((**--/--44%%55FFsK rb   c                 J    SSK Jn  [        U5      R                  U/ UQU5      $ )Nr   )_unsafe_set_version_counter)tensor_version_opr  r)  r   )r   r   r   r   r  s        rc   !handle_unsafe_set_version_counterUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_unsafe_set_version_counter  s*     H/+mB$01rb   c                 `   > T" [         R                  R                  R                  5       5      $ r   )rH   rL   r  peek_interpreter_stack)r   r   r   r   rD  s       rc   'handle_functorch_peek_interpreter_stack[TorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_peek_interpreter_stack  s(     -##::< rb   c                     US   R                   n[        [        R                  R                  R                  U5      5      $ Nr   )r   FuncTorchInterpreterVariablerH   r  pyfunctorchcoerce_cinterpreter)r   r   r   r   cinterpreters        rc   0handle_functorch_pyfunctorch_coerce_cinterpreterdTorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_pyfunctorch_coerce_cinterpreter  s8      7==L/  ,,@@N rb   c                   >^ S[         S[        4UU4S jjmS nU(       a  US   nOSU;   a  US   nUbX  UR                  5       (       dC  T" U5      (       a6  [        [        R
                  R                  5      R                  U/ UQU5      $ g )Nr$  rF   c                    > U R                  5       (       d  [        U T5      (       a  g[        U [        [        45      (       a  [	        U4S jU R
                   5       5      $ g)NTc              3   4   >#    U  H  nT" U5      v   M     g 7fr   ra   )ro  rv  check_any_unspecs     rc   rq  tTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspec.<locals>.<genexpr>  s     DGq/22Gs   F)rN  r   r;   r<   r  r>  )r$  rB  r  s    rc   r  aTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspec  sI    ;;==Jq/$B$BL-#@AADAGGDDD !rb   r   data)r1   r   rN  r)  rH   _refsr  r   )r   r   r   r   data_argr  rB  s        @rc   handle_torch_tensorGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor  s    	!O 	! 	! 	! H76!!&> $ **,,$X.. 4EKK4F4FGUU$  rb   c                     U(       d  U(       a   eUR                   R                  (       d  [        SSSS/[        R                  QS9  [
        R                  " U5        UR                   R                  5       $ )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.r|  )r  
mode_stackr   r   r  r@   register_mutationpop_torch_function_moder_  s       rc   handle_pop_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_pop_torch_function  sj     F**33>>S vJ*55	 +<<R@33KKMMrb   c                    > [        U5      S:w  d  U(       a  [        US[        U5       S35        [        R                  " U5        UR                  R                  US   5        TR                  " S 5      $ )Nr.   z0push_torch_function takes exactly one argument ( given)r   )r   r/   r@   r  r  push_torch_function_moder   rH  s       rc   handle_push_torch_functionNTorchInGraphFunctionVariable._get_handlers.<locals>.handle_push_torch_function  sg     4yA~$Fs4ykQXY +<<R@,,EEd1gN#**400rb   c                    > U(       d  U(       a  [        US5        TR                  " [        UR                  R                  5      5      $ )Nz+len_torch_function_stack takes no arguments)r/   r   r   r  r  rH  s       rc   handle_len_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_len_torch_function  s<     v$R)VW#**B44??@ rb   c                    [        U5      S:w  d  U(       a  [        US[        U5       S35        US   R                  5       nUS:  a#  U[        UR                  R                  5      :  d   eUR                  R                  U   $ )Nr.   z2get_function_stack_at takes exactly one argument (r  r   )r   r/   r   r  r  )r   r   r   r   inds        rc   handle_get_stack_atGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_stack_at  s}     4yA~$HTSZ[ q',,.C!8c"*J*J*U*U&V VVV33>>sCCrb   c           	         [        U5      [        U5      -   S:  d  U(       a(  SU;  a"  [        SSU SU 3S/ [        R                  QS9   U(       a  US   R	                  5       nOU(       a  US   R	                  5       nOS n[
        R                  " U5      nWc=  [        U R                  5      n[        UR                  [        R                  5      5        [        [        5       WR                   R#                  SSS9S   5      n[$        R&                  " XU5      $ ! [         a-  n[        S	SU SU 3S
/ [        R                  QUS9   S nANS nAff = f)Nr.   r  z*improper torch.get_device_module argumentsr  r  z<torch.get_device_module accepts 1 optional argument `device`r|  r   z.bad device argument to torch.get_device_moduleAExpected valid string/torch.device argument ('cpu', 'cuda', etc.)r}  r~  r  r  from_excr   )maxsplitrP  )r   r   r   r  r   rH   get_device_moduler   r#   r   r!   r   r    ID_MATCHr"   r%   r   rsplitr1   r\  )	r   r   r   r   r  moduleer   
new_sources	            rc   handle_get_device_moduleLTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_device_module   sH    4y3v;&*v(&:PH#D66(; ^*55	#H-@@BF!!W779F!F008 ~1$++>f//0E0EFG#&&sQ&7;J #((Z@@+  L#D66(; c9-889s   AD   
E*#EEc           	         [        U5      [        U5      -   S:  d  U(       a(  SU;  a"  [        SSU SU 3S/ [        R                  QS9   U(       a(  [        R
                  " US   R                  5       5      nO1U(       a(  [        R
                  " US   R                  5       5      nOS nUR                  R                  U5      $ ! [         a-  n[        S	SU SU 3S
/ [        R                  QUS9   S nAg S nAff = f)Nr.   r  z9unsupported arguments to torch.accelerator.current_streamr  r  zGtorch.accelerator.current_stream accepts one optional argument `device`r|  r   z7bad device argument to torch.accelerator.current_streamr  r  )
r   r   r   r  rH   r  r   symbolic_stream_state
cur_streamr   )r   r   r   r   r  r  s         rc   handle_current_streamITorchInGraphFunctionVariable._get_handlers.<locals>.handle_current_streamO  s     4y3v;&*v(&:PW#D66(; i*55	"\\&*:*M*M*OPF"\\$q'*D*D*FGF!F//::6BB U#D66(; c9-889s   A:C 
C>#C99C>c                    > [         R                  " U5        US   R                  5       (       a  [         R                  " U5        O[         R                  " U5        TR
                  " S 5      $ r  )r@   r  is_constant_noneclear_default_device!register_device_context_insertionr   rH  s       rc   handle_set_default_deviceMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_set_default_deviceq  sT     +<<R@Aw'')).CCBG.PPQST#**400rb   c           	      4  > S nS nU(       a  US   nUSS  nOSnUc  SU;   a  UR                  S5      nU(       a  US   nOSU;   a  UR                  S5      nUc-  T" UUR                  R                  SU R                  S0 5      S9$ S nS nUb}  [	        U[
        5      (       a  UR                  5       (       a'  [        S[        U5      S	S
S/[        R                  QS9  UR                  5       nUR                  R                  SU5      nUR                  5       (       a2  U R                  UR                  5       U5        TR                  " S 5      $ UR!                  5       n	Uc  U	4n
OX4n
T" UUR                  R                  SU R                  U
0 5      S9$ )Nr   r.   ra   condr  r   r9  z)Can't extract message from torch._check()zThe second argument of torch._check() must be a function defined within the torch.compile region that does not reference a non-local variable.zFMake sure the message function is defined in the torch.compile region.zmRemove any closure variables, e.g. remove references to closure variable `x` in `lambda: f'{x} failed check'`r|  _check_message)popr  r  r   r   r:   has_closurer   r   r   r  r2  %register_static_attr_and_return_proxyr  r   r   r   )r   r   r   r   predicate_vt
message_vt	rest_argsmessage_eagermessage_graph_proxypredicate_proxy
proxy_argsr   rE  s              rc   handle_check@TorchInGraphFunctionVariable._get_handlers.<locals>.handle_check  s     LJ#Aw H		#&(8%zz&1&q\
f$#ZZ	2
#$))00'

	  !M"&%":/IJJ!--//! K #JL
 ei /::	  !+ 7 7 9&(ii&U&U$m'# ..00

<::<mL'..t44*335O #*-/
-C
 ii,,#JJ	 rb   )Fr   )r   r   torch.backends.cudar?  r   r   r@  r   rA  rB  rC  rD  builderrE  r   rd   r1   dispatch_key_set_functionsrH   r]  r^  r  opsinductoraccumulate_grad_defaultr   rh  r   rk  is_inference_mode_enabledr   rN  r  r  r  r  compilelibrarywrap_triton!REWRITE_OPS_TO_TENSOR_SIZE_METHODr]   r^   utils_single_pair_triple
_quadruple_ntupler  use_deterministic_algorithmsr   r  rL   _is_torch_function_enabled_is_torch_function_all_disabled_is_torch_function_mode_enabledr(   has_torch_function_variadichas_torch_function_unarydictfromkeysr   
from_numpyrI   r   rD   r   r  r  hooksBackwardHook	Parameteratensym_sizeint
sym_strideaddcdivrw   _foreach_lerp__foreach_pow"_group_tensors_by_device_and_dtype_assertr7   is_available"torch.distributed.distributed_c10dr&  r'  r(  r)  r*  torch.distributed.tensorr+  
from_localnestednested_tensor
functionalone_hotrN   rV  rW  rX  r	   r^  rc  rg  rk  ro  rt  r  r  r  	_autogradr  r  r  r  r  r  r  _pop_torch_function_stackr   _push_on_torch_function_stack_len_torch_function_stack_get_function_stack_atr  acceleratorcurrent_streamr
  r   set_default_device_check)Pr=  r?  rI  rY  r`  re  ri  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/  rD  rM  rQ  r[  r`  rd  rh  rl  ro  ru  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r@  r   rA  rB  rC  rD  r:  rE  r   sP                                                                         @@@@@@@@@@rc   _get_handlers*TorchInGraphFunctionVariable._get_handlers  s   
 
	38$
	xS)*HS#X,>>?
	 	3	
 	
 	
 	>	*,	-	R'	R #	R &		R
 	R 
.	R* 
-	.	C'	C #	C &		C
 	C 
/	C> 
%//>>JJ	K	'	 #	 &		
 	 
L	 
%))$$55==	>	'	 #	 &		
 	 
?	 
$,,	
	'
	 #
	 &	
	
 t#
	 
 
	 4dhh+ ' *	
 !4'  " 
%11	2	-		 
3	 
%//5??#A#A	B
	6-
	64C
	6
	6 
C
	6 
##

	-	69	t#		

	 
%++		-	69	t#	 
	 
%--	 	'	 #	 &		
 	 
!	( 
%--++	,	'	 #	 &		
 	 
-	( 
4	5	9-	96E	9	9 
6	9 
HH""**HH""((HH""**HH""--HH""**

	7'	7 #	7 &		7
 	7

	7 
%''	(	D-	D	D 
)	D 
%44	5LQ	Y-	Y58	YEI	Y	Y 
6	Y  
%<<	=	Y-	Y	Y 
>	Y 
%((55	6	-		 
7	 
%((::	;	-		 
<	 
%((::	;	-		 
<	 
OO..OO77OO44



	-
	6E
	
	



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

	<-	<7G	<"	<

	<
 
%""	#"	-"	6E"	"	 
$"	H 
%))$$	%	-	9<	IJ		 
&	
 
%..&&44	5	-	7:	DG		 
6	" 
%++##00	1	N'	N #	N &		N
 	N 
2	N 
%(($$	%	?'	? #	? &		?
 	? 
&	? 
%))..))599>>+B+B+F+F	GMQ		3	@Cd
	t#	 
H	 
%))..++UYY^^-F-F-J-J	KMQ		3	@Cd
	t#	 
L	 
%--	 	'	 #	 &		
 t#	 
!	( 
%**		'	 "	 (		
 &	 t#	 
	" 
%&&	'		'	 #	 &		
 t#	 
(	" 
%$$	%		'	 #	 &		
 t#	 
&	& 
%((==	>
	
	'
	 #
	 &	
	
 
	 
?
	 
%--	 	'	 '	 %		
 t#	 
!	 
*		'	 #	 &		
 	 
	  ++--  9'"'4D1D:ID DDB g(()9+9 '9 *	9
 !9 *9v 
%,,,,	- 37	
 "&	'	 )4/	 #		
 $J	 &	 	 
.	@ 
%((%%--	.	'	 #	 &		
 	 
/	( 
%((''77AA	B
 37		'	 "	 /		
 t#	 
C	$ 
%((''77LL	M	-	5D	t#	 
N	  
%((''77EE	F	-	5D	t#	 
G	 
%((''77FF	G	-	5D	t#	 
H	 
%((''77NN	O	-	5D	t#	 
P	 
%((''77DD	E	-	5D		 
F	& 
%((''77MM	N	-	5D	t#	 
O	 
%((''77??	@	-	7F	t#	 
A	 
%((''77>>	?	-	7F	t#	 
@	 
%((''77HH	I	-	5D	t#	 
J	 
%(($$@@	A
	1'
	1 #
	1 &	
	1
 
	1 
B
	1 
%((%%<<	=
	'
	 #
	 &	
	
 '
	 
>
	 
%""..BB	C
	'
	 #
	 &	
	
 *
	 
D
	 
%,,	#	'#	 ##	 &	#	
 t##	 
 #	J 
%((44	5	N'	N #	N &		N
 '	N 
6	N( 
%((88	9	1'	1 #	1 &		1
 	1 
:	1  
%((44	5
	'
	 #
	 &	
	
 
	 
6
	 
%((11	2	D'	D #	D &		D
 '	D 
3	D 
%))55	6,	A',	A #,	A &	,	A
 ,	A 
7,	A\ 
%##22EJJ4M4M	N	'	 #	 &		
 	 
O	B 
%**	+	1'	1 #	1 &		1
 	1 
,	1* 
%,,	S	'S	 #S	 &	S	
 S	 
 S	j rb   r   rB   r   r   r1   c                   ^ SSK JnJm  SSKJn  U R
                  (       a  U R                  XU5      $ U R                  XU5      (       a  [        XX#5      $ U R                  5       (       a  [        X#5      (       a  U R                  [        ;   aL  U R                  c   e[        U R                  5      n[        UR!                  ["        R$                  5      5         UR&                  " U R)                  5       " U Vs/ s H  owR)                  5       PM     sn0 UR+                  5        VV	s0 s H  u  pXR)                  5       _M     sn	nD65      $ U R=                  5       (       Ga[  U R                  R>                  nU(       Ga!  US   RA                  5       (       Ga  US   nUR                  b  [C        [D        RF                  RH                  U5      (       a  [K        [D        RF                  RH                  U5      n[C        US5      (       a  [C        XRM                  5       S   5      (       aw  [D        RN                  RP                  [K        XRM                  5       S   5      RR                  ;   a5  [U        SSS	[W        U R                  5       S
3/ [X        RZ                  QSPS9  U R]                  U[7        U5      U5      $ U R_                  5       Ra                  U R                  5      nU(       a  U" X/UQ70 UD6nU(       a  U$ [c        U4S jU 5       5      n[e        U4S jU 5       5      n[K        U R                  SS5      S:X  a  U R                  R>                  [f        ;   a  U(       a{  U(       at  S[i        U R                  5       S3n[j        Rm                  U5        [U        SSU R                   SU SU 3S[i        U R                  5       S3/ [X        RZ                  QS9  U R                  nU(       aY  SU R                  R>                   3n[K        U R                  SS 5      S:X  a%  [C        [D        U5      (       a  [K        [D        U5      nS nS nSU;   a  US   n[o        U[p        [r        45      (       ao  / nUR*                   H]  nURA                  5       (       a2  URu                  5       Rv                  Rx                  S   Rz                  nOS nUR}                  U5        M_     URA                  5       (       a1  URu                  5       Rv                  Rx                  S   Rz                  n[D        R~                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  [D        R                  1n[        nUU;   aL  UR                  (       a;  UR                  R                  (       a   UR                  R                  R                  nU" 5          U" UUR                  R                  " SU/[        X#5      Q76 S9nS S S 5        WRA                  5       (       aO  SU;   aI  US   R)                  5       (       a1  [U        S SU R                   SU SU 3S!S"S#/[X        RZ                  QS9  UGbD  [o        U[6        5      (       Ga  [        UR*                  U5       H  u  nnUc  M  URA                  5       (       d   eUR                  Rv                  Rx                  S   nUURz                  :w  aM  [U        S$SU R                   SU SU 3S%U R                   S&U S'URz                   S
3/ [X        RZ                  QS9  [D        R                  R                  U5      (       a  M  [U        S(S)U R                   SU SU 3S!/ [X        RZ                  QS9  M     U$ Ub  URA                  5       (       d   eSURu                  5       Rv                  Rx                  ;   d   eURu                  5       Rv                  Rx                  S   nUURz                  :w  aM  [U        S*SU R                   SU SU 3S%U R                   S&U S'URz                   S
3/ [X        RZ                  QS9  [D        R                  R                  U5      (       d/  [U        S+S)U R                   SU SU 3S!/ [X        RZ                  QS9  U$ s  snf s  sn	nf ! [,        [.        [0        4 aF  n
[3        [5        U
5      U[7        [9        UR&                  U
R:                  5      5      S9   S n
A
GNS n
A
ff = f! , (       d  f       GN&= f),Nr.   )r   rB  rE  )r   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.r|  c              3   <   >#    U  H  n[        UT5      v   M     g 7fr   rz  r{  s     rc   rq  =TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>$  s     &Tt!z!_'E'Etr~  c              3   j   >#    U  H(  n[        UT5      =(       d    UR                  5       v   M*     g 7fr   )r   r  r{  s     rc   rq  r%  &  s,      !
NRJq/*Da.B.B.DDds   03r   rH   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=r  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   outrL  r   r9  requires_gradzAAttempted to use tensor creation function with requires_grad=Truer  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)cr   r   rB  r  rE  r*  "_call_nonstrict_traceable_functiontorch_function_override_enabledr>   r   r&   r   #constant_fold_functions_need_guardsr   r#   r!   r   r    EQUALS_MATCHr   r   r>  OverflowError	TypeError
ValueErrorr   typer=  mapr   is_tensor_methodr   rN  r   rH   r  r  r   r#  Taginplace_viewtagsr   r0   r   r  call_tensor_methodr  r:  r  rt  bin_opsr   r  warningr   r<   r;   r   rP  rQ  r4  append_foreach_add_foreach_add__foreach_sub_foreach_sub__foreach_mul_foreach_mul__foreach_div_foreach_div__foreach_clamp_max_foreach_clamp_max__foreach_clamp_min_foreach_clamp_min__foreach_maximum_foreach_maximum__foreach_minimum_foreach_minimum_r  _foreach_pow__foreach_lerpr
  _foreach_addcmul_foreach_addcmul__foreach_addcdiv_foreach_addcdiv_r   	fake_mode	shape_envignore_fresh_unbacked_symbolsr  r  r,   ziprO  _prims_commonis_contiguousis_contiguous_or_false) r   r   r   r   r   rE  r   r$  rA  rB  excr   
tensor_varr9  special_handlerr   any_symints_or_symfloatsall_ints_or_floatsmsgfn_torch_sym_opsaved_out_shapesout_kwarg_vtvtr4  ops_consuming_unbacked_scalarsr"  tensor_variableout_tensor_vtsaved_out_shapefake_outrB  s                                   @rc   r   *TorchInGraphFunctionVariable.call_function  s	    	8*##::2VLL//&AA*2TBB))++0M1
 1
 zz@@{{...1$++>f//0I0IJK'..++-:>?$Q..0$?AGP12244P    ""::&&DQ))++!!W
$$0WUYY^^T5R5R 6BK00#Bq(9::!II22"2||~a'89>>? &$@$&*`ahimisisat`uuv(w#!2!>!># Q#	 **2tDz6BB,,.224::>$T???F#&&Tt&T#T   !
NR!
 
 DJJb1W<

##w.("		TZZ C
 KKbdjj\ixH(TZZ(9 :4 4&22
 jj#"4::#6#6"78Ltzz<6&@W|F F e\2  F?!%=L ,(EFF#% &,,B||~~ " 2 2 7 7 H N N $$++E2 - %%'' ))+0055oFLL ! $$%%$$%%""##""##  ""##""##3*
&6 00|| 6 6ll,,JJU+ii,,# 't4O  %%''6)'::<<[djj\ixH;D6 '22		 ' *D1169 &&$72M? '. !(224444,2277<<_MH&(..8 &$V&)$**WTF)F8$T">tzzl K::I9JJZ[c[i[iZjjk!m#!2!>!>#
 !..<<XFF &$e&1$**WTF)TZS[$\(G#!2!>!>#	;7F ; $/L4J4J4L4LLL&,*?*?*A*F*F*K*KKKK'00277<<_M#x~~5 " I"%djj\ix P:4::, G66F5GGWX`XfXfWgghj.::
 **AA(KK " X"-djj\iPVx X$C.::	 G @P "9j9 (Ic"2"9"9388DE f UsB    g. <g#g. +g(	g.  -i#g. .i	;ii	
ic           
      8  ^^ ^!^"^#^$ SSK Jm!JnJnJm#Jm$  SSKJm   SSKJ	n  SSK
Jn  SSKJn  [        R                  " U[        R                  " X5      [         R                  " X5      45      n	["        R$                  " U5      R'                  X/0 5      n
[)        U
[        5      (       a  [+        U
R,                  5      S:X  d   eU
R,                  u  p[)        U[.        5      (       d   eUR,                   HM  nUR1                  5       nU" U5      (       a  M"  UR1                  5       R2                  n[5        S	S
U S3SS/S9  MO     UR,                   Vs/ s H  oR7                  5       PM     nn UR9                  5       nU RF                  m"S[H        S[H        S[H        4U U"4S jjnU" U5      u  nnURJ                  RM                  T"RN                   S 3U5      nURJ                  RM                  T"RN                  S!-   W5      n[Q        U5      URR                  l(        [Q        U5      URR                  l(        UU/UQ7nS mS[T        S[V        [X           4UU!U#U$4S" jjnURJ                  R[                  S#UU0 5      n U" UU5      nTc   e[H        R                  " UT5      n["        R$                  " [>        Rh                  5      R'                  UUU/0 5      n
U
$ s  snf ! U a  nUR:                  R1                  5       nUR2                  nSS KJs  Jn  URA                  U5      (       a/  [5        SSU SU S3SU S3S/[B        RD                  QUS9   S nAGN[5        SSU SU S3SU S3SSU S3/[B        RD                  QUS9   S nAGNS nAff = f! [\        R^                  R`                  Rb                  [\        R^                  R`                  Rd                  4 a5    [5        S$S%T"RN                   3S&/ [B        RD                  QS9  [g        S'5      ef = f)(Nr   )
flat_applyfunc_to_graphableis_graphable_typeis_valid_outputto_graphable)fake_tensor_tls)tree_flattenr.   )#AsPythonConstantNotImplementedErrorr"  r   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`r|  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.r  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`r   r   rF   c                  f   > TR                   nSTl          T" U 0 UD6nUTl         U$ ! UTl         f = fNT)allow_non_fake_inputs_override)r   r   old_valresro  r9  s       rc   
patched_fnSTorchInGraphFunctionVariable._call_nonstrict_traceable_function.<locals>.patched_fnl  sH     &DDG=AO:I$)&)AH>J BI>s   ' 	0_spec_input_specc                     > T" U SS06nT" U5      u  p#Tc  UmOTU:X  d   SU< ST< 35       eT" U5      (       d   eU$ )Nchecked_outputFzTError: nonstrict-traced functions must return the same output shape every time. got z vs but expected ra   )r   r(  flat_outspeccaptured_specrj  rm  rn  s       rc   flat_apply_capture[TorchInGraphFunctionVariable._call_nonstrict_traceable_function.<locals>.flat_apply_capture  sp    d959C
 *#.NH$ $$, 4488;L]L]_, #8,,,,Orb   r   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.unreachable)5"torch._higher_order_ops.flat_applyrj  rk  rl  rm  rn  torch._subclasses.fake_tensorro  torch.utils._pytreerp  baserq  r  rE  r<   r\  r6   r   UserFunctionVariabler   r   r   r>  r;   python_typer   r   r   r   rb  r  _pytreeis_constant_classr   r  r   r1   r  r  r   r1  rP  r   r=  objectr  rH   rT   rX  UnsupportedTorchRuntimeErrorr  tree_unflatten)%r   r   r   r   rk  rl  rp  rq  rE  packed_input_vtout_vtflat_args_vtsinput_spec_vtflat_arg_vtarg_type	type_nameproxified_flat_args
input_specr  typpytreerw  r   f_specf_spec_proxyinput_spec_proxyall_argsr  rO  proxy_list_vtout_spec_vtr  ro  rj  r9  rm  rn  s%                                  @@@@@@rc   r*  ?TorchInGraphFunctionVariable._call_nonstrict_traceable_function  sV   	
 	
 	B4=* (--$$R.0A0G0G0ST
 //=KK!2
 &-00S5F!5KKK'-||$-6666 )..K"..0H$X..'335BB	P9)BG/
G	 /. 7D6I6I
6I{  "6I 	 
'	&99;JP ZZ	"	.=		 	 &j1	6 yyFF{{m5!6
 99JJKK-'

 "&f%)*%5" "2I5HI *.	c 	d6l 	 	$ 		&&/2
	0)"e4M& (((%++B> //0F0FGUU,b
 o
 3 %	$$""$C((I00'',,t$]O3Ei[PRS$$-; /ff
 s*66   \$]O3Ei[PRSRR[Q\\oq g9) EG G +66  +%	h MM))MM//	
 	0 Q$R[[M2d 7)556 !//!	0s2   K1K" ?	N "N(A.N.NNBPc                   ^^ U R                   [        R                  R                  R                  R
                  L a  US   R                  5       mO#U R                   R                  S   R                  m[        T[        5      (       d   eU(       a   eS[        S[        4UU4S jjnU R                   [        R                  R                  R                  R
                  L a  [        R                  " U5      $ U" US   5      $ )z1inline behavior of torch.nn.modules.utils._ntupler   r   rF   c                   > U R                  T5      (       a.  [        R                  " [        U R	                  T5      5      5      $ U R                  5       (       ad  [        R                  R                  [        R                  R                  R                  R                  T5      " U R                  5       5      5      $ [        SSU  3SS/S9  g )NzPAttempted to use `torch.nn.modules.utils._ntuple` with unsupported argument typezvalue=r  z:Change use of _ntuple with argument as constant or tensor.r|  )has_unpack_var_sequencer   r<   r=  r  r  r   r   rH   r]   r^   r  r  r   r   )r   countr   s    rc   r  @TorchInGraphFunctionVariable._call_ntuple.<locals>.handle_ntuple  s    ,,R00 ..22267  ))++ 1188HH$$**2259%:R:R:TU  n$UG, ?T	rb   )r   rH   r]   r^   r  r  r   __closure__cell_contentsr   r  r1   r   LambdaVariable)r   r   r   r   r  r  s    `   @rc   r  )TorchInGraphFunctionVariable._call_ntuple  s     ::))//777G..0EJJ**1-;;E%%%%%z	 	_ 	 	( ::))//777++M:: a))rb   r  r)  c           
      >   UR                   (       a  [        SSSS/[        R                  QS9  [	        U[
        R                  5      (       a   UR                  5       nUb  UR                  5       (       d   [        S
SU 3SS/[        R                  QS9  UR                  (       a  U R                  XU5      $ [        R                  (       a  [        SSSSS/[        R                  QS9  [	        U[        5      (       d  [!        UR"                  5      (       a%  [        S[%        U5      S/ [        R                  QS9  ['        5       (       d  [        SSSS/[        R(                  QS9   [+        UR-                  US5      R                  5       5      nUR-                  US5      R                  5       nUR-                  US5      R                  5       nUR.                  R1                  [2        WWWU45      nUR4                  (       a  UR7                  US/ 0 5      nSSKJn	  U	" UUR.                  R=                  S[>        URA                  5       URA                  5       40 5      UR                  S 9n
U
R                  5       (       d   e[B        RD                  RF                  U
l        S!U
l$        U
$ ! [         a$    [        SSU 3SS/[        R                  QS9   GNf = f! [         a,  n[        SSU 3SS/[        R                  QUS9   S	nAGN@S	nAff = f)"z>A call to torch.nn.Parameter() gets lifted to before the graphz3Attempted to use `torch.nn.Parameter()` with exportr   r  z.Do not use `torch.nn.Parameter()` with export.r|  z=non-constant `requires_grad` argument to `torch.nn.Parameter`zrequires_grad=z$Change `requires_grad` to be a bool.Nz1`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_parameterr4  r  r  z8`torch.nn.Parameter` with non-constant Tensor attributeszBEnsure the Tensor argument's shape, dtype, and device are correct.r  detachr.   r"  r   r   F)%exportr   r   r  r   r   r1   r   NotImplementedErrorr  rN  r   _nn_param_via_prefix_insertr   graph_break_on_nn_param_ctorr?   r   
class_typer   r   	DIFFICULTr<  var_getattrr  synthetic_graph_inputr   r)  r  r  rE  r  r   r   rH   r]   r  has_grad_fn)r   r   r  r)  r4  r  r  r  placeholderrE  r   s              rc   r  .TorchInGraphFunctionVariable.call_nn_parameter  s    99M;D&22	 mY%>%>?? - @ @ B <t~~//KvUX&11	 ;;222]KK..Y:ZV '22		 (
 
 0@@^D	;&22	 122TIZ&00		$**2w7JJLME$$R1DDFE%%b(3FFHF ii55%E6=1
 ##B"b9D*II"")+"6"6"89 %%
 !!!!!HH.. # s ' 	[,]O< ?>*55		R # 
	Rv;X&11 	 	
	s+   J5 .A)K& 5*K#"K#&
L0!LLc                   ^ U R                   R                  5       nU R                   R                  c   e[        U R                   R                  5      mTR	                  U4S j5        T" UR
                  5        T" [        R                  " U5      5        TR                  SS5        TR                  U5        U R                   R                  R                  TR                  5       5        UR                  5       R                  nUR                  S;  a)  [!        SSUR                   3S/ ["        R$                  QS9  ['        U5      n[(        R*                  R-                  U R                   R/                  UR                  5       R                  5      US	9n[0        R2                  " XU5      nUR5                  5       n[6        R8                  " 5       R:                  R<                  R?                  U5        U$ )
Nc                  (   > T R                  SS5      $ )Nztorch.nnr  )load_import_from)cgs   rc   <lambda>JTorchInGraphFunctionVariable._nn_param_via_prefix_insert.<locals>.<lambda>	  s    !4!4Z!Mrb   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.r|  )r)  ) r  new_varroot_txr   add_push_nullr   r   r   r   storepregraph_bytecodeextendget_instructionsr   rP  opr   r   r  r$   rH   r]   r  example_value_from_input_noder1   r\  realizer   r:  guards_contextdynamo_guardsremove_guards_with_source)	r   r  r)  varname	data_noder   rL  r   r  s	           @rc   r  8TorchInGraphFunctionVariable._nn_param_via_prefix_insert	  s   
 ))##% yy  ,,,ryy(()
MN
4;;
9%%m45
E"

		##**2+>+>+@AMMO((	<<::['	~6M&00	 &g.**II33DMMO4H4HI' + 
 !&&r&A! 	++99SS	
 rb   c                 d    US   R                  XR                  5       R                  USS  U5      $ )Nr   r.   )r  r2  r   r_  s       rc   r7  /TorchInGraphFunctionVariable.call_tensor_method	  s2     Aw""2'8'8':'C'CT!"XvVVrb   c                 N   SSK Jn  [        R                  " U R	                  5       5      =(       aV    [        U R	                  5       S5      =(       a5    U R	                  5       R                  [        R                  R                  :H  =(       d    U R	                  5       U" 5       ;   $ )Nr   )get_tensor_method__objclass__)
r-  r  r   ismethoddescriptorr2  r   r  rH   rL   
TensorBase)r   r  s     rc   r3  -TorchInGraphFunctionVariable.is_tensor_method	  s    3 &&t'8'8':; H))+^<H !!#00EHH4G4GG	8
  $5$77	8rb   c                    U R                  5       [        5       ;   =(       dL    [        U R                  5       [        R                  R
                  [        R                  R                  45      =(       a    [        XU5      $ r   )r2  rl   r   rH   r   r   r   r=   r_  s       rc   r+  <TorchInGraphFunctionVariable.torch_function_override_enabled	  sd     #<#>> !!#&&

(C(CD< *"F;	<rb   c                     grs  ra   r   s    rc   is_python_hashable/TorchInGraphFunctionVariable.is_python_hashable	  s    rb   c                 ,    [        U R                  5      $ r   )hashr   r   s    rc   get_python_hash,TorchInGraphFunctionVariable.get_python_hash	  s    DJJrb   otherc                 p    [        U[        5      (       d  gU R                  5       UR                  5       :H  $ )NF)r   r1   r   )r   r  s     rc   is_python_equal,TorchInGraphFunctionVariable.is_python_equal	  s/    %11&&(E,D,D,FFFrb   )r*  r   rs  )%r   r   r   r   r   r   r   r   r   r   r   r2  r'  	functoolscacher  r  r   r1   r   r*  r  r   r  r  r=  r7  r3  r   r+  r  r  r  r  r  r   r   r   s   @rc   r)  r)    s   J
 ,07S!7 "D[7 	7
 
7 7m# mhsCx0  __L4c 2HS#X4F FG L  L\&^#^ '^ -	^
 
^@	Q#Q 'Q -	Q
 
Qf%*#%* '%* S/)*	%*
 
%*N   "	N#N DjN 	N
 
N N` )#)+.)?C)	) )VW#W ?#W S/)*	W
 
W8$ 8	<)	<19#	<HLSRUX	<		<D    GV G G Grb   r)  c            
          ^  \ rS rSrSr\S\S\SS 4S j5       r\	S\S\
SS 4S j5       rS	\S\4S
 jrSSS	\S\\   S\\\4   SS4
U 4S jjrSrU =r$ )rW  i	  zrepresents torch.DispatchKeySetr   r   rF   c                     [        U 40 UD6$ r   )rW  )r   r   s     rc   r   DispatchKeySetVariable.create	  s    %e6v66rb   r   c                 ^    [        UR                  [        R                  5      5        U " XS9$ r   )r!   r   r    DISPATCH_KEY_SET_MATCHr   s      rc   r   )DispatchKeySetVariable.create_with_source	  s(     	f''(K(KLM5((rb   r   c                     US:H  $ )Nhasra   )r   r   s     rc   is_constant_fold_method.DispatchKeySetVariable.is_constant_fold_method	  s    u}rb   r   rB   r   r1   c                   > U R                  U5      (       a  [        X45      (       a  [        U R                  U5      n[        R
                  R                  U" U Vs/ s H  ofR                  5       PM     sn0 UR                  5        VVs0 s H  u  pxXxR                  5       _M     snnD65      $ US:X  a.  [        R                  " U R                  R                  5       5      $ [        T	U ]1  XX45      $ s  snf s  snnf )NhighestPriorityTypeId)r  r&   r   r   r   r   r   r   r>  EnumVariabler  r   r  )
r   r   r   r   r   methodr$  rA  rB  r   s
            rc   r  "DispatchKeySetVariable.call_method	  s     ''--2O3
 3
 TZZ.F--446:;d**,d;=C\\^L^TQq..00^L  ,,))$***J*J*LMMw"2T:: <Ls   C6C;ra   )r   r   r   r   r   r'  r   r   r   r   r   r   r   r   r  r=  r1   r  r  r   r   r   s   @rc   rW  rW  	  s    )7n 7 78P 7 7 )"),2)	!) )C D ;#; ; ?#	;
 S/)*; 
; ;rb   rW  c            
       t   ^  \ rS rSrSr\S\S\SS 4S j5       rSSS	\	S
\
\   S\\	\4   SS4
U 4S jjrSrU =r$ )r  i
  z<represents torch._functorch.pyfunctorch.FuncTorchInterpreterr   r   rF   c                 ^    [        UR                  [        R                  5      5        U " XS9$ r   )r!   r   r    r  r   s      rc   r   /FuncTorchInterpreterVariable.create_with_source	
  s(     	f''(=(=>?5((rb   r   rB   r   r   r   r1   c                   > US:X  a.  [         R                  " U R                  R                  5       5      $ US:X  aI  UR	                  [
        R                  " XR                  R                  R                  5      U /U-   U5      $ US;   a8  [         R                  R                  [        U R                  U5      " 5       5      $ US:X  a0  U(       d  U(       a   e[         R                  R                  US 5      $ [        TU ]9  XX45      $ )Nkeyprocess)level
batch_size
randomnesslower)r   r  r   r  rc  r1   r\  r  __func__r   r   r   0TemporarilyPopInterpreterStackCtxManagerVariabler   r  )r   r   r   r   r   r   s        rc   r  (FuncTorchInterpreterVariable.call_method
  s     5=))$**..*:;;Y11%%b***<*<*E*EF 
 ::--44WTZZ5N5PQQW_F**MMTTD  w"2T::rb   ra   )r   r   r   r   r   r   r   r   r   r   r=  r1   r  r  r   r   r   s   @rc   r  r  
  sy    F))!')	') );#; ; ?#	;
 S/)*; 
; ;rb   r  )r   r  r   loggingr   r   collections.abcr   r   r   
contextlibr   typingr   r   r	   r
   r   torch._CrH   torch._refstorch.fxtorch.nnr  r  r  r    torch._dynamo.variables.constantr   torch._dynamo.variables.streamsr   &torch._dynamo.variables.torch_functionr   torch._guardsr   r   torch._loggingr   torch.utils._python_dispatchr   r   r   r   r   r   r   r   create_parameter_opr   r   r   r  r   rX  r   r   guardsr    r!   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r  r/   r0   r1   ctx_managerr2   r3   r4   r5   dictsr6   distributedr7   r8   r   r9   r:   rJ  r;   r<   torch_functionr=   r>   r?   r@   numpyr  ModuleNotFoundError#torch.distributed.fsdp._fully_shardrA   torch._dynamo.symbolic_convertrB   rC   rD   rE   	getLoggerr   r  r  r   r  r  r   r  r  r  r  rL   r  r  r  r  r  r  r  r  r  r  r  r	  	grad_moder   r   r   r   r  r  r  r
  rN   r   r   r  r]   r   r!  r   _shape_as_tensorr  r  current_device_indexcurrent_acceleratorcurrent_deviceis_initializedxpur,  r  rW   _get_device_index_get_cublas_allow_tf32_is_any_autocast_enabledr  get_device_propertiesget_autocast_dtypeget_autocast_gpu_dtypeget_default_dtypeis_autocast_cache_enabledis_autocast_cpu_enabledis_autocast_enabledr  r  r  
_Reductionget_enumpromote_types_get_privateuse1_backend_name_is_checkpoint_validr   r  get_rankget_world_sizer  r   rd   r8  rM  _dispatch_tls_local_include_set_dispatch_tls_local_exclude_setr  ro   rl   r}   r   r)  rW  r  ra   rb   rc   <module>r4     s  6     	 8 8 " B B     % % # = : L 0 ' K > >  
 @ 9 0 	 	 	 A @  % B C . E
 D, CLCL! $''!!77!!,,''//--%%44))@@))??))FF		((  ,,  //  ((  1188		##,,

$$--####// 	&&22; ! F %)MM% ! 
**	))	JJ	JJ	II	II' # 
MM	LL""	HH##	HH%%	""	JJ$$	JJ	""		  		##	!!				HH""++		HH**	NN''	II##	II-. (/( 0 	!!##"",,&&,,	
 '+mm4W&X #--(?@  hr3w&7$&G!H  . --<
= 
HH	HH,,	HH,,  3xS'9#:  $IA IAXk7#4 k7\cG#4 cGL?$;. $;N ;#4  ;KM  	B
  s$   _0 _? 0_<;_<?`
`