
    sh                        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	  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  SS
KJr  SSKJrJrJr  SSK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+J,r,J-r-J.r.J/r/J0r0  SSK1J2r2  SSK3J4r4J5r5J6r6  SSK7J8r8  SSK9J:r:J;r;  SSK<J=r=J>r>  SSK?J@r@JArAJBrB   SSKCrD SSKFJGrG  \	(       a  SSKHJIrI  \R                  " \K5      rL\MR                  \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      ro\MR                  \R                  /5      rq\R                  R                  /rs\R                  \R                  R                  \R                  R                  \R                  R                  \R                  R                  \R                  R                  \Rr                  R                  \R                  \R                  \R                  \R                  \R                  \GR                   \GR                  \GR                  \R                  GR                  GR                  GR
                  \GR                  \R                  GR                  \R                  GR                  /\s-   r\Rr                  R                  5       (       aT  \GR                  \Rr                  GR                  \Rr                  GR                  \Rr                  GR                  /5        \MR                  \s5      rs\MR                  \5      r\GR                  GR                  S\GR                  GR                   S\R                  GR"                  S\GR$                  GR&                  GR(                  S\GR*                  GR,                  S\GR.                  GR0                  GR2                  S\R                  GR2                  S\GR4                  GR2                  S\GR4                  GR6                  S\GR4                  GR8                  S\R                  GR:                  GR<                  GR>                  S0r\MR                  / SQ5      r\R                  GRD                  \R                  GRF                  \R                  GRH                  1r\GRL                  " S5      S 5       r " S S\25      r " S  S!\5      r " S" S#\5      r " S$ S%\5      r " S& S'\5      rg! \E a    SrD GNf = f! \E a    SrG GNf = 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)TYPE_CHECKING)TracingContext)warning_once)"is_traceable_wrapper_subclass_type   )config	polyfills	variables)	PyCodegen)!can_convert_to_tracable_parameternew_parameter_placeholdertracable_create_parameter) get_registered_device_interfaces)unimplemented)GuardBuilderinstall_guard)CallFunctionNoArgsSourceSyntheticLocalSource)check_unspec_or_constant_argsguard_if_dynhas_torch_functionhashableproductproxy_args_kwargsunwrap_if_wrapper   )VariableTracker)AutocastModeVariableProfilerContextVariableTorchFunctionDisableVariable)ConstDictVariable)DistributedVariableProcessGroupVariable)ListVariableTupleVariable)can_dispatch_torch_functiondispatch_torch_functionTorchFunctionModeStackVariable)_fsdp_param_group)InstructionTranslatorFT)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)	itertoolsr2   torch.overridesr3   setfrom_iterablevaluestorchones	ones_likezeros
zeros_likeemptyfullupdate)r2   get_overridable_functions_funcsmores       q/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/_dynamo/variables/torch.pyr3   r3      sp    W##$>$@$G$G$IJKE



D 
LLL    c                   b   ^  \ rS rSrSr\S 5       rSU 4S jjrS 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      rD   create_with_source$BaseTorchVariable.create_with_source   s&    f''(C(CDE5((rE   c                 2   > [         TU ]  " S0 UD6  Xl        g )N )super__init__rQ   )selfrQ   kwargs	__class__s      rD   rW   BaseTorchVariable.__init__   s    "6"
rE   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rer-   extend_outputsetup_globally_cached)rX   codegennameunique_var_names       rD   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   rX   s    rD   as_proxyBaseTorchVariable.as_proxy       zzrE   c                     U R                   $ rn   ro   rp   s    rD   as_python_constant$BaseTorchVariable.as_python_constant   rs   rE   c                 l    [        U R                  U5      n[        R                  R	                  U5      $ rn   )hasattrrQ   r   ConstantVariablecreate)rX   txri   results       rD   call_obj_hasattr"BaseTorchVariable.call_obj_hasattr   s)    T*))0088rE   c                 `    U R                   [        ;   a  g[        U R                   SS 5      S:H  $ )NTra   math)rQ   constant_fold_functionsgetattrrp   s    rD   can_constant_fold_through+BaseTorchVariable.can_constant_fold_through   s*    ::00tzz<6&@@rE   ro   returnNr{   r+   )rb   ra   __qualname____firstlineno____doc__classmethodrR   rW   rk   rq   ru   r}   r   __static_attributes____classcell__rZ   s   @rD   rG   rG      s=    R) )
9A ArE   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$ )TorchCtxManagerClassVariable   zLPoints to a context manager class in torch.* that dynamo has implementationsr   c                 "    SU R                    S3$ )NzTorchCtxManagerClassVariable()ro   rp   s    rD   __repr__%TorchCtxManagerClassVariable.__repr__   s    .tzzl!<<rE   c                 r    [        U 5      n [        U 5      =(       a    [        U 5      =(       a	    U [        ;   $ rn   )r   callabler   supported_ctx_manager_classesro   s    rD   is_matching_cls,TorchCtxManagerClassVariable.is_matching_cls   s6     "%( UO  ;::	
rE   r{   r+   argsrY   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 a&  U(       d  U(       a   e[d        R*                  " U5      $ U R                  [        Rf                  Rh                  Rj                  L a#  [!        U5      S:X  d   eUR+                  UU5      $ U R                  [        Rf                  Rl                  Rn                  L a"  [!        U5      S:X  d   eUR+                  U5      $ U R                  [        RX                  Rp                  Rr                  L a=  [!        U5      S:X  d   eUR+                  UU Vs/ s H  n[u        U5      PM     sn5      $ U R                  [        RX                  Rp                  Rv                  L a"  [!        U5      S:X  d   eUR+                  U5      $ U R                  [        Rf                  Rl                  Rx                  L a"  [!        U5      S:X  d   eUR+                  U5      $ U R                  [        Rf                  Rl                  Rz                  L a=  [!        U5      S:X  d   eUR+                  UU Vs/ s H  n[u        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 a_  [!        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UR+                  UUR3                  5       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_functionrU   z$Profiler function %s will be ignoredr   backends)H r   r   r   r   r   r   r   r   r   r   r   r   rQ   r9   no_gradlen
isinstancer   	functionsBaseUserFunctionVariablerz   r   enable_gradset_grad_enabledru   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    _CDisableTorchFunctionSubclassr!   
_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_hooksr*   FSDPParamGroupuse_training_statenn	attentionsdpa_kernel_sdpa_kernel_variadicrV   )rX   r{   r   rY   r   r   r   r   r   r   r   r   r   r   r   r   ctxinf_moder   xr   argrZ   s                         rD   r   *TorchCtxManagerClassVariable.call_function  sY   	
 	
 	
 	
 ::&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*,,ZZ588@@@''/66r::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.tAwfZ6HH%,,R1L1L1NOOZZ588--CCC%,,>#S++->  w$Rv66M 0 0* ?s   `
`

`
rU   )rb   ra   r   r   r   strr   staticmethodr   r   r   r   r   r   r   s   @rD   r   r      sa    V=# = 
 
7#7 '7 -	7
 
7 7rE   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      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 graphNr   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)rV   rW   trace_rulesr   nonstrict_traceable)rX   rQ   r   rY   r   rZ   s        rD   rW   %TorchInGraphFunctionVariable.__init__  s/    )&)=&"=e"D#6 rE   c                 <    SU R                    SU R                   S3$ )NzTorchInGraphFunctionVariable(z, nonstrict_traceable=r   )rQ   r   rp   s    rD   r   %TorchInGraphFunctionVariable.__repr__  s%    .tzzl:PQUQiQiPjjkllrE   c                     U R                   $ rn   ro   rp   s    rD   get_function)TorchInGraphFunctionVariable.get_function  rs   rE   c                  8  ^4^5^6^7^8^9^:^;^<^= 0 m;U;4S jn SSK Jn  SSKJm4Jm5Jm6Jm7Jm8Jm9J	m:  SSK
Jm<Jm=  U " [        6   S8U44S jj5       nU " [        6   S8S j5       nU " [        R                   R"                  R$                  5        S8S	 j5       nU " [        R&                  R(                  R*                  R,                  5      S8S
 j5       nU " [.        R0                  5      S8S j5       nU " [        R2                  [        R                   R4                  5      S8U4U9U:4S jj5       nU " [        R6                  [        R8                  5      S8U4U94S jj5       nU " [        R:                  5      S8U4U94S jj5       n	U " [        R<                  5      S8S j5       n
U " [>        6 S8U94S jj5       nU " [        R@                  RB                  RD                  RF                  [        R@                  RB                  RD                  RH                  [        R@                  RB                  RD                  RJ                  [        R@                  RB                  RD                  RL                  [        R@                  RB                  RD                  RN                  5      S8S j5       nU " [        RP                  5      U4U64S j5       nU " [        RR                  5       S9 S8U54S jjj5       nU " [        RT                  5      U4U54S j5       nU " [        RV                  RX                  5      U44S j5       nU " [        R                   RZ                  [        R                   R\                  [        R                   R^                  5      S8U44S jj5       nU " [`        Rc                  S [e        5        5       5      6 S8U74S jj5       nU " [        Rf                  5      S8U9U=4S jj5       nU " [        Rh                  Rj                  5      S8S j5       nU " [        Rl                  Rn                  Rp                  5        S8U4U94S jj5       nU " [        RD                  Rr                  Rt                  5      S8S j5       nU " [        R@                  Rv                  5      S8S j5       nU " [        R&                  Rx                  Rz                  [        R&                  Rx                  Rz                  R|                  5      S:S j5       nU " [        R&                  Rx                  R~                  [        R&                  Rx                  R~                  R|                  5      S:S  j5       nU " [        R                  5      S8S! j5       nU " [        R                  5      U94S" j5       nU " [        R                  5        S8S# j5       nU " [        R                  5      S8U94S$ jj5       nU " [        R                  5      S8U44S% jj5       nU " U5      S8U<4S& jj5       n[        R                  " 5       (       aJ  SS'KGJHn JIn!JJn"JKn#JLn$  SS(KMJNn%  U " U U!U"U$U#5        S8U44S) jj5       n&U " U%R                  5      S8U<4S* jj5       n'U " [        R                  R                  5       S:SS+. S8S, jjj5       n(U " [        R@                  R                  R                  5      S8S- j5       n)U " [        R                  R                  R                  R                  5      S8U4U84S. jj5       n*U " [        RV                  R                  R                  5        S8S/ j5       n+U " [        RV                  R                  R                  5        S8U:4S0 jj5       n,U " [        R                  R                  R                  5        S8S1 j5       n-U " [        R                  5      S8U8U94S2 jj5       n.U " [        RV                  R                  5        S8S3 j5       n/U " [        RV                  R                  5        S8U44S4 jj5       n0U " [        RV                  R                  5        S8U44S5 jj5       n1U " [        RV                  R                  5      S8S6 j5       n2U " [        R                  5        S8U44S7 jj5       n3T;$ );z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 $ rn   rU   )handlerfnfnshandlerss     rD   	_registerOTorchInGraphFunctionVariable._get_handlers.<locals>.register.<locals>._register  s0    BX-1r1-#*HRL  rE   r   )r   )r   r   r   s   ` rD   register<TorchInGraphFunctionVariable._get_handlers.<locals>.register  s%     CF####rE   r   )
SDPAParamsr   )ry   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                  [        U R                      5      $ rn   )rQ   r9   _utilsis_compiling_dynamoexternal_utilscompileris_dynamo_compilingis_exportingmark_inconsistent_side_effectsrz   tracing_state_functionsrX   r{   r   rY   ry   s       rD   handle_tracing_state_functionsRTorchInGraphFunctionVariable._get_handlers.<locals>.handle_tracing_state_functions  s     F**zz)),,99++22++  113#**+B4::+NOOrE   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   r9   r   _dispatch_keysr   r   r   r   proxynodemeta_subclasses
FakeTensorDispatchKeySetDispatchKeyPythonPythonTLSSnapshotDispatchKeySetVariablerz   )rX   r{   r   rY   r  dkss         rD   !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BrE   c                 h    [         R                  " U[        R                  R	                  5       5      $ rn   )r   buildr9   	overridesget_default_nowrap_functionsrX   r{   r   rY   s       rD   #handle_get_default_nowrap_functionsWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_get_default_nowrap_functions  s)     #((EOO@@B rE   c                 l    UR                  [        R                  " U[        R                  5      X#5      $ rn   )inline_user_function_returnr   r  r
   accumulate_gradr"  s       rD   handle_accumulate_grad_KTorchInGraphFunctionVariable._get_handlers.<locals>.handle_accumulate_grad_  s-    11%%b)*C*CDd rE   c                     [        X#5      (       d5  UR                  [        R                  " U[        R
                  5      X#5      $ g rn   )r   r&  r   r  r
   radiansr"  s       rD   handle_radiansBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_radians  s=    0>>55#))"i.?.?@$  ?rE   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   r9   r   is_tensor_likerx   rz   )rX   r{   r   ry   r   r   s      rD   handle_is_tensorDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_tensor  sh    #~..

eoo<<<s$=>>CII';<<'..t44'..u55rE   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   r9   is_floating_pointrz   
is_complexAssertionError)rX   r{   input	input_argry   r   s       rD   handle_is_floating_pointLTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_floating_point  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4rE   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_sizerz   r   sizecall_method)rX   r{   r8  ry   r   s      rD   handle_numel@TorchInGraphFunctionVariable._get_handlers.<locals>.handle_numel   sa    %00U5E5E5G5G'..wuzz/BCCE>22((Wb"== 3rE   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   r"  s       rD   handle_torch_compileHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_compile(  s    4yA~AwVWrE   c                 R   > [        UT5      (       d   eUR                  US/ 0 5      $ Nr?  )r   r@  )rX   r{   r8  r   s      rD   handle_tensor_size_rewritesOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_tensor_size_rewrites0  s-    e^4444$$RR88rE   c                 &    U R                  XU5      $ rn   )_call_ntupler"  s       rD   handle_ntupleATorchInGraphFunctionVariable._get_handlers.<locals>.handle_ntuple5  s     $$Rv66rE   c                 v   > [        TR                  5        TR                  [        R                  " 5       5      $ rn   )r   _guards_singletonrz   r9   is_grad_enabled)rX   r{   ry   r   s     rD   handle_is_grad_enabledJTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_grad_enabled?  s,    *<<=#**5+@+@+BCCrE   c                    > U(       a   UR                  5       (       a  [        S5        TR                  XR                  5       5      $ )Nz2torch.use_deterministic_algorithms(warn_only=True))ru   r   rz   )rX   r{   mode	warn_onlyr   s       rD   #handle_use_deterministic_algorithmsWTorchInGraphFunctionVariable._get_handlers.<locals>.handle_use_deterministic_algorithmsD  s9     Y99;;RS299">U>U>WXXrE   c                 v   > [        TR                  5        TR                  [        R                  " 5       5      $ rn   )r   rO  rz   r9   $are_deterministic_algorithms_enabled)rX   r{   ry   r   s     rD   +handle_are_deterministic_algorithms_enabled_TorchInGraphFunctionVariable._get_handlers.<locals>.handle_are_deterministic_algorithms_enabledL  s,    9KKL#**5+U+U+WXXrE   c                    > [        [        R                  5        TR                  UR                  R
                  5      $ rn   )r   r!   rO  rz   r   torch_function_enabled)rX   r{   ry   s     rD    handle_is_torch_function_enabledTTorchInGraphFunctionVariable._get_handlers.<locals>.handle_is_torch_function_enabledQ  s-    6HHI#**299+K+KLLrE   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rn   )r   .0r   s     rD   	<genexpr>`TorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_function.<locals>.<genexpr>b  s     95a&q))5s   )r   r   r&   unpack_var_sequencerz   any)rX   r{   r   elemsry   s       rD   handle_has_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_has_torch_functionV  s_     t9>ja-&H&H Q++B/ 
 $**9599 rE   c              3   >   #    U  H  u  pUR                   v   M     g 7frn   )stream)rc  r`   device_interfaces      rD   rd  =TorchInGraphFunctionVariable._get_handlers.<locals>.<genexpr>f  s       +M'A !''+Ms   c                 &   > TR                  X5      $ rn   )rz   )rX   r{   rl  r   s      rD   handle_device_interface_streamRTorchInGraphFunctionVariable._get_handlers.<locals>.handle_device_interface_streame  s     )//;;rE   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   r9   	as_tensorr   )rX   r{   r   r   r   s      rD   handle_from_numpyETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_numpyn  sh    %%MN2HI$)ii,,#OO 'tR0
 #	 	rE   c                     U$ rn   rU   )rX   r{   the_type	the_values       rD   handle_jit_annotateGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_jit_annotate  s    rE   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   )r4  device)	r   r9   tensorr4  r  rz   r   cudnnis_acceptable)rX   r{   r  extra
tensor_inpry   r   s        rD   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:> rE   c                 J    [         R                  R                  " U/UQ70 UD6$ rn   )r   BackwardHookVariablerz   r"  s       rD   handle_backward_hookHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_backward_hook  s#    1188MdMfMMrE   c                 .    U R                   " U/UQ70 UD6$ rn   )call_nn_parameterr"  s       rD   handle_parameterDTorchInGraphFunctionVariable._get_handlers.<locals>.handle_parameter  s    ))">t>v>>rE   Nc                 4    Ub  UR                  USU/0 5      $ g rG  r@  self_r{   rX   dims       rD   handle_sym_sizeCTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_size  s'     ''FSE2>> rE   c                 4    Ub  UR                  USU/0 5      $ g )Nstrider  r  s       rD   handle_sym_strideETorchInGraphFunctionVariable._get_handlers.<locals>.handle_sym_stride  s%    ''HseR@@ rE   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   r9   r/   r   r.   r,   )rX   r{   r   rY   r|   s        rD   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~rE   c                    > [        UT5      (       ai  [        [        R                  R                  R
                  5      R                  X/0 5      n[        [        R                  5      R                  XU/U5      $ g rn   )r   r   r9   opsaten_local_scalar_denser   r?   )rX   r{   r?  
fill_valuerY   r|   r   s         rD   handle_full?TorchInGraphFunctionVariable._get_handlers.<locals>.handle_full  sh    *n555IINN66-L"5  4EJJ?MMv 	 6rE   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   r  r
   foreach_lerp_inplace)r`   r{   r   rY   s       rD   "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~rE   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   r  r
   foreach_pow_scalar)r`   r{   r   rY   r   s       rD   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~rE   c                    > UR                  5       (       a  UR                  5       (       d4  [        U[        R                  5      (       a  UR                  5       (       a  T" S 5      $ g g rn   )is_python_constantru   r   r   r   evaluate_expr)rX   r{   	conditionmessagery   s       rD   handle_assertATorchInGraphFunctionVariable._get_handlers.<locals>.handle_assert  sX    ,,..93O3O3Q3Q9i&?&?@@++--'-- . ArE   c           
         > T" UUR                   R                  " S[        R                  R                  /[        X#5      Q76 US9$ )Nr   )r  
param_vars)r   r   r9   r   _SDPAParamsr   )rX   r{   r   rY   r   s       rD   handle_sdpa_paramsFTorchInGraphFunctionVariable._get_handlers.<locals>.handle_sdpa_params  sI     ii,,#HH(( 't4
   rE   )_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%   r7  rQ   ru   r   r  )rX   r{   r   r   args_as_valueinvocation_resultry   s         rD   &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  ro   )r   r  r  r  kwargs_as_valuerX   s      rD   fn_with_prim_typesaTorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local.<locals>.fn_with_prim_types'  s/    ::)-<DI rE   zprim r   r   r{   r  )NN)ru   itemsrQ   rb   r   r   r   )rX   r{   r   rY   r   kvkwargs_to_be_proxiedr  r  r  r   s   `        @@rD   handle_from_localETorchInGraphFunctionVariable._get_handlers.<locals>.handle_from_local  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  ru   r9   stridedr   r   )rX   r{   tensor_listr  r   rY   r  s          rD   handle_nested_tensorHTorchInGraphFunctionVariable._get_handlers.<locals>.handle_nested_tensor;  s@     0&335FSTk<<AB =rE   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  ru   r   r"  s       rD   handle_one_hotBTorchInGraphFunctionVariable._get_handlers.<locals>.handle_one_hotK  sd    4y3v;&!+D	QG..00G..0B6R 7 1 rE   c                   > [        UT5      (       aZ  [        R                  R                  [        R
                  R                  R                  R                  UR                  5      5      $ [        UT5      (       a  U$ g rn   )
r   r   ry   rz   r9   fxexperimentalsymbolic_shapesguard_size_oblivioussym_num)rX   r{   exprry   r   s      rD   handle_guard_size_obliviousOTorchInGraphFunctionVariable._get_handlers.<locals>.handle_guard_size_obliviousV  sj    $00 !1188HH))99NN 
 D"233 4rE   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   )rX   r{   r   rY   r  s        rD   !handle_unsafe_set_version_counterUTorchInGraphFunctionVariable._get_handlers.<locals>.handle_unsafe_set_version_counterc  s*     H/+mB$01rE   c                 `   > T" [         R                  R                  R                  5       5      $ rn   )r9   r   r   peek_interpreter_stack)rX   r{   r   rY   r   s       rD   'handle_functorch_peek_interpreter_stack[TorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_peek_interpreter_stackm  s(     -##::< rE   c                     US   R                   n[        [        R                  R                  R                  U5      5      $ Nr   )rQ   FuncTorchInterpreterVariabler9   r   pyfunctorchcoerce_cinterpreter)rX   r{   r   rY   cinterpreters        rD   0handle_functorch_pyfunctorch_coerce_cinterpreterdTorchInGraphFunctionVariable._get_handlers.<locals>.handle_functorch_pyfunctorch_coerce_cinterpreterw  s8      7==L/  ,,@@N rE   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rn   rU   )rc  ycheck_any_unspecs     rD   rd  tTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspec.<locals>.<genexpr>  s     DGq/22Gs   F)r   r%   r&   rg  r  )r   r   r   r  s    rD   r  aTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor.<locals>.check_any_unspec  sD    a./!BCCL-#@AADAGGDDD !rE   r   data)r   r   r9   _refsr  r   )rX   r{   r   rY   data_argr  r   r   s        @rD   handle_torch_tensorGTorchInGraphFunctionVariable._get_handlers.<locals>.handle_torch_tensor  s~    	! H76!!&> h77<LX<V<V 4EKK4F4FGUU$  =W7rE   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)symbolic_torch_function_state
mode_stackr   r)   register_mutationpop_torch_function_moder"  s       rD   handle_pop_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_pop_torch_function  sM     F**33>>#$UVV*<<R@33KKMMrE   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   r)   r  r  push_torch_function_moderz   r  s       rD   handle_push_torch_functionNTorchInGraphFunctionVariable._get_handlers.<locals>.handle_push_torch_function  sO     t9>&00*<<R@,,EEd1gN#**400rE   c                    > U(       d  U(       a   eTR                  [        UR                  R                  5      5      $ rn   )rz   r   r  r  r  s       rD   handle_len_torch_functionMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_len_torch_function  s7     F**#**B44??@ rE   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   $ r  )r   ru   r  r  )rX   r{   r   rY   inds        rD   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CrE   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      $ r  )r)   r  r  ru   clear_default_device!register_device_context_insertionrz   r  s       rD   handle_set_default_deviceMTorchInGraphFunctionVariable._get_handlers.<locals>.handle_set_default_device  sf     +<<R@Aw))++Q0J0J0L0T.CCBG.PPQST#**400rE   r   )Frn   )dtorch.backends.cudar   r   ry   r   r   r   r   r   r   builderr   r   r
  dispatch_key_set_functionsr9   r   r!  __wrapped__r  inductoraccumulate_grad_defaultr   r+  	is_tensorr0  r5  r6  r=  compile!REWRITE_OPS_TO_TENSOR_SIZE_METHODr   modulesutils_single_pair_triple
_quadruple_ntuplerP  use_deterministic_algorithmsrY  r   _is_torch_function_enabledr   has_torch_function_variadichas_torch_function_unarydictfromkeysr   
from_numpyjitannotater   r  r  hooksBackwardHook	Parameterr  sym_sizeint
sym_strideaddcdivr?   _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  	_autogradr  r   r  r  r  r  _pop_torch_function_stack_push_on_torch_function_stack_len_torch_function_stack_get_function_stack_atset_default_device)>r   r   r  r  r#  r(  r,  r1  r:  rA  rD  rH  rL  rQ  rV  rZ  r^  ri  rp  rw  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  ry   r   r   r   r   r   r   r   r   r   s>                                                       @@@@@@@@@@rD   _get_handlers*TorchInGraphFunctionVariable._get_handlers  s   
 	 	3	
 	
 	
 	>	*	+	P-	P 
,	P 
-	.	C-	C 
/	C6 
%//>>JJ	K		-		 
L		 
%))$$55==	>	 
?	
 
$,,		 
 	 
%//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	M 
7	M 
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
	 
%(($$@@	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$ rE   r{   r+   r   rY   r   r   c                   ^1^2^3 SSK JnJm1J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m2  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                  m3U2U34S jnU" U5      u  nnURL                  RO                  T3RP                   S3U5      nURL                  RO                  T3RP                  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       (       a  U Rs                  XU5      $ U Ru                  5       Rw                  U RJ                  5      n#U#(       a  U#" X/UQ70 UD6n$U$(       a  U$$ [y        U14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%  [        [        U)5      (       a  [}        [        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   n.US   R                  RT                  R                  S   n/U*U.R                  :w  a  [=        S#5        [        R                  R                  U/5      (       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   n/[        R                  R                  U/5      (       d  [=        S$5        U+$ [1        US   [6        5      (       a  [        US   R4                  5       H  u  n0n SU R                  RT                  R                  ;   d   eU R                  RT                  R                  S   n/[        R                  R                  U/5      (       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N[=        SU SU S35         S nAGNS nAff = fs  sn f s  sn"n!f )'Nr   )ry   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   rY   old_valresrT  r   s       rD   
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   c              3   <   >#    U  H  n[        UT5      v   M     g 7frn   )r   )rc  r   r   s     rD   rd  =TorchInGraphFunctionVariable.call_function.<locals>.<genexpr>p  s     &Tt!z!_'E'Ets   c              3   v   #    U  H/  n[        U[        R                  [        R                  45      v   M1     g 7frn   )r   r   ry   r   rb  s     rD   rd  ra  r  s2      !
 q955y7P7PQRRs   79ra   r   r9   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 )Nr   ry   r   r   r  r   r   "torch._higher_order_ops.flat_apply_higher_order_ops
flat_applyrR  rS  torch._subclasses.fake_tensorrT  torch.utils._pytreerU  baserV  r&   r  r"   r   UserFunctionVariabler   r   r   r  r%   python_typer   r   rq   ru   vtr'  _pytreeis_constant_classrQ   r   %register_static_attr_and_return_proxyrb   typer  r   torch_function_override_enabledr(   r   r   #constant_fold_functions_need_guardsr   rL   r   rM   r   EQUALS_MATCHrz   is_tensor_methodcall_tensor_methodrN  getrg  allr   bin_opsr   r   warningrx   r9   r  r  r  r   zip_size_prims_commonis_contiguous	enumerate)4rX   r{   r   rY   ry   r   r   rh  rR  rS  rU  rV  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  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   rT  r   s4                                                    @@@rD   r   *TorchInGraphFunctionVariable.call_function  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    ""**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e# 7 dd&&(,,	44++C00!``i_j k  "V W`  Va a~ H  ~I I	 b <Ls1   /d5d: (f:f?:f7 Af2f22f7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&   listrf  r  ry   rz   r9   r   r&  r'  r,  ru   r   )rQ   countr{   s    rD   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IrE   )rQ   r9   r   r&  r'  r,  ru   __closure__cell_contentsr   r:  r   LambdaVariable)rX   r{   r   rY   rL  r  s    `   @rD   rK  )TorchInGraphFunctionVariable._call_ntuple  s    ::))//777G..0EJJ**1-;;E%%%%%z	J ::))//777++M:: a))rE   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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[.        UR1                  5       UR1                  5       40 5      UR                  S9n
[        U
[        R                  5      (       d   e[2        R4                  R6                  U
l        SU
l        U
$ ! [         a    [        S5         GNf = 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  r4  r  zParameter not python_constant: Ndetachr   rQ  r   rK   F)exportr   r   r   r   ru   NotImplementedErrorr   rL   _nn_param_via_prefix_insertr   
class_typer   tuplevar_getattrr   synthetic_graph_inputr   re  r@  r  r   r   r   rq   r9   r   r8  has_grad_fn)rP   r{   r  re  r  r4  r  r  placeholderr   r|   s              rD   r  .TorchInGraphFunctionVariable.call_nn_parameter  s    99OPmY%>%>??K - @ @ B $	 8 899OD61BCD ;;222]KK-doo>>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.. # m ' KIJK( # 	A;A3?@@	As*   H/ A)I /II
I.I))I.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[.        R0                  " 5       R2                  R4                  R7                  U5        U$ )Nc                  (   > T R                  SS5      $ )Nztorch.nnr8  )load_import_from)cgs   rD   <lambda>JTorchInGraphFunctionVariable._nn_param_via_prefix_insert.<locals>.<lambda>^  s    !4!4Z!MrE   r   F)r  get_attrzAUnexpected type of data placeholder op for parameter construction)r   new_varr   add_push_nullrL   r   ry   r   storepregraph_bytecodeextendget_instructionsrq   r  opr   r   r9   r   r8  example_value_from_input_noder   r  r   rx  guards_contextdynamo_guardsremove_guards_with_source)	r{   r  re  varname	data_noderL   r  r|   r  s	           @rD   r  8TorchInGraphFunctionVariable._nn_param_via_prefix_insertW  s6    ))##% r]
MN
4;;
9%%m45
E"

		##**2+>+>+@AMMO((	<<::S
 &g.**II33DMMO4H4HI
 !&&r&A 	++99SS	
 rE   c                 d    US   R                  XR                  5       R                  USS  U5      $ )Nr   r   )r@  r   rb   r"  s       rD   rw  /TorchInGraphFunctionVariable.call_tensor_methodx  s0    Aw""2'8'8':'C'CT!"XvVVrE   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   rx   r  r9   r   
TensorBase)rX   r  s     rD   rv  -TorchInGraphFunctionVariable.is_tensor_method{  s    3 &&t'8'8':; H))+^<H!!#00EHH4G4GG8  $5$77		8rE   c                    U R                  5       [        5       ;   =(       dL    [        U R                  5       [        R                  R
                  [        R                  R                  45      =(       a    [        XU5      $ rn   )r   r3   r   r9   _ops
OpOverloadOpOverloadPacketr'   r"  s       rD   rs  <TorchInGraphFunctionVariable.torch_function_override_enabled  sb    #<#>> !!#&&

(C(CD< *"F;	<rE   )r   rn   r   r   rX  )rb   ra   r   r   r   rW   r   r   r   r   	functools	lru_cacherN  r   r   r   rK  r   r  r  rw  rv  rs  r   r   r   s   @rD   r   r     s    J7 7m# m l  l\f#f 'f -	f
 
fP	*6 > >@  @W8< <rE   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$ )r  i  zrepresents torch.DispatchKeySetc                     [        U 40 UD6$ rn   )r  )rQ   rY   s     rD   rz   DispatchKeySetVariable.create  s    %e6v66rE   c                 ^    [        UR                  [        R                  5      5        U " XS9$ rJ   )r   rM   r   DISPATCH_KEY_SET_MATCHrO   s      rD   rR   )DispatchKeySetVariable.create_with_source  s&    f''(K(KLM5((rE   c                     US;   $ )N)hasrU   )rX   ri   s     rD   is_constant_fold_method.DispatchKeySetVariable.is_constant_fold_method  s    wrE   r   rY   r   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   ry   rz   ru   r  EnumVariabler  rV   r@  )
rX   r{   ri   r   rY   methodr   r  r  rZ   s
            rD   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;rU   )rb   ra   r   r   r   r   rz   r   rR   r  r  r   r1  r   r@  r   r   r   s   @rD   r  r    sh    )7 7 ) ); ?#	;
 S/)*; 
; ;rE   r  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$ )
r  i  z<represents torch._functorch.pyfunctorch.FuncTorchInterpreterc                 ^    [        UR                  [        R                  5      5        U " XS9$ rJ   )r   rM   r   ID_MATCHrO   s      rD   rR   /FuncTorchInterpreterVariable.create_with_source  s&    f''(=(=>?5((rE   r   rY   r   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   r  rQ   r  r&  rl  r  __func__ry   rz   r   0TemporarilyPopInterpreterStackCtxManagerVariablerV   r@  )rX   r{   ri   r   rY   rZ   s        rD   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::rE   rU   )rb   ra   r   r   r   r   rR   r  r   r1  r   r@  r   r   r   s   @rD   r  r    sO    F) ); ?#	;
 S/)*; 
; ;rE   r  )r   r  r   loggingr   re   collections.abcr   typingr   torch._Cr9   torch._refstorch.fxtorch.nntorch._guardsr   torch._loggingr   torch.utils._python_dispatchr   r   r	   r
   r   rh   r   create_parameter_opr   r   r   rm  r   excr   guardsr   r   rL   r   r   r'  r   r   r   r   r   r   r   rk  r   ctx_managerr   r    r!   dictsr"   distributedr#   r$   r  r%   r&   torch_functionr'   r(   r)   numpyru  ModuleNotFoundError#torch.distributed.fsdp._fully_shardr*   torch._dynamo.symbolic_convertr+   	getLoggerrb   r   r1  r2  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	grad_moder   r   r   r   r   r   r   r   r   r   r   r   r   _shape_as_tensorr%  current_devicert  r?  r  _get_device_index_get_cublas_allow_tf32_is_any_autocast_enabledget_device_propertiesr@  get_autocast_dtypeget_autocast_gpu_dtypeget_default_dtypeis_autocast_cache_enabledis_autocast_cpu_enabledis_autocast_enabledr6  r5  rF  
_Reductionget_enumpromote_types_get_privateuse1_backend_name_is_checkpoint_validr   r  is_initializedget_rankget_world_sizer4  is_scripting
is_tracing_get_tracing_stater  _symbolic_traceis_fx_tracingonnxis_in_onnx_exportr  r  r  r  r  r  r&  
activation_is_make_fx_tracingr
  rz  r  _dispatch_tls_local_include_set_dispatch_tls_local_exclude_setr  r  r3   rG   r   r   r  r  rU   rE   rD   <module>r,     s  6     	 $       ( ' K + +  
 @  0 C   " 
 % B . E
 D ! $''!!77!!,,''//--44))@@))??))FF		((  ,,  //  ((  1188		##,,

$$--&&00)! 4 %)MM% ! 
JJ' #
 
MM	LL""	HH##	HH%%	JJ$$	JJ	""		  		##	!!				HH""++		HH**	NN'''( ()( * 	!!##"",,&&,,	
 '+mm4W&X #--(?@  
IIE	II%	HH	HH**E	JJ  %	MM  --t	LLt	NN	NN&&	NN	HH33U  --<
= 
HH	HH,,	HH,,  T $#A #ALU7#4 U7py<#4 y<x";. ";J;#4 ;}*  	B
  s$   >] ]. ]+*]+.]:9]: