
    7h                    \   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  SSK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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J r J!r!J"r"  SSK#J$r$  SSK%J&r&J'r'  SSK(J)r)J*r*  SSK+J,r,J-r-  SSK.J/r/J0r0J1r1J2r2J3r3J4r4J5r5  SSK6J7r7J8r8  SSK9J:r:J;r;J<r<  SSK=J>r>  SSK?J@r@JArA  SSKBJCrCJDrD  SSKEJFrFJGrGJHrHJIrI   SSKJrK SSKMJNrN  \(       a  SSKOJPrP  \R                  " \R5      rS\TR                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  \R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  R                  R                  \R                  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                  /5      rw\TR                  \R                  /5      ry\R                  R                  \R                  R                  \R                  R                  \R                  R                  \R                  R                  /r\GR                   \GR                  GR                  \R                  GR                  \R                  GR                  \R                  GR
                  \R                  GR                  \R                  GR
                  \R~                  GR
                  \GR                  \GR                  \GR                  \GR                  \GR                  \GR                  \GR                  \GR                  \R                  GR                  GR                   GR"                  \GR$                  \R                  GR&                  \R                  GR(                  \R                  GR                  \R                  GR
                  /\-   r\R~                  GR                  5       (       aS  \GR-                  \R~                  R                  \R~                  GR.                  \R~                  GR0                  /5        \TR                  \5      r\TR                  \5      r\GR2                  S\T\
/ \	4   \\   4   4S j5       r\TR                  / SQ5      r\R                  GR:                  \R                  GR<                  \R                  GR>                  1r\GR2                  S 5       r " S S\85      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      rg! \L a    SrK GNKf = f! \L a    SrN GNSf = f)(ak  
This module implements variable tracking for torch functions and operations during Dynamo tracing.

It provides classes to handle different types of torch operations:

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

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

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

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

This is a core part of Dynamo's tracing system, translating torch operations into
traceable graph nodes while preserving correct semantics and handling edge cases.
    N)Sequence)AnyCallableOptionalTYPE_CHECKING)TracingContext)warning_once)"is_traceable_wrapper_subclass_type   )configgraph_break_hints	polyfills	variables)	PyCodegen)!can_convert_to_tracable_parameternew_parameter_placeholdertracable_create_parameter) get_registered_device_interfaces)unimplementedunimplemented_v2)GuardBuilderinstall_guard)CallFunctionNoArgsSourceSyntheticLocalSource)check_unspec_or_constant_argsguard_if_dynhas_torch_functionhashableproductproxy_args_kwargsunwrap_if_wrapper   )typestrVariableTracker)AutocastModeVariableProfilerContextVariableTorchFunctionDisableVariable)ConstDictVariable)DistributedVariableProcessGroupVariable)ListVariableTupleVariable)can_dispatch_torch_functiondispatch_torch_functionTensorWithTFOverrideVariableTorchFunctionModeStackVariable)_fsdp_param_group)InstructionTranslatorreturnc                     [         R                  R                  S[         R                  R                  S[         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(                  R*                  S0$ )NFT)torchjitis_scripting
is_tracing_C_get_tracing_statefx_symbolic_traceis_fx_tracingonnxis_in_onnx_export_dynamoexternal_utilsis_compiling_utilscompileris_dynamo_compilingis_exportingnnmodules
activation_is_make_fx_tracing     W/var/www/fran/franai/venv/lib/python3.13/site-packages/torch/_dynamo/variables/torch.pytracing_state_functionsrN      s     					e##T  ..

$$e$$114!!4##T**D##T##77 rL   )addsubmuldivsqrtc                  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)	itertoolsrU   torch.overridesrV   setfrom_iterablevaluesr5   ones	ones_likezeros
zeros_likeemptyfullupdate)rU   get_overridable_functions_funcsmores       rM   rV   rV      sp    W##$>$@$G$G$IJKE



%D 
LLLrL   c                   f   ^  \ rS rSrSr\S 5       rSU 4S jjrSS jrS r	S r
SS jrS	 rS
rU =r$ )BaseTorchVariable   zHcommon base for all torch.* functions, classes, modules and other thingsc                 ^    [        UR                  [        R                  5      5        U " XS9$ Nsource)r   
make_guardr   FUNCTION_MATCHclsvaluerl   s      rM   create_with_source$BaseTorchVariable.create_with_source   s&    f''(C(CDE5((rL   c                 2   > [         TU ]  " S0 UD6  Xl        g )NrK   )super__init__rq   )selfrq   kwargs	__class__s      rM   rv   BaseTorchVariable.__init__   s    "6"
rL   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_]+_)	rq   
__module____name__	ExceptionidrerP   extend_outputsetup_globally_cached)rw   codegennameunique_var_names       rM   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rq   rw   s    rM   as_proxyBaseTorchVariable.as_proxy       zzrL   c                     U R                   $ r   r   r   s    rM   as_python_constant$BaseTorchVariable.as_python_constant   r   rL   c                 l    [        U R                  U5      n[        R                  R	                  U5      $ r   )hasattrrq   r   ConstantVariablecreate)rw   txr   results       rM   call_obj_hasattr"BaseTorchVariable.call_obj_hasattr   s)    T*))0088rL   c                 `    U R                   [        ;   a  g[        U R                   SS 5      S:H  $ )NTr   math)rq   constant_fold_functionsgetattrr   s    rM   can_constant_fold_through+BaseTorchVariable.can_constant_fold_through  s*    ::00tzz<6&@@rL   r   r3   N)r   r   r   r2   )r   r   __qualname____firstlineno____doc__classmethodrr   rv   r   r   r   r   r   __static_attributes____classcell__ry   s   @rM   rg   rg      s=    R) )
9A ArL   rg   c                   d   ^  \ rS rSrSrS\4S jr\S 5       rSSS\	\
   S	S
SS4U 4S jjrSrU =r$ )TorchCtxManagerClassVariablei  zLPoints to a context manager class in torch.* that dynamo has implementationsr3   c                 "    SU R                    S3$ )NzTorchCtxManagerClassVariable()r   r   s    rM   __repr__%TorchCtxManagerClassVariable.__repr__
  s    .tzzl!<<rL   c                 r    [        U 5      n [        U 5      =(       a    [        U 5      =(       a	    U [        ;   $ r   )r!   callabler   supported_ctx_manager_classesr   s    rM   is_matching_cls,TorchCtxManagerClassVariable.is_matching_cls  s6     "%( UO  ;::	
rL   r   r2   argsrx   dict[str, VariableTracker]r$   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  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                  [        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 a0  [!        U5      S:X  a!  U	R+                  XS   R3                  5       SS9$ U R                  [        R4                  L aV  [!        U5      S::  a  [!        U5      S:X  d   e[!        U5      S:X  a  US   R3                  5       OSnU
R+                  UU5      $ [6        R8                  " U R                  5      (       a_  [;        U R                  [        R<                  5      (       a6  SSKJ n  U" UUURB                  RE                  SU R                  S	0 5      5      $ U R                  [        RF                  RH                  RJ                  [        RL                  RF                  RJ                  [        RN                  RF                  RJ                  4;   a!  [P        R*                  " U R                  X#5      $ U R                  [        RR                  RT                  [        RR                  RV                  [        RX                  RR                  RT                  [        RX                  RR                  RV                  4;   a%  [[        [\        S
U R                  5        [_        5       $ U R                  [        R`                  Rb                  L d'  U R                  [        R`                  Rd                  L aH  U(       d  U(       a   e[f        R*                  " XR                  [        R`                  Rb                  L S9$ U R                  [        Rh                  Rj                  Rl                  L a#  [!        U5      S:X  d   eUR+                  UU5      $ U R                  [        Rh                  Rn                  Rp                  L a"  [!        U5      S:X  d   eUR+                  U5      $ U R                  [        RX                  Rr                  Rt                  L a=  [!        U5      S:X  d   eUR+                  UU Vs/ s H  n[w        U5      PM     sn5      $ U R                  [        RX                  Rr                  Rx                  L a"  [!        U5      S:X  d   eUR+                  U5      $ U R                  [        Rh                  Rn                  Rz                  L a"  [!        U5      S:X  d   eUR+                  U5      $ U R                  [        Rh                  Rn                  R|                  L a=  [!        U5      S:X  d   eUR+                  UU Vs/ s H  n[w        U5      PM     sn5      $ U R                  [        RX                  R~                  R                  L a3  [!        U5      S:X  d   eUR+                  XS   R3                  5       5      $ [        b^  U R                  [        R                  R                  L a7  [!        U5      S:X  d   eUR+                  XS   US   R3                  5       5      $ U R                  [        R                  R                  R                  L am  [!        U5      S:X  d  [!        U5      S:X  a  SU;   d   e[!        U5      S:X  a  US   OUS   nSU;   a  US   OSnUR+                  UUR3                  5       U5      $ U R                  [        R                  R                  R                  L a0  UR+                  X Vs/ s H  nUR3                  5       PM     sn5      $ [        TU ]Y  XU5      $ s  snf s  snf s  snf )Nr"   )!DisabledSavedTensorsHooksVariableDualLevelContextManager&FSDPParamGroupUseTrainingStateVariable&GradIncrementNestingCtxManagerVariable)GradInplaceRequiresGradCtxManagerVariableGradModeVariableInferenceModeVariable%JvpIncrementNestingCtxManagerVariableSDPAKernelVariableSetFwdGradEnabledContextManagerStreamVariable&VmapIncrementNestingCtxManagerVariabler   FT)initialized)wrap_fx_proxy_clscall_functionrK   z$Profiler function %s will be ignored)only_subclassr   backendsset_priority)I r   r   r   r   r   r   r   r   r   r   r   r   rq   r5   no_gradlen
isinstancer   	functionsBaseUserFunctionVariabler   r   enable_gradset_grad_enabledr   inference_modeinspectisclass
issubclassStreamtorch._dynamo.variables.builderr   outputcreate_proxyampautocast_modeautocastcudacpur%   profilerprofilerecord_functionautogradr	   logr&   r9   DisableTorchFunctionSubclassDisableTorchFunctionr'   
_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_hooksr1   FSDPParamGroupuse_training_staterG   	attentionsdpa_kernel_sdpa_kernel_variadicru   )rw   r   r   rx   r   r   r   r   r   r   r   r   r   r   r   r   ctxinf_moder   xr   r   argry   s                          rM   r   *TorchCtxManagerClassVariable.call_function  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==__TZZ((Z

ELL-Q-QI$		&&#JJ		 	 ZZII##,,JJNN##IIMM""
 

 (..tzz4HHZZ NN""NN**NN##++NN##33
 
 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9t9>c&kQ&6:;OPP"%d)q.tAwfZ6HH5Cv5M6.1SXL%,,H//1<  ZZ588--CCC%,,>#S++->  w$Rv66S 0 00 ?s   a
(a!
+a&
rK   )r   r   r   r   r   strr   staticmethodr   r   r$   r   r   r   r   s   @rM   r   r     sa    V=# = 
 
G7#G7 'G7 -	G7
 
G7 G7rL   r   c                      ^  \ rS rSrSrSSU 4S jjjrS\4S jrS r\	\
R                  S 5       5       rSS	S
\\   SSSS4S jrSS jr\SS j5       r\	SS j5       rS rS rS rSrU =r$ )TorchInGraphFunctionVariablei  z@Points to a torch function/method that should be put in FX graphr3   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)ru   rv   trace_rulesr  nonstrict_traceable)rw   rq   r  rx   r  ry   s        rM   rv   %TorchInGraphFunctionVariable.__init__  s/    )&)=&"=e"D#6 rL   c                 <    SU R                    SU R                   S3$ )NzTorchInGraphFunctionVariable(z, nonstrict_traceable=r   )rq   r  r   s    rM   r   %TorchInGraphFunctionVariable.__repr__  s%    .tzzl:PQUQiQiPjjkllrL   c                     U R                   $ r   r   r   s    rM   get_function)TorchInGraphFunctionVariable.get_function  r   rL   c                    ^>^?^@^A^B^C^D^E^F^G 0 mEUE4S jn SSK Jn  SSKJm>Jm?Jm@JmAJmBJmCJ	mD  SSK
JmFJmG  U " [        5       6   SBU>4S jj5       nU " [        6   SBS j5       nU " [        R                   R"                  R$                  5        SBS	 j5       nU " [        R&                  R(                  R*                  R,                  5      SBS
 j5       nU " [.        R0                  5      SBS j5       nU " [        R2                  5      SBS j5       nU " [        R4                  [        R                   R6                  5      SBU>UCUD4S jj5       nU " [        R8                  [        R:                  5      SBU>UC4S jj5       n	U " [        R<                  5      SBU>UC4S jj5       n
U " [        R>                  5      SBS j5       nU " [@        6 SBUC4S jj5       nU " [        RB                  RD                  RF                  RH                  [        RB                  RD                  RF                  RJ                  [        RB                  RD                  RF                  RL                  [        RB                  RD                  RF                  RN                  [        RB                  RD                  RF                  RP                  5      SBS j5       nU " [        RR                  5      U>U@4S j5       nU " [        RT                  5       SC SBU?4S jjj5       nU " [        RV                  5      U>U?4S j5       nU " [        RX                  RZ                  5      U>4S j5       nU " [        RX                  R\                  5      U>4S j5       nU " [        R                   R^                  [        R                   R`                  [        R                   Rb                  5      SBU>4S jj5       nU " [d        Rg                  S [i        5        5       5      6 SBUA4S jj5       nU " [        Rj                  5      SBUCUG4S jj5       nU " [        Rl                  Rn                  5      SBS j5       nU " [        Rp                  Rr                  Rt                  5        SBU>UC4S jj5       nU " [        RF                  Rv                  Rx                  5      SBS j5       nU " [        RB                  Rz                  5      SBS j5       nU " [        R&                  R|                  R~                  [        R&                  R|                  R~                  R                  5      SDS! j5       nU " [        R&                  R|                  R                  [        R&                  R|                  R                  R                  5      SDS" j5       nU " [        R                  5      SBS# j5       nU " [        R                  5      UC4S$ j5       nU " [        R                  5        SBS% j5       nU " [        R                  5      SBUC4S& jj5       nU " [        R                  5      SBU>4S' jj5       n U " U5      SBUF4S( jj5       n![        R                  " 5       (       aJ  SS)KIJJn"JKn#JLn$JMn%JNn&  SS*KOJPn'  U " U"U#U$U&U%5        SBU>4S+ jj5       n(U " U'R                  5      SBUF4S, jj5       n)U " [        R                  R                  5       SDS S-. SBS. jjj5       n*U " [        RB                  R                  R                  5      SBS/ j5       n+U " [        R                  R                  R                  R                  5      SBU>UB4S0 jj5       n,U " [        R                  R                  R                  R                  5      SBU>UB4S1 jj5       n-U " [        R                  R                  R                  R                  5      SBU>UB4S2 jj5       n.U " [        R                  R                  R                  R                  5      SBU>UB4S3 jj5       n/U " [        R                  R                  R                  R                  5      SBU>UB4S4 jj5       n0U " [        R                  R                  R                  R                  5      SBU>UB4S5 jj5       n1U " [        R                  R                  R                  R                  5      SBUB4S6 jj5       n2U " [        R                  R                  R                  R                  5      SBUB4S7 jj5       n3U " [        R                  R                  R                  R                  5      SBU>UB4S8 jj5       n4U " [        RX                  R                  R                  5        SBS9 j5       n5U " [        RX                  R                  R                  5        SBUD4S: jj5       n6U " [        R                  R                  R                  5        SBS; j5       n7U " [        R                  5      SBUBUC4S< jj5       n8U " [        RX                  R                  5        SBS= j5       n9U " [        RX                  R                  5        SBU>4S> jj5       n:U " [        RX                  R                  5        SBU>4S? jj5       n;U " [        RX                  R                  5      SBS@ j5       n<U " [        R                  5        SBU>4SA jj5       n=TE$ )Ez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.c                  B   >^  U U4S jn[        T S   5      (       d   eU$ )Nc                 >   > T H  nUT;  d   U5       eU TU'   M     U $ r   rK   )handlerfnfnshandlerss     rM   	_registerOTorchInGraphFunctionVariable._get_handlers.<locals>.register.<locals>._register  s0    BX-1r1-#*HRL  rL   r   )r   )r  r  r  s   ` rM   register<TorchInGraphFunctionVariable._get_handlers.<locals>.register  s%     CF####rL   r   )
SDPAParamsr"   )r   DeterministicAlgorithmsVariabler   StreamContextVariableSymNodeVariableTensorVariableUserDefinedObjectVariable)wrap_fx_proxyr   c                   > U(       d  U(       a   eU R                   [        R                  R                  [        R                  R
                  R                  [        R                  R                  [        R                  R                  [        R                  R                  4;   a  UR                  5         TR                  [        5       U R                      5      $ r   )rq   r5   rC   rB   r@   rA   rD   rE   rF   mark_inconsistent_side_effectsr   rN   rw   r   r   rx   r   s       rM   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QrL   c                     U(       a   eU R                   [        R                  R                  4;   Ga0  [	        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)rq   r5   r9   _dispatch_keysr   r   r   r  proxynodemeta_subclasses
FakeTensorDispatchKeySetDispatchKeyPythonPythonTLSSnapshotDispatchKeySetVariabler   )rw   r   r   rx   r%  dkss         rM   !handle_dispatch_key_set_functionsUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_dispatch_key_set_functions  s$    :zzehh55774yA~%~!$q'9+C+CDDDD $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BrL   c                 h    [         R                  " U[        R                  R	                  5       5      $ r   )r$   buildr5   	overridesget_default_nowrap_functionsrw   r   r   rx   s       rM   #handle_get_default_nowrap_functionsWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_default_nowrap_functions  s)     #((EOO@@B rL   c                 l    UR                  [        R                  " U[        R                  5      X#5      $ r   )inline_user_function_returnr$   r5  r   accumulate_gradr8  s       rM   handle_accumulate_grad_KTorchInGraphFunctionVariable._get_handlers.<locals>.handle_accumulate_grad_  s-    11%%b)*C*CDd rL   c                     [        X#5      (       d5  UR                  [        R                  " U[        R
                  5      X#5      $ g r   )r   r<  r$   r5  r   radiansr8  s       rM   handle_radiansBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_radians  s=    0>>55#))"i.?.?@$  ?rL   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)rw   r   s     rM    handle_is_inference_mode_enabledTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_inference_mode_enabled  s4    TP&22&55	rL   c                   > [        UT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)r   rq   r5   r6  is_tensor_liker   r   )rw   r   r   r   r  r  s      rM   handle_is_tensorDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_tensor(  sh    #~..

eoo<<<s$=>>CII';<<'..t44'..u55rL   c                   > Un[        UT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 g )Nzcalling )r   dtyperq   r5   is_floating_pointr   
is_complexAssertionError)rw   r   input	input_argr   r  s       rM   handle_is_floating_pointLTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_floating_point3  s    
 I)^449T::!8!88+229??3T3TUUZZ5#3#33+229??3M3MNN(8DJJ<)@AA :U4rL   c                    > [        UT5      (       a9  UR                  5       (       a$  TR                  [        UR                  5      5      $ [        UT5      (       a  UR                  US/ 0 5      $ g )Nnumel)r   
valid_sizer   r   sizecall_method)rw   r   rX  r   r  s      rM   handle_numel@TorchInGraphFunctionVariable._get_handlers.<locals>.handle_numelA  sa    %00U5E5E5G5G'..wuzz/BCCE>22((Wb"== 3rL   c                 B    [        U5      S:X  a  US   $ [        S5        g )Nr"   r   z:torch.compile is used as a decorator in the compiled frame)r   r   r8  s       rM   handle_torch_compileHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_compileI  s    4yA~AwVWrL   c                 R   > [        UT5      (       d   eUR                  US/ 0 5      $ Nr_  )r   r`  )rw   r   rX  r  s      rM   handle_tensor_size_rewritesOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_tensor_size_rewritesQ  s-    e^4444$$RR88rL   c                 &    U R                  XU5      $ r   )_call_ntupler8  s       rM   handle_ntupleATorchInGraphFunctionVariable._get_handlers.<locals>.handle_ntupleV  s     $$Rv66rL   c                 v   > [        TR                  5        TR                  [        R                  " 5       5      $ r   )r   _guards_singletonr   r5   is_grad_enabled)rw   r   r   r   s     rM   handle_is_grad_enabledJTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_grad_enabled`  s,    *<<=#**5+@+@+BCCrL   c                    > U(       a   UR                  5       (       a  [        S5        TR                  XR                  5       5      $ )Nz2torch.use_deterministic_algorithms(warn_only=True))r   r   r   )rw   r   mode	warn_onlyr  s       rM   #handle_use_deterministic_algorithmsWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_use_deterministic_algorithmse  s9     Y99;;RS299">U>U>WXXrL   c                 v   > [        TR                  5        TR                  [        R                  " 5       5      $ r   )r   ro  r   r5   $are_deterministic_algorithms_enabled)rw   r   r   r  s     rM   +handle_are_deterministic_algorithms_enabled_TorchInGraphFunctionVariable._get_handlers.<locals>.handle_are_deterministic_algorithms_enabledm  s,    9KKL#**5+U+U+WXXrL   c                    > [        [        R                  5        TR                  UR                  R
                  5      $ r   )r   r'   ro  r   symbolic_torch_function_statetorch_function_subclass_enabledrw   r   r   s     rM    handle_is_torch_function_enabledTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_enabledr  s6    6HHI $**00PP rL   c                    > [        [        R                  5        TR                  UR                  R
                  (       + 5      $ r   )r   r'   ro  r   r}  torch_function_mode_enabledr  s     rM   %handle_is_torch_function_all_disabledYTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_all_disabled{  s7    6HHI#**44PPP rL   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   .0r   s     rM   	<genexpr>`TorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_function.<locals>.<genexpr>  s     95a&q))5s   )r   r   r,   unpack_var_sequencer   any)rw   r   r   elemsr   s       rM   handle_has_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_function  s_     t9>ja-&H&H Q++B/ 
 $**9599 rL   c              3   >   #    U  H  u  pUR                   v   M     g 7fr   )stream)r  r   device_interfaces      rM   r  =TorchInGraphFunctionVariable._get_handlers.<locals>.<genexpr>  s       +M'A !''+Ms   c                 &   > TR                  X5      $ r   )r   )rw   r   r  r  s      rM   handle_device_interface_streamRTorchInGraphFunctionVariable._get_handlers.<locals>.handle_device_interface_stream  s     )//;;rL   c                    > [         R                  (       d  [        S5        [        (       d  [        S5        T" TUUR                  R
                  " S[        R                  /[        U0 5      Q76 S S9$ )Nz-torch.from_numpy. config.trace_numpy is Falsez(torch.from_numpy. NumPy is not availabler   )
target_clsr   r'  r%  )	r   trace_numpyr   npr   r   r5   	as_tensorr    )rw   r   r   r  r   s      rM   handle_from_numpyETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_numpy  sh    %%MN2HI$)ii,,#OO 'tR0
 #	 	rL   c                     U$ r   rK   )rw   r   the_type	the_values       rM   handle_jit_annotateGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_jit_annotate  s    rL   c                   > U(       a   S5       e[        UT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   )rT  device)	r   r5   tensorrT  r  r   r   cudnnis_acceptable)rw   r   r  extra
tensor_inpr   r  s        rM   handle_cudnn_is_acceptableNTorchInGraphFunctionVariable._get_handlers.<locals>.handle_cudnn_is_acceptable  sw     EEE9fn55 D5 av||FMMRJ#**$$22:> rL   c                 J    [         R                  R                  " U/UQ70 UD6$ r   )r   BackwardHookVariabler   r8  s       rM   handle_backward_hookHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_backward_hook  s#    1188MdMfMMrL   c                 .    U R                   " U/UQ70 UD6$ r   )call_nn_parameterr8  s       rM   handle_parameterDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_parameter  s    ))">t>v>>rL   Nc                 4    Ub  UR                  USU/0 5      $ g rg  r`  self_r   rw   dims       rM   handle_sym_sizeCTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_size  s'     ''FSE2>> rL   c                 4    Ub  UR                  USU/0 5      $ g )Nstrider  r  s       rM   handle_sym_strideETorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_stride  s%    ''HseR@@ rL   c                 f   [        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 g g )N   rq   r"   r   )r   r  r5   rR   r   rQ   rO   )rw   r   r   rx   r   s        rM   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  9I"3~rL   c                    > [        UT5      (       ai  [        [        R                  R                  R
                  5      R                  X/0 5      n[        [        R                  5      R                  XU/U5      $ g r   )r   r  r5   opsaten_local_scalar_denser   ra   )rw   r   r_  
fill_valuerx   r   r  s         rM   handle_full?TorchInGraphFunctionVariable._get_handlers.<locals>.handle_full  sh    *n555IINN66-L"5  4EJJ?MMv 	 6rL   c                     [        U5      S:X  aW  [        US   [        5      (       d>  U(       d6  UR                  [        R
                  " U[        R                  5      UU5      $ g g g )Nr  r   )r   r   r+   r<  r$   r5  r   foreach_lerp_inplace)r   r   r   rx   s       rM   "handle_inplace_foreach_lerp_scalarVTorchInGraphFunctionVariable._get_handlers.<locals>.handle_inplace_foreach_lerp_scalar  s]     4yA~ja,&G&GPV55#))"i.L.LM  QW&G~rL   c                    > [        U5      S:X  aS  [        US   T5      (       a>  U(       d6  UR                  [        R                  " U[
        R                  5      UU5      $ g g g )Nr   r   )r   r   r<  r$   r5  r   foreach_pow_scalar)r   r   r   rx   r  s       rM   handle_foreach_pow_scalarMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_foreach_pow_scalar  s]     4yA~*T!Wn"E"Ef55#))"i.J.JK  OU"E~rL   c                    > UR                  5       (       a  UR                  5       (       d4  [        U[        R                  5      (       a  UR                  5       (       a  T" S 5      $ g g r   )is_python_constantr   r   r   r  evaluate_expr)rw   r   	conditionmessager   s       rM   handle_assertATorchInGraphFunctionVariable._get_handlers.<locals>.handle_assert  sX    ,,..93O3O3Q3Q9i&?&?@@++--'-- . ArL   c           
         > T" UUR                   R                  " S[        R                  R                  /[        X#5      Q76 US9$ )Nr   )r'  
param_vars)r   r   r5   r9   _SDPAParamsr    )rw   r   r   rx   r  s       rM   handle_sdpa_paramsFTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sdpa_params  sI     ii,,#HH(( 't4
   rL   )_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  a  [        US   [        T45      (       d   eOY[        U5      S:X  a/  [        US   [        5      (       a  [        US   T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   r*   r+   rW  rq   r   r$   r5  )rw   r   r   r   args_as_valueinvocation_resultr   s         rM   &handle_constant_processgroup_functionsZTorchInGraphFunctionVariable._get_handlers.<locals>.handle_constant_processgroup_functions!  s     t9>%d1g0DFV/WXXXXY!^%d1g|<<Q!1B B   B )/v 6$$(JJ<1  FJ JTc!7!7!9T J$(JJ$>!
 ',,RCC !Ks   Cc           
        >^ ^	^
 USS   Vs/ s H  oDR                  5       PM     snm	UR                  5        VVs0 s H  u  pVUS;  d  M  XVR                  5       _M     snnm
S Vs0 s H  oUU;   d  M
  XSU   _M     nnSU	U
U 4S 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 )	Nr"   shaper  c                 8   > TR                   " U /TQ70 TDXS.D6$ )Nr  r   )r   r  r  r  kwargs_as_valuerw   s      rM   fn_with_prim_typesaTorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local.<locals>.fn_with_prim_typesS  s/    ::)-<DI rL   zprim r   r   r   r'  )NN)r   itemsrq   r   r   r   r    )rw   r   r   rx   r   kvkwargs_to_be_proxiedr  r  r  r  s   `        @@rM   handle_from_localETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_localE  s    BFab JA!5!5!7 J !'# . 33 .A++-- .# +>(*=QfLAayL*= % (  /6

8K8K.K"+$))00'* +!!WI0
 
% !K#
(s   CCC'	C#4	C#)layoutc                    SSK Jn  U(       a-  UR                  5       [        R                  :X  a  [        S5        [        X&5      (       d  [        S5        g g )Nr"   )BaseListVariablez3torch.compile does not support strided NestedTensorz!nested_tensor with non-list input)listsr  r   r5   stridedr   r   )rw   r   tensor_listr  r   rx   r  s          rM   handle_nested_tensorHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_nested_tensorg  s@     0&335FSTk<<AB =rL   c                     [        U5      [        U5      -   S:X  d>  [        U5      S:X  a=  US   R                  5       (       a$  US   R                  5       S:X  a  [        S5        g g g g )Nr"   r   z<torch.nn.functional.one_hot with data-dependent output shape)r   r  r   r   r8  s       rM   handle_one_hotBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_one_hotw  sd    4y3v;&!+D	QG..00G..0B6R 7 1 rL   c                   > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ [        UT5      (       a  U$ g r   )
r   r   r   r   r5   r;   experimentalsymbolic_shapesguard_size_oblivioussym_numrw   r   exprr   r  s      rM   handle_guard_size_obliviousOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_size_oblivious  sj    $00 !1188HH))99NN 
 D"233 4rL   c                   > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ [        UT5      (       a  U$ g r   )
r   r   r   r   r5   r;   r  r  guard_or_truer  r	  s      rM   handle_guard_or_trueHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_or_true  sg    $00 !1188HH))99GGU  D"233 4rL   c                   > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ [        UT5      (       a  U$ g r   )
r   r   r   r   r5   r;   r  r  guard_or_falser  r	  s      rM   handle_guard_or_falseITorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_or_false  sg    $00 !1188HH))99HHV  D"233 4rL   c                   > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ [        UT5      (       a  U$ g r   )
r   r   r   r   r5   r;   r  r  statically_known_falser  r	  s      rM   handle_statically_known_falseQTorchInGraphFunctionVariable._get_handlers.<locals>.handle_statically_known_false  sh    $00 1188HH))99PP 
 D"233 4rL   c                 n  > [        UT5      (       a  UR                  nOG[        UT5      (       a  UR                  nO)[        R                  R
                  R                  S5      e[        R                  R                  [        R                  R                  R                  R                  U5      5      $ )Nzbranch not supported)r   r  rq   r5   r@   excUnsupportedr   r   r   r;   r  r  guard_scalarrw   r   r
  valr   r  s       rM   r  @TorchInGraphFunctionVariable._get_handlers.<locals>.guard_scalar  s    $00llD"233jjmm''334JKK--44%%55BB3G rL   c                   > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ [        UT5      (       a  U$ g r   )
r   r   r   r   r5   r;   r  r  statically_known_truer  r	  s      rM   handle_statically_known_truePTorchInGraphFunctionVariable._get_handlers.<locals>.handle_statically_known_true  sh    $00 1188HH))99OO 
 D"233 4rL   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   r   r  r   r  s     rM   r  UTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_and.<locals>.<genexpr>       A5a:a115   c              3   @   #    U  H  oR                  5       v   M     g 7fr   r   r  s     rM   r  r(         61**,,   r  )allr   r5   r;   r  r  sym_andrw   r   termsr  s      rM   handle_sym_andBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_and  s`    A5AAA&--HH))99AA66 ! .   BrL   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   r&  r'  s     rM   r  TTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_or.<locals>.<genexpr>  r)  r*  c              3   @   #    U  H  oR                  5       v   M     g 7fr   r,  r  s     rM   r  r8    r-  r.  r/  )r0  r   r5   r;   r  r  sym_orr2  s      rM   handle_sym_orATorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_or  s`    A5AAA&--HH))99@@66 ! .   BrL   c                   > [        UT5      (       a  UR                  nO[        UT5      (       a  UR                  nOg [        R                  R                  [        R                  R                  R                  R                  U5      5      $ r   )r   r  rq   r   r   r   r5   r;   r  r  has_static_valuer  s       rM   handle_has_static_valueKTorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_static_value  sj    $00llD"233jj--44%%55FFsK rL   c                 J    SSK Jn  [        U5      R                  U/ UQU5      $ )Nr   )_unsafe_set_version_counter)tensor_version_oprB  r  r   )rw   r   r   rx   rB  s        rM   !handle_unsafe_set_version_counterUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_unsafe_set_version_counter  s*     H/+mB$01rL   c                 `   > T" [         R                  R                  R                  5       5      $ r   )r5   r9   r   peek_interpreter_stack)rw   r   r   rx   r  s       rM   'handle_functorch_peek_interpreter_stack[TorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_peek_interpreter_stack  s(     -##::< rL   c                     US   R                   n[        [        R                  R                  R                  U5      5      $ Nr   )rq   FuncTorchInterpreterVariabler5   r   pyfunctorchcoerce_cinterpreter)rw   r   r   rx   cinterpreters        rM   0handle_functorch_pyfunctorch_coerce_cinterpreterdTorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_pyfunctorch_coerce_cinterpreter  s8      7==L/  ,,@@N rL   c                    >^ UUU4S jmS nU(       a  US   nOSU;   a  US   n[        UT5      (       dD  T" U5      (       a6  [        [        R                  R                  5      R                  U/ UQU5      $ g g )Nc                    > [        U TT4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   rK   )r  ycheck_any_unspecs     rM   r  tTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspec.<locals>.<genexpr>  s     DGq/22Gs   F)r   r+   r,   r  r  )r   r  r  rV  s    rM   rV  aTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspec	  sD    a./!BCCL-#@AADAGGDDD !rL   r   data)r   r  r5   _refsr  r   )rw   r   r   rx   data_argrV  r  r  s        @rM   handle_torch_tensorGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor  s~    	! H76!!&> h77<LX<V<V 4EKK4F4FGUU$  =W7rL   c                     U(       d  U(       a   eUR                   R                  (       d  [        S5      e[        R                  " U5        UR                   R                  5       $ )Nz/Popping from an empty torch function mode stack)r}  
mode_stackr   r0   register_mutationpop_torch_function_moder8  s       rM   handle_pop_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_pop_torch_function"  sM     F**33>>#$UVV*<<R@33KKMMrL   c                    > [        U5      S:X  a  U(       a   e[        R                  " U5        UR                  R	                  US   5        TR                  S 5      $ Nr"   r   )r   r0   r`  r}  push_torch_function_moder   r!  s       rM   handle_push_torch_functionNTorchInGraphFunctionVariable._get_handlers.<locals>.handle_push_torch_function,  sO     t9>&00*<<R@,,EEd1gN#**400rL   c                    > U(       d  U(       a   eTR                  [        UR                  R                  5      5      $ r   )r   r   r}  r_  r!  s       rM   handle_len_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_len_torch_function5  s7     F**#**B44??@ rL   c                     [        U5      S:X  a  U(       a   eUS   R                  5       nUS:  a#  U[        UR                  R                  5      :  d   eUR                  R                  U   $ re  )r   r   r}  r_  )rw   r   r   rx   inds        rM   handle_get_stack_atGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_stack_at>  sc    t9>&00q',,.C!8c"*J*J*U*U&V VVV33>>sCCrL   c                   > [         R                  " U5        US   R                  5       (       a+  US   R                  5       c  [         R                  " U5        O[         R
                  " U5        TR                  S 5      $ rK  )r0   r`  r  r   clear_default_device!register_device_context_insertionr   r!  s       rM   handle_set_default_deviceMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_set_default_deviceE  sf     +<<R@Aw))++Q0J0J0L0T.CCBG.PPQST#**400rL   r   )Fr   )ntorch.backends.cudar  r   r   r  r   r  r  r  r  builderr  r   rN   dispatch_key_set_functionsr5   r6  r7  __wrapped__r  inductoraccumulate_grad_defaultr   rA  is_inference_mode_enabled	is_tensorrP  rU  rV  r]  compile!REWRITE_OPS_TO_TENSOR_SIZE_METHODrG   rH   utils_single_pair_triple
_quadruple_ntuplerp  use_deterministic_algorithmsry  r9   _is_torch_function_enabled_is_torch_function_all_disabledr   has_torch_function_variadichas_torch_function_unarydictfromkeysr   
from_numpyr6   annotater   r  r  hooksBackwardHook	Parameterr  sym_sizeint
sym_strideaddcdivra   _foreach_lerp__foreach_pow_assertr)   is_available"torch.distributed.distributed_c10dr  r  r  r  r  torch.distributed.tensorr  
from_localnestednested_tensor
functionalone_hotr;   r  r  r  r  r  r  r  r!  r1  r:  r>  	_autogradrB  r   rG  rM  rN  r  _pop_torch_function_stack_push_on_torch_function_stack_len_torch_function_stack_get_function_stack_atset_default_device)Hr  r  r"  r2  r9  r>  rB  rL  rQ  rZ  ra  rd  rh  rl  rq  rv  rz  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"  r4  r;  r?  rD  rH  rP  r\  rb  rg  rj  rn  rs  r   r  r   r  r  r  r  r  r  r   sH                                                                 @@@@@@@@@@rM   _get_handlers*TorchInGraphFunctionVariable._get_handlers  s	   
 	 	3	
 	
 	
 	>	*,	-	R-	R 
.	R 
-	.	C-	C 
/	C6 
%//>>JJ	K		-		 
L		 
%))$$55==	>	 
?	
 
$,,		 
 	 
%11	2		 
3		 
%//5??#A#A	B	6 	6 
C	6 
##

	B	

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

	7

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


	


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

	<

	< 
%""	#	 
$	  
%))$$	%	 
&	 
%..&&44	5	-	 
6	" 
%++##00	1	N 
2	N 
%(($$	%	? 
&	? 
%))..))599>>+B+B+F+F	G	? 
H	?
 
%))..++UYY^^-F-F-J-J	K	A 
L	A 
%--	 	 
!	 
%**		 
	 
%&&	'	*	 
(	 
%$$	%	 
&	 
%--	 	. 
!	. 
*			 
		 ++--  9'"'4D1DD: g(() *B 
%,,,,	- 	C
 	C'	C 
.	C 
%((%%--	.	 
/	 
%((''77LL	M
	 
N
	 
%((''77EE	F	 
G	 
%((''77FF	G	 
H	 
%((''77NN	O	 
P	 
%((''77DD	E		 
F		 
%((''77MM	N	 
O	 
%((''77??	@	 
A	 
%((''77>>	?	 
@	 
%((''77HH	I
	 
J
	 
%(($$@@	A	1-	1 
B	1 
%((%%<<	=	-	 
>	 
%""..BB	C	-	 
D	 
%,,		 
 	4 
%((44	5	N-	N 
6	N 
%((88	9	1-	1 
:	1 
%((44	5	-	 
6	 
%((11	2	D 
3	D 
%**	+	1-	1 
,	1$ rL   r   r2   r   rx   r   r$   c                 "  ^3^4^5 SSK JnJm3Jn  SSKJn  U R                  (       GaJ  SS KJs  J	n  SSKJ
nJn	  SSKJm4  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[1        U[$        5      (       a  [3        UR4                  5      S	:X  d   eUR4                  u  p[1        U[6        5      (       d   eUR4                   HK  nUR9                  5       nU	" U5      (       a  M"  UR9                  5       R:                  n[=        S
U S35        MM     UR4                   Vs/ s H  nUR?                  5       PM     nn URA                  5       nU RJ                  m5U4U54S jnU" U5      u  nnURL                  RO                  T5RP                   S3U5      nURL                  RO                  T5RP                  S-   W5      n[S        U5      URT                  l)        [S        U5      URT                  l)        UU/UQ7nURL                  RW                  SUU0 5      nU" UU5      nU$ U RY                  XU5      (       a  [[        XX#5      $ U R]                  5       (       a  [_        X#5      (       a  U RJ                  [`        ;   a=  [c        U Rd                  5      n[g        URi                  [j        Rl                  5      5        URo                  U RA                  5       " U V s/ s H  n U RA                  5       PM     sn 0 UR5                  5        V!V"s0 s H  u  n!n"U!U"RA                  5       _M     sn"n!D65      $ U Rq                  5       (       Ga]  U RJ                  RP                  n#U(       Ga-  [1        US   [*        R                  5      (       Ga
  US   n$U$Rd                  b  [s        [t        Rv                  Rx                  U#5      (       a  [{        [t        Rv                  Rx                  U#5      m5[s        T5S5      (       a  [s        T5T5R}                  5       S   5      (       ax  [t        R~                  R                  [{        T5T5R}                  5       S   5      R                  ;   a5  [        SSS[        U RJ                  5       S3/ [        R                  QSPS9  U R                  XU5      $ U R                  5       R                  U RJ                  5      n%U%(       a  U%" X/UQ70 UD6n&U&(       a  U&$ [        U34S jU 5       5      n'[        S U 5       5      n([{        U RJ                  SS5      S:X  ae  U RJ                  RP                  [        ;   aG  U'(       a@  U((       a9  S [        U RJ                  5       S!3n)[        R                  U)5        [=        U)5        U RJ                  n*U'(       aY  S"U RJ                  RP                   3n+[{        U RJ                  SS 5      S#:X  a%  [s        [t        U+5      (       a  [{        [t        U+5      n*S n,S$U;   aR  [1        US$   [*        R                  5      (       a0  US$   R                  RT                  R                  S%   R                  n,U" UURL                  RV                  " SU*/[        X#5      Q76 S&9n-[1        U-U5      (       a)  S'U;   a#  US'   RA                  5       (       a  [=        S(5        S$U;   Gam  [1        US$   [*        R                  5      (       a  US$   RA                  5       Gb6  [1        U-[$        5      (       a  [1        US$   [$        [6        45      (       d   e[        US$   R4                  U-R4                  5       Ho  u  n.n/[1        U.[*        R                  5      (       d  M'  [1        U/[*        R                  5      (       d  MH  U.R                  U/R                  :w  d  Md  [=        S)5        Mq     U-$ [1        U-U5      (       a  [1        US$   U5      (       d   eS%US$   R                  RT                  R                  ;   d   eU-R                  RT                  R                  S%   n0US$   R                  RT                  R                  S%   n1U,U0R                  :w  a  [=        S)5        [t        R                  R                  U15      (       d  [=        S*5        U-$ [1        U-U5      (       GaX  U-RJ                  GcJ  [1        US$   U5      (       a  S%US$   R                  RT                  R                  ;   d   eUS$   R                  RT                  R                  S%   n1[t        R                  R                  U15      (       d  [=        S*5        U-$ [1        US$   [6        5      (       a  [        US$   R4                  5       H  u  n2n S%U R                  RT                  R                  ;   d   eU R                  RT                  R                  S%   n1[t        R                  R                  U15      (       a  Mu  [=        S+5        M     U-$ [=        S,[S        US$   5       35        U-$ s  snf ! U aw  nURB                  R9                  5       nUR:                  nSS KJ"s  J#n  URI                  U5      (       a  [=        SU S35         S nAG	NJ[=        SU SU S35         S nAG	NbS nAff = fs  sn f s  sn"n!f )-Nr"   )r   r  r  r  r   )func_to_graphableis_graphable_type)fake_tensor_tls)tree_flatten)#AsPythonConstantNotImplementedErrorr   z
For `nonstrict_trace`-ed function, the only allowed input types are basic types (e.g., torch.Tensor, int, float) or pytree containers of those. Here you are calling the function with arguments that contain a value of type <z>, please use 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`
z`
You are calling 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.

Please construct the object _outside_ the `torch.compile` region, or submit an issue to GitHub.
    z
You are calling a `nonstrict_trace`-ed function where one one of the inputs has been registered with a `pytree_flatten` that puts an object of type <z> into the context.

Please consider modifying that `pytree_flatten` to avoid putting the object into context, and apply one of the following to <z>
  * `torch.utils._pytree.register_constant`
  * `torch.utils._pytree.register_dataclass`
  * `torch.utils._pytree.register_pytree_node`

If the above doesn't work, please subtmit an issue to GitHub.
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   rx   old_valresr  r  s       rM   
patched_fn>TorchInGraphFunctionVariable.call_function.<locals>.patched_fn  sH     *HHAE>Md-f-CELOB
 FMOBs   ' 	0_spec_input_specr   	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.rE  c              3   <   >#    U  H  n[        UT5      v   M     g 7fr   r&  r'  s     rM   r  =TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>  s     &Tt!z!_'E'Etr*  c              3   v   #    U  H/  n[        U[        R                  [        R                  45      v   M1     g 7fr   )r   r   r   r  r  s     rM   r  r    s2      !
 q955y7P7PQRRs   79r   r5   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.
_sym_r   outr%  r  requires_gradzfactory functions that return tensors that require grad are not supported.
Either create the tensor outside the compiled region, or do not set the tensor to require_gradz*out variants with resizing on graph inputsz9out= op was called where output tensor was non-contiguouszGout= op was called where some of the output tensors were non-contiguouszout variant of )Xr   r   r  r  rv  r  r  "torch._higher_order_ops.flat_apply_higher_order_ops
flat_applyr  r  torch._subclasses.fake_tensorr  torch.utils._pytreer  baser  r,   r5  r(   r   UserFunctionVariabler   r   r   r  r+   python_typer   r   r   r   vtr  _pytreeis_constant_classrq   r   %register_static_attr_and_return_proxyr   typer(  r   torch_function_override_enabledr.   r   r   #constant_fold_functions_need_guardsr   rl   r   rm   r   EQUALS_MATCHr   is_tensor_methodr   r5   r  r  r   r  Taginplace_viewtagsr   r#   r   SUPPORTABLEcall_tensor_methodr  getr  r0  bin_opsr   r   warningr'  r)  r  r    zip_size_prims_commonis_contiguous	enumerate)6rw   r   r   rx   r   r  r  r  r  r  r  r  packed_input_vtout_vtflat_args_vtsinput_spec_vtflat_arg_vtarg_type	type_nameproxified_flat_args
input_specetyppytreer  r   f_specf_spec_proxyinput_spec_proxyall_argsr'  rl   r   r  r  r   
tensor_varspecial_handlerr   any_symints_or_symfloatsall_ints_or_floatsmsgfn_torch_sym_opfake_out_shapetensor_variable
out_tensorresult_tensorfake_tensorfake_outidxr  r  r  s6                                                      @@@rM   r   *TorchInGraphFunctionVariable.call_functionZ  s	    	HG*###CC F8A ,11]((24E4K4KB4WXO 33LAOO%rF fm44V\\9Ja9OOO+1<<(Mm\::::  -22&224(22 + 7 7 9 F FI!` aj  `k k	  3  ;H:M:M#:M;$$&:M   #*==?
8 B
 **5IAv 99JJ;;-u%vL  "yyNNm+Z  &*&\L")-j)9!!&$&6M9LMH II**?JRTUE"2u-F M//&AA*2TBB))++0M1
 1
 zz@@1$++>f//0I0IJK#**'')6:;da**,d;=C\\^L^TQq!..00^L    ""::&&D
47I,D,DEE!!W
$$0WUYY^^T5R5R 6BK00#Bq(9::!II22"2r||~a'89>>? )$@$&*`ahimisisat`uuv(w#!2!>!># Q#	 **2V<<,,.224::>$T???F#&&Tt&T#T   !
!
 

 DJJb1W<

##w.("		TZZ C
 KK#
 jj#"4::#6#6"78Ltzz<6&@W|F F e\2 F?z&-9Q9QRR $E]0055::?KQQN'))(( #40
 776)'::<<b F?ve}i&@&@AAu002: /=99!&--1NOOOO145M'')>)>2-J #:y/G/GHH&}i6N6NOO&,,(../
 &&RS2l U O^<<!&-@@@@&&-*=*=*B*B*G*GGGG-3388==oN!%=..3388I![%6%66 ""NO**88BB "S< 5 ?,<==#))1 fUm^<<*fUm.A.A.F.F.K.KKKK%e}2277<<_MH ..<<XFF &W    u|<<"+F5M,?,?"@Q.!'',,2C2CCCC#$77<<#4#4_#E$22@@JJ * i #A  VE]0C/DEFQ# 7 dd&&(,,	44++C00!``i_j k  "V W`  Va a~ H  ~I I	 b <Ls1   /jj (lllAk>&k>>l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UU4S 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   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U  S35        g )Nztorch.nn.modules.utils._ntuple(r   )has_unpack_var_sequencer   r,   listr  r  r   r   r5   rG   rH   r  r  r   r   )rq   countr   s    rM   rl  @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   ?waHIrL   )rq   r5   rG   rH   r  r  r   __closure__cell_contentsr   r  r   LambdaVariable)rw   r   r   rx   rl  r  s    `   @rM   rk  )TorchInGraphFunctionVariable._call_ntuple  s    ::))//777G..0EJJ**1-;;E%%%%%z	J ::))//777++M:: a))rL   c           
         UR                   (       a  [        S5        [        U[        R                  5      (       a   UR                  5       n[        U[        R                  5      (       d  [        SU S35        UR                  (       a  U R                  XU5      $ [        U[        5      (       d  [        UR                  5      (       a  [        S5        [        5       (       d  [        S5         [        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                   R#                  [$        WWWU/5      nUR&                  (       a  UR)                  US/ 0 5      nSSKJn	  U	" UUR                   R/                  S[0        UR3                  5       UR3                  5       40 5      UR                  S9n
[        U
[        R                  5      (       d   e[4        R6                  R8                  U
l        SU
l        U
$ ! [         a    [        S5         GNf = f! [         a  n[        S
U 35         SnAGN"SnAff = f)z>A call to torch.nn.Parameter() gets lifted to before the graphz3nn parameter construction not supported with exportz)Parameter(requires_grad=...) not constantzParameter(data=z) not implementedz.Parameter constructor with tensor subclass NYIz4Workaround for issues with nn_parameter constructionr  rT  r  zParameter not python_constant: Ndetachr"   r  r   rk   F)exportr   r   r   r$   r   NotImplementedErrorr  rl   _nn_param_via_prefix_insertr/   r
   
class_typer   tuplevar_getattrr   synthetic_graph_inputr   r  r`  rv  r  r   r   r   r5   rG   r  has_grad_fn)rp   r   rY  r  r  rT  r  r  placeholderr  r   s              rM   r  .TorchInGraphFunctionVariable.call_nn_parameter  s*    99OPmY%>%>??K - @ @ B $	 8 899OD61BCD ;;222]KK.
 
/@@JK022PQ	A$**2w7JJLME$$R1DDFE%%b(3FFHF ii55%ufm'L
 ##B"b9D*II"")+"6"6"89	 %%
 &)":":;;;;!HH.. # q ' KIJK, # 	A;A3?@@	As*   I 3A)I  II 
J*I>>Jc                 b  ^ U R                   R                  5       n[        U 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5        [!        U5      n["        R$                  R'                  U R                   R)                  UR                  5       R                  5      5      n[*        R,                  " XU5      nUR/                  5       n[0        R2                  " 5       R4                  R6                  R9                  U5        U$ )Nc                  (   > T R                  SS5      $ )Nztorch.nnr  )load_import_from)cgs   rM   <lambda>JTorchInGraphFunctionVariable._nn_param_via_prefix_insert.<locals>.<lambda>  s    !4!4Z!MrL   r   F)r  get_attrzAUnexpected type of data placeholder op for parameter construction)r   new_varr   add_push_nullrl   r   r   r   storepregraph_bytecodeextendget_instructionsr   r(  opr   r   r5   rG   r  example_value_from_input_noder$   r5  realizer   r  guards_contextdynamo_guardsremove_guards_with_source)	r   rY  r  varname	data_noderl   r%  r   r  s	           @rM   r  8TorchInGraphFunctionVariable._nn_param_via_prefix_insert  sB    ))##% r]
MN
4;;
9%%m45
E"

		##**2+>+>+@AMMO((	<<::S
 &g.**II33DMMO4H4HI
 !&&r&A! 	++99SS	
 rL   c                 d    US   R                  XR                  5       R                  USS  U5      $ )Nr   r"   )r`  r  r   r8  s       rM   r  /TorchInGraphFunctionVariable.call_tensor_method  s0    Aw""2'8'8':'C'CT!"XvVVrL   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   ismethoddescriptorr  r   r-  r5   r9   
TensorBase)rw   r,  s     rM   r  -TorchInGraphFunctionVariable.is_tensor_method  s    3 &&t'8'8':; H))+^<H!!#00EHH4G4GG8  $5$77		8rL   c                    U R                  5       [        5       ;   =(       dL    [        U R                  5       [        R                  R
                  [        R                  R                  45      =(       a    [        XU5      $ r   )r  rV   r   r5   _ops
OpOverloadOpOverloadPacketr-   r8  s       rM   r  <TorchInGraphFunctionVariable.torch_function_override_enabled%  sb    #<#>> !!#&&

(C(CD< *"F;	<rL   )r  r   r   r   r  )r   r   r   r   r   rv   r   r   r  r   	functoolscacher  r   r$   r   rk  r   r  r  r  r  r  r   r   r   s   @rM   r  r    s    J7 7m# m __^
  ^
@|#| '| -	|
 
||	*6 @ @D    DW8< <rL   r  c                   r   ^  \ rS rSrSr\S 5       r\S 5       rS r	S\
\   S\\\4   SS	4U 4S
 jjrSrU =r$ )r0  i/  zrepresents torch.DispatchKeySetc                     [        U 40 UD6$ r   )r0  )rq   rx   s     rM   r   DispatchKeySetVariable.create2  s    %e6v66rL   c                 ^    [        UR                  [        R                  5      5        U " XS9$ rj   )r   rm   r   DISPATCH_KEY_SET_MATCHro   s      rM   rr   )DispatchKeySetVariable.create_with_source6  s&    f''(K(KLM5((rL   c                     US;   $ )N)hasrK   )rw   r   s     rM   is_constant_fold_method.DispatchKeySetVariable.is_constant_fold_method;  s    wrL   r   rx   r3   r$   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   rq   r   r   r   r   r  EnumVariablerC  ru   r`  )
rw   r   r   r   rx   methodr   r  r  ry   s
            rM   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;rK   )r   r   r   r   r   r   r   r   rr   r@  r   r$   r  r   r`  r   r   r   s   @rM   r0  r0  /  sh    )7 7 ) ); ?#	;
 S/)*; 
; ;rL   r0  c                   \   ^  \ rS rSrSr\S 5       rS\\   S\	\
\4   SS4U 4S jjrS	rU =r$ )
rL  iT  z<represents torch._functorch.pyfunctorch.FuncTorchInterpreterc                 ^    [        UR                  [        R                  5      5        U " XS9$ rj   )r   rm   r   ID_MATCHro   s      rM   rr   /FuncTorchInterpreterVariable.create_with_sourceW  s&    f''(=(=>?5((rL   r   rx   r3   r$   c                   > US:X  a.  [         R                  " U R                  R                  5       5      $ US:X  aI  UR	                  [         R
                  " U 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 ]5  XX45      $ )Nkeyprocess)level
batch_size
randomnesslower)r   rD  rq   rL  r<  r  rM  __func__r   r   r   0TemporarilyPopInterpreterStackCtxManagerVariableru   r`  )rw   r   r   r   rx   ry   s        rM   r`  (FuncTorchInterpreterVariable.call_method\  s     5=))$**..*:;;Y11..tzz/A/A/J/JK 
 ::--44WTZZ5N5PQQW_F**MMTTD  w"2T::rL   rK   )r   r   r   r   r   r   rr   r   r$   r  r   r`  r   r   r   s   @rM   rL  rL  T  sO    F) ); ?#	;
 S/)*; 
; ;rL   rL  )r   r6  r   loggingr   r   collections.abcr   typingr   r   r   r   torch._Cr5   torch._refstorch.fxtorch.nntorch._guardsr   torch._loggingr	   torch.utils._python_dispatchr
   r   r   r   r   r   r   r   create_parameter_opr   r   r   r  r   r  r   r   guardsr   r   rl   r   r   r  r   r   r   r   r   r    r!   r  r#   r$   ctx_managerr%   r&   r'   dictsr(   distributedr)   r*   r  r+   r,   torch_functionr-   r.   r/   r0   numpyr  ModuleNotFoundError#torch.distributed.fsdp._fully_shardr1   torch._dynamo.symbolic_convertr2   	getLoggerr   r   r  r  r   r   r   r   r   r   r   r9   r   r   r   r   r   r   r   r   r   r   r   r   	grad_moder   r   r   r   r   r   r   r   rG   r   r   r   r   _shape_as_tensorr  acceleratorcurrent_device_indexcurrent_deviceis_initializedxpur  r  rC   _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_enabledrV  rU  r  
_Reductionget_enumpromote_types_get_privateuse1_backend_name_is_checkpoint_validr   r  get_rankget_world_sizer7  boolrN   r  r&  _dispatch_tls_local_include_set_dispatch_tls_local_exclude_setrw  rV   rg   r   r  r0  rL  rK   rL   rM   <module>r     sc  6     	 $ 9 9     ( ' K > >  
 @ 1 0 C   + 
 % B . E
 D ! $''!!77!!,,''//--%%44))@@))??))FF		((  ,,  //  ((  1188		##,,

$$--&&00+! 6 %)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,,   $#A #AL]7#4 ]7@E<#4 E<P$";. ";J;#4 ;}/  	B
  s$   \ \ \\\+*\+