+
    &j                       ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHtHt ^ RIHt ^ RIt^ R	IHt ^ R
I H!t! ^ RI"H#t# ^ RI$H%t%H&t& ^ RI'H(t( ]PR                  ! ]*4      t+]'       d9   ^ RI,H-t-H.t.H/t/ ^ RI0H1t1 ^ RI2t2^ RI3H4t4 ^ RI5H6t6 ^ RI7H8t8 ^ RI9H:t: ^ RI;H<t< ^ RI=H>t>  ]P~                  ! R4      t@]P~                  ! R4      tA]! RRRR7       ! R R4      4       tB ! R R]4      tC ! R R]P                  4      tE  ! R  R!4      tF]P$                  ! RR"7       ! R# R$4      4       tG ! R% R&]4      tH]P$                  ! RR'7       ! R( R)4      4       tI]! R*4      tJ ]P$                  ! RR"7       ! R+ R,4      4       tK ]P$                  ! RR"7       ! R- R.]K4      4       tL ]P$                  ! RR"7       ! R/ R0]K4      4       tM  ! R1 R2]]J,          4      tN ! R3 R44      tO ! R5 R64      tP ! R7 R8]N]P,          4      tQ ! R9 R:4      tR ! R; R<]N]R,          4      tS ! R= R>4      tT  ! R? R@]N]O,          4      tU ! RA RB4      tV] ! RC RD4      4       tW] ! RE RF4      4       tX ! RG RH]V4      tY ! RI RJ4      tZ]P                  ! 4       t\  ! RK RL4      t]] ! RM RN4      4       t^ ! RO RP4      t_]RQ RR l4       t`]RS RT l4       ta]RU RV l4       tb]RcRW RX ll4       tb]! 4       RcRY RZ ll4       tb]b! RR"7       ! R[ R\4      4       tc]b! RR"7       ! R] R^]c4      4       tdRcR_ R` llteRa Rb ltfR# )d    )annotationsN)abstractmethod)defaultdict)contextmanager)	dataclass)AnyGeneric
NamedTupleoverloadTYPE_CHECKINGTypeVar)dataclass_transform)_pytree)
OrderedSet)is_traceable_wrapper_subclass)CapturedTracebackformat_frame)WeakTensorKeyDictionary)Callable	GeneratorIterator)CodeType)DDPOptimizerContext)	PyCodegen)GuardCheckSpec)ViewAndMutationMeta)NestedCompileRegionOptionsFakeTensorModez-^(?P<frame_id>\d+)/(?P<frame_compile_id>\d+)$zQ^!(?P<compiled_autograd_id>\d+)(?:/(?P<frame_id>\d+)/(?P<frame_compile_id>\d+))?$T)frozenkw_onlyslotsc                  \    ] tR t^Ft$ R]R&   R]R&   RtR]R&   R R lt]R R	 l4       tR
t	R# )	CompileId
int | Noneframe_idframe_compile_idNcompiled_autograd_idc                   V ^8  d   QhRR/#    returnstr )formats   "e/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/_guards.py__annotate__CompileId.__annotate__U   s     > > >    c                	   V P                   e   V P                  R J V P                  R J 8w  d&   \        RV P                   RV P                   24      hRpV P                  e   RV P                   RV P                   2pRV P                    V 2# V P                  e   V P                  f&   \        RV P                   RV P                   24      hV P                   RV P                   2# )NzMframe_id and frame_compile_id must both be None or both be set, got frame_id=z, frame_compile_id= /!z=frame_id and frame_compile_id must not be None, got frame_id=)r(   r&   r'   AssertionError)self	frame_strs   & r0   __str__CompileId.__str__U   s   $$0%4+@+@D+HI$$$(MM?2EdF[F[E\^  I}}(a0E0E/FG	t001)==}}$(=(=(E$$$(MM?2EdF[F[E\^  mm_Ad&;&;%<==r3   c                    V ^8  d   QhRRRR/# )r+   
compile_id
str | Noner,   CompileId | Noner.   )r/   s   "r0   r1   r2   k   s     J JZ J4D Jr3   c                F   Vf   R#  \         \        3 Fb  pVP                  V4      ;p'       g   K  VP                  4       pVP	                  4        F  w  rVVf   K  \        V4      WE&   K  	  V ! R/ VB u # 	  \        h  \         d   p\        RT R24      ThRp?ii ; i)zt
Factory method that creates a CompileId from its string representation.
Keep this in sync with the __str__ method.
NzInvalid compile_id ''r.   )COMPILE_ID_PATTERNCA_COMPILE_ID_PATTERNmatch	groupdictitemsint
ValueError	Exception)clsr>   patternrE   groupskves   &&      r0   from_stringCompileId.from_stringj   s     	J.0EF#MM*55555"__.F &=(+AFI !/ ==( G !  	J3J<qABI	Js(   %B  &B  B  8B   B BB r.   )
__name__
__module____qualname____firstlineno____annotations__r(   r;   classmethodrQ   __static_attributes__r.   r3   r0   r$   r$   F   s8    
 !  (,*+
>* J Jr3   r$   c                  8    ] tR t^t$ R]R&   R]R&   R R ltRtR# )	TraceIdr$   r>   rH   attemptc                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   TraceId.__annotate__   s     7 7 7r3   c                	    V P                   ^ 8X  d   \        V P                  4      # V P                   RV P                    2# )r   _)r\   r-   r>   r9   s   &r0   r;   TraceId.__str__   s7    <<1t''oo&a~66r3   r.   NrS   rT   rU   rV   rW   r;   rY   r.   r3   r0   r[   r[      s     L7 7r3   r[   c                      ] tR t^t^ t^t^t^t^t^t	^t
^t^t^	t^
t^t^t^t^t^t^tR R ltR R ltR R ltR R ltR	 R
 ltRtR# )GuardSourcec                   V ^8  d   QhRR/# r+   r,   boolr.   )r/   s   "r0   r1   GuardSource.__annotate__   s     W W Wr3   c                	H    V \         P                  \         P                  39   # N)re   GLOBAL_FSDP_MODULELOCAL_FSDP_MODULEra   s   &r0   is_fsdp_moduleGuardSource.is_fsdp_module   s    668U8UVVVr3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   ri      s     
 
$ 
r3   c                	    ^ RI Hu Hp VP                  '       d<   V \        P
                  \        P                  39   ;'       g    V P                  4       # V \        P
                  \        P                  39   # r   N)torch._dynamo.config_dynamoconfig_unsafe_skip_fsdp_module_guardsre   GLOBAL_SPECIALIZED_NN_MODULELOCAL_SPECIALIZED_NN_MODULErn   )r9   ru   s   & r0   is_specialized_nn_module$GuardSource.is_specialized_nn_module   sv    --111<<;; ) )
 &&( 4433
 
 	
r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   ri      s     
 
D 
r3   c                	    V \         P                  \         P                  \         P                  \         P                  39   # rk   )re   GLOBAL_UNSPECIALIZED_NN_MODULELOCAL_UNSPECIALIZED_NN_MODULE&GLOBAL_UNSPECIALIZED_BUILTIN_NN_MODULE%LOCAL_UNSPECIALIZED_BUILTIN_NN_MODULEra   s   &r0   is_unspecialized_nn_module&GuardSource.is_unspecialized_nn_module   s8    6655>>==	
 
 	
r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   ri      s     
 
D 
r3   c                	H    V \         P                  \         P                  39   # rk   )re   r   r   ra   s   &r0   "is_unspecialized_builtin_nn_module.GuardSource.is_unspecialized_builtin_nn_module   s&    >>==
 
 	
r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   ri      s     
 
$ 
r3   c                	    V \         P                  \         P                  \         P                  \         P                  \         P
                  39   # rk   )re   LOCALrx   rm   r~   r   ra   s   &r0   is_localGuardSource.is_local   sA    33))55==
 
 	
r3   r.   N)rS   rT   rU   rV   r   GLOBALrx   rw   CONSTANTRANDOM_VALUE	SHAPE_ENVrm   rl   BACKWARD_STATE	EPHEMERALSYNTHETIC_LOCALr~   r}   r   r   
TEMP_LOCALrn   ry   r   r   r   rY   r.   r3   r0   re   re      s~    EF"##$ HLINIO$&!%'",.)-/*JW
"


 
r3   re   c                      ] tR t^tRtR# )GuardBuilderBaser.   NrS   rT   rU   rV   rY   r.   r3   r0   r   r      s    r3   r   )r    c                  8    ] tR t^t$ R]R&   R]R&   R R ltRtR# )	SLocz#traceback.FrameSummary | str | Noneframework_locr?   maybe_user_locc                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   SLoc.__annotate__   s     	 	 	r3   c                	    \        V P                  \        4      '       d   V P                  M\        V P                  4      pV P                  e   V P                   RV R2# RV R2# )Nz ()()
isinstancer   r-   r   r   )r9   flocs   & r0   r;   SLoc.__str__   sk     $,,c22 d001 	
 *))*"TF!44tfA;r3   r.   Nrc   r.   r3   r0   r   r      s    66	 	r3   r   c                  6    ] tR t^t$ R]R&   R]R&   R]R&   RtR# )	
ShapeGuardzsympy.logic.boolalg.Booleanexprr   slocrh   size_obliviousr.   NrS   rT   rU   rV   rW   rY   r.   r3   r0   r   r      s    
%%
Jr3   r   )r"   c                  n   ] tR t^t$ R]R&   R]R&   RtR]R&   RtR]R&   RtR	]R
&   RtR]R&   Rt	R]R&   Rt
R]R&   RtR]R&   RtR]R&   R R ltR R ltR R ltR R lt]R R l4       t]R  R! l4       t]R" R# l4       tR$ R% ltR& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltR0 R1 ltR2 R3 ltR4tR# )5GuardSourceoriginating_sourcez)Callable[[GuardBuilderBase, Guard], None]	create_fnNzlist[str] | Noneguard_types	code_listzobject | Noneobj_weakref!weakref.ReferenceType[Any] | Noneguarded_class_weakrefzCapturedTraceback | Nonestackztraceback.StackSummary | None
user_stackr%   _hashFrh   _unserializablec                   V ^8  d   QhRR/# r+   r,   rH   r.   )r/   s   "r0   r1   Guard.__annotate__  s      # r3   c                	    V P                   f;   \        V P                  V P                  \	        V P
                  4      34      V n         V P                   # rk   )r   hashnamesourceidr   ra   s   &r0   __hash__Guard.__hash__  s:    ::tyy$++r$..7IJKDJzzr3   c                   V ^8  d   QhRR/# )r+   r,   ztuple[bool, int, int, str, int]r.   )r/   s   "r0   r1   r     s     
 
9 
r3   c                	   \        V P                  \        P                  4      ;'       dE    V P                  P                  \
        P                  P                  P                  P                  J pTV P                  '       d   V P                  P                  MR\        V P                  4      V P                  V P                  4       P                  P                   3# )   )r   r   	functoolspartialfunctorchrt   guardsGuardBuilderDUPLICATE_INPUTr   valuelenr   inner_create_fn__code__co_firstlineno)r9   is_duplicate_inputs   & r0   sort_keyGuard.sort_key  s    
 t~~y'8'89 Y Y##u}}';';'H'H'X'XX 	
 !%DKK"		NII  "++::
 	
r3   c                    V ^8  d   QhRRRR/# )r+   otherr   r,   rh   r.   )r/   s   "r0   r1   r   -  s     2 2E 2d 2r3   c                	D    V P                  4       VP                  4       8  # rk   )r   r9   r   s   &&r0   __lt__Guard.__lt__-  s    }}!111r3   c                   V ^8  d   QhRR/# )r+   r,   z(Callable[[GuardBuilderBase, Guard], Any]r.   )r/   s   "r0   r1   r   0  s     " "!I "r3   c                	    \        V P                  \        P                  4      '       d   V P                  P                  # V P                  # rk   )r   r   r   r   r   ra   s   &r0   r   Guard.inner_create_fn0  s3    dnni&7&788>>&&&>>!r3   c                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   r   7  s     , ,c ,r3   c                	.    V P                   P                  # rk   )r   r   ra   s   &r0   r   
Guard.name6  s    &&+++r3   c                   V ^8  d   QhRR/# r+   r,   re   r.   )r/   s   "r0   r1   r   ;  s     4 4 4r3   c                	.    V P                   P                  # rk   )r   guard_sourcera   s   &r0   r   Guard.source:  s    &&333r3   c                    V ^8  d   QhRRRR/# )r+   r   objectr,   r-   r.   )r/   s   "r0   r1   r   ?  s     $ $F $s $r3   c           
     &   \        V \        P                  4      '       dh   V ! 4       pVeE   R\        \	        V 4      4       RVP
                  P                   R\        \	        V4      4       R2# R\        \	        V 4      4       R2# \        V 4      # )a  
This is a workaround of a Python weakref bug.

`obj_weakref` is instance returned by `weakref.ref`,
`str(obj_weakref)` is buggy if the original obj overrides __getattr__, e.g:

    class MyConfig(dict):
        def __getattr__(self, x):
            return self[x]

    obj = MyConfig(offset=5)
    obj_weakref = weakref.ref(obj)
    str(obj_weakref)  # raise error: KeyError: '__name__'
z<weakref at z; to 'z' at >z; dead>)r   weakrefReferenceTypehexr   	__class__rS   r-   )r   objs   & r0   weakref_to_strGuard.weakref_to_str>  s      k7#8#899-C%c"[/&:%;6#--BXBXAYY^_bceficj_k^llmnn%c"[/&:%;7CC{##r3   c                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   r   W  s     
 
# 
r3   c                	f   R V P                   '       d%   V P                   P                  P                  4       MR R\        V P                  4       RV P	                  4       P
                   RV P                   RV P                   RV P                  V P                  4       RV P                   R2pV# )z	
        r5    z&
        {
            'guard_types': z,
            'code': z,
            'obj_weakref': z
            'guarded_class': z
        }
        )r   r   lowerreprr   rS   r   r   r   r   r   )r9   ss   & r0   __repr__Guard.__repr__W  s    	%)[[[					!b94		?:K1TMaMaMcMlMlLm n ,,- .^^$ % //0@0@AB C"889 :	 r3   c                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   r   c  s     	 	 	r3   c                	   R \        V P                  4       R2pV P                  '       d%   V P                  P                  P                  4       MRpVRV R2,          pVRV P	                  4       P
                   R2,          pVRV P                   R2,          pVRV P                   R2,          pVRV P                  V P                  4       R2,          pVRV P                   R2,          pV# )	zName: 
r5   z    Source: z    Create Function: z    Guard Types: z    Code List: z    Object Weakref: z    Guarded Class Weakref: )r   r   r   r   r   rS   r   r   r   r   r   )r9   outputr   s   &  r0   r;   Guard.__str__c  s    $tyy/*"--1[[[!!'')bL++)$*>*>*@*I*I)J"MM%d&6&6%7r::ODNN#3266()<)<T=M=M)N(OrRR/0J0J/K2NNr3   c                    V ^8  d   QhRRRR/# )r+   builderr   r,   r   r.   )r/   s   "r0   r1   r   n  s      . 3 r3   c           	     	`    V P                  W4      #   \         d    \        P                  R \	        T 4      P                  4       4       T P                  '       dO   \        P                  RRP                  T P                  P                  4       RR 4      P                  4       4       h i ; i)zError while creating guard:
%szCreated at:
%sr5   N)
r   rJ   log	exceptionr-   rstripr   errorjoinr/   )r9   r   s   &&r0   createGuard.createn  s    	>>'00 	MM;SY=M=M=OPzzz		+RWWTZZ5F5F5H5M-N-U-U-WX		s
    BB-c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   r   w  s     6 6$ 6r3   c                	6    V P                   P                  4       # rk   )r   ry   ra   s   &r0   ry   Guard.is_specialized_nn_modulew  s    {{3355r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   r   z  s     , , ,r3   c                	6    V P                   P                  4       # rk   )r   rn   ra   s   &r0   rn   Guard.is_fsdp_modulez  s    {{))++r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   r   }  s     & &$ &r3   c                	6    V P                   P                  4       # rk   )r   r   ra   s   &r0   r   Guard.is_local}  s    {{##%%r3   c                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   r     s     " " "r3   c                	    \        V P                  \        P                  4      '       d#   V P                  P                  pVP
                  # V P                  pVP
                  # rk   )r   r   r   r   r   rS   )r9   r   s   & r0   create_fn_nameGuard.create_fn_name  sM    dnni&7&788++I !!! I!!!r3   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r+   
guard_typer-   guarded_classr   r   	list[str]r   r   r,   Noner.   )r/   s   "r0   r1   r     s<     &' &'&' 9&' 	&'
 &' 
&'r3   c                	    V P                   '       g   . V n         V P                   P                  V4       V P                  VR 39  d   \        RV P                   RV 24      hW n        V P                  '       g   W0n        MV P                  P                  V4       V P                  VR 39   ;'       g0    \        V P                  4      ;'       d    V P                  4       R J pV'       g   \        RV P                   RV 24      hW@n        R # )Nz1Guarded class id must be identical, or None, got z vs zHGuarded object must be identical, None or ephemeral (dead weakref), got )r   appendr   r8   r   extendr   callable)r9   r  r  r   r   is_valids   &&&&& r0   set_export_infoGuard.set_export_info  s    !D
+%%mT-BB 112$}oG  &3"~~~&NNN!!), d 33 + +(() + +  "d* 	
  ''([M;  'r3   )r   r   r   r   r   )rS   rT   rU   rV   rW   r   r   r   r   r   r   r   r   r   r   r   r   propertyr   r   staticmethodr   r   r;   r  ry   rn   r   r  r  rY   r.   r3   r0   r   r      s    & 88 %)K!("&I&!%K%?C<C&*E#*04J-4E:!OT!

 2" , , 4 4 $ $0
	6,&"&' &'r3   r   Tc                      ] tR tRtRtR# )GuardEnvExpri  r.   Nr   r.   r3   r0   r%  r%    s    r3   r%  c                  8    ] tR tRt$ R]R&   R]R&   R R ltRtR# )	DuplicateInputsi  r   input_source_ainput_source_bc                   V ^8  d   QhRR/# r+   r,   r  r.   )r/   s   "r0   r1   DuplicateInputs.__annotate__  s      t r3   c                	l    V P                   V P                  8X  d   \        R V P                    24      hR# )z9input_source_a and input_source_b must be different, got N)r(  r)  r8   ra   s   &r0   __post_init__DuplicateInputs.__post_init__  s>    $"5"55 **+-  6r3   r.   N)rS   rT   rU   rV   rW   r.  rY   r.   r3   r0   r'  r'    s     r3   r'  c                  ,    ] tR tRt$ R]R&   R]R&   RtR# )StorageOverlapi  zlist[Source]overlapping_sourcesnon_overlapping_sourcesr.   Nr   r.   r3   r0   r1  r1    s    %%))r3   r1  c                  B    ] tR tRt]R R l4       t]R R l4       tRtR# )Checkpointablei  c                   V ^8  d   QhRR/# )r+   r,   r#  r.   )r/   s   "r0   r1   Checkpointable.__annotate__  s    '''r3   c                	    R # rk   r.   ra   s   &r0   copy_graphstateCheckpointable.copy_graphstate  s    $'r3   c                    V ^8  d   QhRRRR/# )r+   stater#  r,   r  r.   )r/   s   "r0   r1   r7    s    777d7r3   c                	    R # rk   r.   r9   r<  s   &&r0   restore_graphstate!Checkpointable.restore_graphstate  s    47r3   r.   N)rS   rT   rU   rV   r   r9  r?  rY   r.   r3   r0   r5  r5    s    ' '7 7r3   r5  c                  J    ] tR tRt$ RtR]R&   R R ltR R ltR	 R
 ltRt	R# )GuardsCheckpointStatei  zO
The GuardCheckpointState - it is the T of Checkpointable[T] for GuardsContext
OrderedSet[Guard]dynamo_guardsc                    V ^8  d   QhRRRR/# )r+   rD  rC  r,   r  r.   )r/   s   "r0   r1   "GuardsCheckpointState.__annotate__  s     + +&7 +D +r3   c                	    Wn         R # rk   rD  )r9   rD  s   &&r0   __init__GuardsCheckpointState.__init__  s    *r3   c                    V ^8  d   QhRRRR/# )r+   r   rB  r,   OrderedSet[Guard] | Noner.   )r/   s   "r0   r1   rF    s     
 
/ 
4L 
r3   c                t    V P                   P                  VP                   4      p\        V4      ^ 8X  d   R# V# )z
Produces a delta against another GuardsCheckpointState.

Returns None if no delta is found, otherwise, return an OrderedSet() of mismatched
Guard type objects.
N)rD  
differencer   r9   r   rs   && r0   diffGuardsCheckpointState.diff  s3     ))%*=*=>q6Q;r3   c                    V ^8  d   QhRRRR/# r+   r   r   r,   rh   r.   )r/   s   "r0   r1   rF         ( (F (t (r3   c                	X    \        V\        4      '       g   R # V P                  V4      RJ # FN)r   rB  rQ  r   s   &&r0   __eq__GuardsCheckpointState.__eq__  s'    %!677yy4''r3   rH  N)
rS   rT   rU   rV   __doc__rW   rI  rQ  rX  rY   r.   r3   r0   rB  rB    s#     %$+
( (r3   rB  c                  J    ] tR tRt$ / tR]R&   R R ltR R ltR R	 ltR
t	R# )ModuleContextCheckpointStatei  dict[str, torch.nn.Module]
nn_modulesc                    V ^8  d   QhRRRR/# )r+   r^  r]  r,   r  r.   )r/   s   "r0   r1   )ModuleContextCheckpointState.__annotate__  s     % %#= %$ %r3   c                	    Wn         R # rk   r^  )r9   r^  s   &&r0   rI  %ModuleContextCheckpointState.__init__  s    $r3   c                    V ^8  d   QhRRRR/# )r+   r   r\  r,   set[str] | Noner.   )r/   s   "r0   r1   r`         
 
6 
? 
r3   c                    \        V P                  P                  4       4      P                  \        VP                  P                  4       4      4      p\	        V4      ^ 8X  d   R# V# )z
Produces a delta against another ModuleContextCheckpointState.

Returns None if no delta is found, otherwise, return a set() of mismatched
module key names.
N)setr^  keysrN  r   rO  s   && r0   rQ  !ModuleContextCheckpointState.diff  sM     $$&'223u7G7G7L7L7N3OPq6Q;r3   c                    V ^8  d   QhRRRR/# rT  r.   )r/   s   "r0   r1   r`  )  rU  r3   c                	X    \        V\        4      '       g   R # V P                  V4      RJ # rW  )r   r\  rQ  r   s   &&r0   rX  #ModuleContextCheckpointState.__eq__)  '    %!=>>yy4''r3   rb  N)
rS   rT   rU   rV   r^  rW   rI  rQ  rX  rY   r.   r3   r0   r\  r\    s!    -/J*/%
( (r3   r\  c                  :    ] tR tRtR R ltR R ltR R ltRtR	# )
ModuleContexti/  c                   V ^8  d   QhRR/# r+  r.   )r/   s   "r0   r1   ModuleContext.__annotate__0  s     - -$ -r3   c                	    / V n         R # rk   rb  ra   s   &r0   rI  ModuleContext.__init__0  s	    *,r3   c                   V ^8  d   QhRR/# )r+   r,   r\  r.   )r/   s   "r0   r1   rr  3  s     C C!= Cr3   c                	>    \        \        V P                  4      4      # rk   )r\  dictr^  ra   s   &r0   r9  ModuleContext.copy_graphstate3  s    +D,ABBr3   c                    V ^8  d   QhRRRR/# )r+   r<  r\  r,   r  r.   )r/   s   "r0   r1   rr  6  s     + +(D + +r3   c                	    \        V\        4      '       g   \        R \        V4       24      hVP                  V n        R# )z+expected ModuleContextCheckpointState, got N)r   r\  r8   typer^  r>  s   &&r0   r?   ModuleContext.restore_graphstate6  s:    %!=>> =d5k]K   **r3   rb  N)rS   rT   rU   rV   rI  r9  r?  rY   r.   r3   r0   rp  rp  /  s    -C+ +r3   rp  c                  J    ] tR tRt$ / tR]R&   R R ltR R ltR R	 ltR
t	R# )GlobalContextCheckpointStatei>  dict[str, tuple[Callable, Any]]global_statec                    V ^8  d   QhRRRR/# )r+   global_statesr  r,   r  r.   )r/   s   "r0   r1   )GlobalContextCheckpointState.__annotate__A  s     * *&E *$ *r3   c                	    Wn         R # rk   r  )r9   r  s   &&r0   rI  %GlobalContextCheckpointState.__init__A  s    )r3   c                    V ^8  d   QhRRRR/# )r+   r   r~  r,   re  r.   )r/   s   "r0   r1   r  D  rf  r3   c                    \        V P                  P                  4       4      P                  \        VP                  P                  4       4      4      p\	        V4      ^ 8X  d   R# V# )z
Produces a delta against another GlobalContextCheckpointState.

Returns None if no delta is found, otherwise, return a set() of mismatched
global key names.
N)rh  r  ri  rN  r   rO  s   && r0   rQ  !GlobalContextCheckpointState.diffD  sO     !!&&()44S9K9K9P9P9R5STq6Q;r3   c                    V ^8  d   QhRRRR/# rT  r.   )r/   s   "r0   r1   r  P  rU  r3   c                	X    \        V\        4      '       g   R # V P                  V4      RJ # rW  )r   r~  rQ  r   s   &&r0   rX  #GlobalContextCheckpointState.__eq__P  rn  r3   r  N)
rS   rT   rU   rV   r  rW   rI  rQ  rX  rY   r.   r3   r0   r~  r~  >  s!    46L16*
( (r3   r~  c                  F    ] tR tRtRt0 RmtR R ltR R ltR R ltR	t	R
# )GlobalContextiV  zn
This keeps track of the global torch state during tracing of a function.
For example, torch.is_grad_enabled.
c                   V ^8  d   QhRR/# r+  r.   )r/   s   "r0   r1   GlobalContext.__annotate__e  s     @ @$ @r3   c                	    / V n         R # rk   r  ra   s   &r0   rI  GlobalContext.__init__e  s
    =?r3   c                   V ^8  d   QhRR/# )r+   r,   r~  r.   )r/   s   "r0   r1   r  h  s     ? ?!= ?r3   c                	,    \        V P                  4      # rk   )r~  r  ra   s   &r0   r9  GlobalContext.copy_graphstateh  s    +D,=,=>>r3   c                    V ^8  d   QhRRRR/# )r+   r<  r~  r,   r  r.   )r/   s   "r0   r1   r  k  s      (D  r3   c                	   \        V\        4      '       g   \        R \        V4       24      hVP                  V n        \        V P                  4      \        V P                  4      8X  d3   \        V P                  P                  4       4      V P                  8X  g=   \        R\        V P                  P                  4       4       RV P                   24      hV P                  P                  4        F  w  r#V! V4       K  	  R# )z+expected GlobalContextCheckpointState, got z Global state mismatch: got keys z, expected N)
r   r~  r8   r{  r  r   _supported_global_statesrh  ri  values)r9   r<  r   argss   &&  r0   r?   GlobalContext.restore_graphstatek  s    %!=>> =d5k]K  "..!!"c$*G*G&HHD%%**,-1N1NN 23t7H7H7M7M7O3P2Q R 99:<  ++224JDJ 5r3   r  N>   grad_enabledautocast_enabledautocast_cpu_dtypeautocast_gpu_dtypeautocast_cpu_enabledautocast_cache_enabled)
rS   rT   rU   rV   rZ  r  rI  r9  r?  rY   r.   r3   r0   r  r  V  s$    
 @? r3   r  c                      ] tR tRtRR R lltR R ltR R ltR	 R
 ltR R ltR R lt	R R lt
RRR^ /R R lltR R ltR R ltR R ltRtR# )	GuardsSeti  Nc                    V ^8  d   QhRRRR/# )r+   innerrL  r,   r  r.   )r/   s   "r0   r1   GuardsSet.__annotate__  s     	. 	.6 	.$ 	.r3   c                	    Vf   \        4       V n        MWn        \        \        4      V n        V P                   F  pV P                  V4       K  	  R # rk   )r   r  r   listsource_to_guardstrack_guard_by_source)r9   r  guards   && r0   rI  GuardsSet.__init__  sB    =,6LDJJ CNdBSZZE&&u-  r3   c                    V ^8  d   QhRRRR/# )r+   r  r   r,   r  r.   )r/   s   "r0   r1   r    s     4 45 4T 4r3   c                	b    VP                   pV P                  V,          P                  V4       R # rk   )r   r  r  )r9   r  r   s   && r0   r  GuardsSet.track_guard_by_source  s&    ))f%,,U3r3   c                   V ^8  d   QhRR/# )r+   r,   zIterator[Guard]r.   )r/   s   "r0   r1   r    s        /  r3   c                	,    \        V P                  4      # rk   )iterr  ra   s   &r0   __iter__GuardsSet.__iter__      DJJr3   c                   V ^8  d   QhRR/# r   r.   )r/   s   "r0   r1   r    s       r3   c                	,    \        V P                  4      # rk   )r   r  ra   s   &r0   __len__GuardsSet.__len__  s    4::r3   c                    V ^8  d   QhRRRR/# )r+   r   r  r,   r.   )r/   s   "r0   r1   r    s     3 3Y 39 3r3   c                	N    \        V P                  VP                  ,
          4      # rk   )r  r  r   s   &&r0   __sub__GuardsSet.__sub__  s    ekk122r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   r    s        $  r3   c                	,    \        V P                  4      # rk   )rh   r  ra   s   &r0   __bool__GuardsSet.__bool__  r  r3   c                   V ^8  d   QhRR/# r+  r.   )r/   s   "r0   r1   r    s     2 2t 2r3   c                	L    \        4       V n        \        \        4      V n        R # rk   )r   r  r   r  r  ra   s   &r0   clearGuardsSet.clear  s    \
 +D 1r3   collect_debug_stackTskipc               (    V ^8  d   QhRRRRRRRR/# )	r+   r  r   r  rh   r  rH   r,   r  r.   )r/   s   "r0   r1   r    s,     * **48*GJ*	*r3   c               	B   WP                   9   d   R # V'       d2   VP                  f$   \        P                  ! ^V,           R7      Vn        VP                  f   \
        P                  4       Vn        V P                   P                  V4       V P                  V4       R # )Nr  )	r  r   r   extractr   TracingContextextract_stackaddr  )r9   r  r  r  s   &&$$r0   r  GuardsSet.add  so     JJ{{"/77QXF#-;;=E

u""5)r3   c                    V ^8  d   QhRRRR/# )r+   othersz
set[Guard]r,   r  r.   )r/   s   "r0   r1   r    s     $ $j $T $r3   c                	P    V F  pV F  pV P                  V^R7       K  	  K!  	  R# )r   r  N)r  )r9   r  ogs   &*  r0   updateGuardsSet.update  s&    A#  r3   c                    V ^8  d   QhRRRR/# )r+   r   r   r,   zlist[Guard]r.   )r/   s   "r0   r1   r    s     3 3F 3{ 3r3   c                :    \        V P                  V,          4      # )z4Return all guards with the given originating_source.)r  r  )r9   r   s   &&r0   get_guards_for_sourceGuardsSet.get_guards_for_source  s    D))&122r3   c                    V ^8  d   QhRRRR/# )r+   r   r   r,   r  r.   )r/   s   "r0   r1   r    s     . . .4 .r3   c                   aa ^RI Ho \        VV3R lV P                   4       4      V n        \	        \
        4      V n        V P                   F  pV P                  V4       K  	  R# )z.Delete all guards that contains a given source)is_from_sourcec              3  ^   <"   T F"  pS! VP                   S4      '       d   K  Vx  K$  	  R # 5irk   )r   ).0r  r  r   s   & r0   	<genexpr>6GuardsSet.remove_guards_with_source.<locals>.<genexpr>  s%       
!!8L8Lf)UAAzs   -
-N)_dynamo.sourcer  r   r  r   r  r  r  )r9   r   r  r  s   &f @r0   remove_guards_with_source#GuardsSet.remove_guards_with_source  sN    2  
zz 
 


 !,D 1ZZE&&u-  r3   )r  r  rk   )rS   rT   rU   rV   rI  r  r  r  r  r  r  r  r  r  r  rY   r.   r3   r0   r  r    sN    	.4 
3 2*;?*MN*$
3. .r3   r  c                  d    ] tR tRtR R lt]P                  R R l4       tR R ltR R	 lt	R
t
R# )GuardsContexti  c                   V ^8  d   QhRR/# r+  r.   )r/   s   "r0   r1   GuardsContext.__annotate__  s     ( ($ (r3   c                	@    \        4       V n        . V n        R V n        R# rW  )r  rD  aotautograd_guardsskip_installra   s   &r0   rI  GuardsContext.__init__  s    (168"'r3   c                   V ^8  d   QhRR/# r+   r,   Generator[None, None, None]r.   )r/   s   "r0   r1   r    s     $ $$? $r3   c              #  	`   "   V P                   pR V n          Rx  Wn         R#   Yn         i ; i5i)TN)r  )r9   olds   & r0   skip_guard_install GuardsContext.skip_guard_install  s,      	$ #s   .# .+.c                   V ^8  d   QhRR/# )r+   r,   rB  r.   )r/   s   "r0   r1   r    s     K K!6 Kr3   c                	R    \        \        V P                  P                  4      4      # rk   )rB  r   rD  r  ra   s   &r0   r9  GuardsContext.copy_graphstate  s    $Z0B0B0H0H%IJJr3   c                    V ^8  d   QhRRRR/# )r+   r<  rB  r,   r  r.   )r/   s   "r0   r1   r    s     < <(= <$ <r3   c                	    \        V\        4      '       g   \        R \        V4       24      h\	        VP
                  4      V n        R# )z$expected GuardsCheckpointState, got N)r   rB  r8   r{  r  rD  r>  s   &&r0   r?   GuardsContext.restore_graphstate  s:    %!677 #GU}!UVV&u':':;r3   )r  rD  r  N)rS   rT   rU   rV   rI  
contextlibr   r  r9  r?  rY   r.   r3   r0   r  r    s1    (
 $ $K< <r3   r  c                      ] tR tRt]R R l4       t]R R l4       t]R R l4       t]R R	 l4       t]R
 R l4       t	]R R l4       t
]R R l4       t]R R l4       tRtR# )HopSubgraphCachei  c               $    V ^8  d   QhRRRRRR/# r+   fn_coder   
identifierr-   r,   r  r.   )r/   s   "r0   r1   HopSubgraphCache.__annotate__  s$      -0	r3   c                	    R # rk   r.   r9   r  r   s   &&&r0   add_dynamo_installed_submodule/HopSubgraphCache.add_dynamo_installed_submodule  s     r3   c                    V ^8  d   QhRRRR/# r+   r  r   r,   r  r.   )r/   s   "r0   r1   r    s    RRxRIRr3   c                	    R # rk   r.   r9   r  s   &&r0   get_dynamo_installed_submodules0HopSubgraphCache.get_dynamo_installed_submodules  s    ORr3   c               $    V ^8  d   QhRRRRRR/# r+   r   r-   keyr   r,   r  r.   )r/   s   "r0   r1   r    s    QQQ8QQr3   c                	    R # rk   r.   r9   r   r  s   &&&r0   add_autograd_key_entry'HopSubgraphCache.add_autograd_key_entry  s    NQr3   c                    V ^8  d   QhRRRR/# r+   r   r-   r,   zCallable | Noner.   )r/   s   "r0   r1   r    s    MMMMr3   c                	    R # rk   r.   r9   r   s   &&r0   get_autograd_key_entry'HopSubgraphCache.get_autograd_key_entry  s    JMr3   c               $    V ^8  d   QhRRRRRR/# r  r.   )r/   s   "r0   r1   r    s    SS3SXS$Sr3   c                	    R # rk   r.   r  s   &&&r0   add_proxy_dispatch_entry)HopSubgraphCache.add_proxy_dispatch_entry  s    PSr3   c                    V ^8  d   QhRRRR/# r  r.   )r/   s   "r0   r1   r    s    OO3O?Or3   c                	    R # rk   r.   r  s   &&r0   get_proxy_dispatch_entry)HopSubgraphCache.get_proxy_dispatch_entry  s    LOr3   c               (    V ^8  d   QhRRRRRRRR/# 	r+   r   r-   tangent_metadatatuple[object]gmodtorch.fx.GraphModuler,   rH   r.   )r/   s   "r0   r1   r    s2       ( #	
 
r3   c                	    R # rk   r.   )r9   r   r#  r%  s   &&&&r0   add_lazy_bwd_entry#HopSubgraphCache.add_lazy_bwd_entry  s     r3   c               $    V ^8  d   QhRRRRRR/# r+   r   r-   r#  r$  r,   z.tuple[torch.fx.GraphModule | None, int | None]r.   )r/   s   "r0   r1   r    s$     = ==1>=	7=r3   c                	    R # rk   r.   r9   r   r#  s   &&&r0   get_lazy_bwd_entry#HopSubgraphCache.get_lazy_bwd_entry  s     :=r3   r.   N)rS   rT   rU   rV   r   r  r
  r  r  r  r  r(  r.  rY   r.   r3   r0   r  r    s      R RQ QM MS SO O  = =r3   r  c                  l    ] tR tRt$ R]R&   R]R&   R]R&   R]R	&   R
]R&   R]R&   R]R&   ^ tR]R&   RtR# )InvokeSubgraphReuseEntryi	  r-   	body_namer&  	body_gmodz!NestedCompileRegionOptions | Noneru   	list[Any]subgraph_input_mappingrh   single_tensor_outputzIlist[tuple[torch.Size, tuple[int, ...], torch.dtype, torch.device, bool]]output_metadatazlist[Source | None]arg_sourcesrH   num_user_outputsr.   N)rS   rT   rU   rV   rW   r9  rY   r.   r3   r0   r1  r1  	  sD    N##--    %$ cr3   r1  c                  j    ] tR tRt$ R]R&   R]R&   RtR]R&   ]P                  ! ]R	7      t	R
]R&   Rt
R# )InvokeSubgraphReuseConditioni#  zlist[tuple[Any, object]]input_checksz2list[tuple[Source, GuardCheckSpec, object, Guard]]r   Nzpytree.TreeSpec | Nonetreespec)default_factoryzOrderedSet[Source]traced_sourcesr.   )rS   rT   rU   rV   rW   r=  dataclassesfieldr   r?  rY   r.   r3   r0   r;  r;  #  s7     +*
 ?> (,H$+
 *5):)::)VN&Vr3   r;  c                      ] tR tRtR R ltR R ltR R ltR R	 ltR
 R ltR R lt	R R lt
R R ltR R ltR R ltR R ltR"R R lltR R ltR R ltR"R R lltR tR!# )#InvokeSubgraphCachei>  c                   V ^8  d   QhRR/# r+  r.   )r/   s   "r0   r1    InvokeSubgraphCache.__annotate__?  s      $ r3   c                	    / V n         / V n        \        \        4      V n        \        \
        4      V n        / V n        \        \        4      V n        \        \
        4      V n	        R # rk   )
autograd_cacheproxy_dispatch_cacher   r  dynamo_installed_submodulesrw  lazy_bwd_cacheeffects_cachesubgraph_reuse_cachesubgraph_reuse_key_cachera   s   &r0   rI  InvokeSubgraphCache.__init__?  sc    359;!FQRVFW(  	
  	  	!  	%r3   c               $    V ^8  d   QhRRRRRR/# r  r.   )r/   s   "r0   r1   rE  U  s)     E EE-0E	Er3   c                	J    V P                   V,          P                  V4       R # rk   )rI  r  r  s   &&&r0   r  2InvokeSubgraphCache.add_dynamo_installed_submoduleU  s     	((188Dr3   c                    V ^8  d   QhRRRR/# r  r.   )r/   s   "r0   r1   rE  Z  s     A Ax AI Ar3   c                	:    V P                   P                  V. 4      # rk   )rI  getr	  s   &&r0   r
  3InvokeSubgraphCache.get_dynamo_installed_submodulesZ  s    //33GR@@r3   c               $    V ^8  d   QhRRRRRR/# r  r.   )r/   s   "r0   r1   rE  ]  s!     . . .8 . .r3   c                	"    W P                   V&   R # rk   )rG  r  s   &&&r0   r  *InvokeSubgraphCache.add_autograd_key_entry]  s    *-J'r3   c                    V ^8  d   QhRRRR/# r  r.   )r/   s   "r0   r1   rE  `  s     9 9 9 9r3   c                	:    V P                   P                  VR 4      # rk   )rG  rT  r  s   &&r0   r  *InvokeSubgraphCache.get_autograd_key_entry`  s    ""&&z488r3   c               $    V ^8  d   QhRRRRRR/# r  r.   )r/   s   "r0   r1   rE  c  s!     4 43 4X 4$ 4r3   c                	"    W P                   V&   R # rk   )rH  r  s   &&&r0   r  ,InvokeSubgraphCache.add_proxy_dispatch_entryc  s    03!!*-r3   c                    V ^8  d   QhRRRR/# r  r.   )r/   s   "r0   r1   rE  f  s     ? ?3 ?? ?r3   c                	:    V P                   P                  VR 4      # rk   )rH  rT  r  s   &&r0   r  ,InvokeSubgraphCache.get_proxy_dispatch_entryf  s    ((,,Z>>r3   c               (    V ^8  d   QhRRRRRRRR/# r"  r.   )r/   s   "r0   r1   rE  i  s2     	 		 (	 #		
 
	r3   c                	l    \        V P                  V,          4      pW43V P                  V,          V&   V# rk   )r   rJ  )r9   r   r#  r%  	num_gmodss   &&&& r0   r(  &InvokeSubgraphCache.add_lazy_bwd_entryi  s8     ++J78	=A<MJ'(89r3   c               $    V ^8  d   QhRRRRRR/# r+  r.   )r/   s   "r0   r1   rE  t  s)     S SS1>S	7Sr3   c                	l    WP                   9  d   R# V P                   V,          P                  VR4      # )N)NN)rJ  rT  r-  s   &&&r0   r.  &InvokeSubgraphCache.get_lazy_bwd_entryt  s5     000"":.223C\RRr3   c               $    V ^8  d   QhRRRRRR/# )r+   r   r-   effectsrh  r,   r  r.   )r/   s   "r0   r1   rE  |  s!     
1 
1c 
1C 
1D 
1r3   c           	         V P                   P                  VR4      ;p'       d   W#8w  d   \        RV RV RV R24      hW P                   V&   R# )z>Store the effect types for a given invoke_subgraph identifier.NzPDifferent number of effects were found for invoke_subgraph call with identifier z,. 
Previously we had the following effects: z.
But now we have: .)rK  rT  r8   )r9   r   rj  prev_effectss   &&& r0   add_effectsInvokeSubgraphCache.add_effects|  sj    --11*dCC<C&$,,6< 8@@L~ N((/y3  *1:&r3   c                    V ^8  d   QhRRRR/# )r+   r   r-   r,   z
set | Noner.   )r/   s   "r0   r1   rE    s     8 8c 8j 8r3   c                :    V P                   P                  VR4      # )zARetrieve the effect types for a given invoke_subgraph identifier.N)rK  rT  r  s   &&r0   get_effectsInvokeSubgraphCache.get_effects  s    !!%%j$77r3   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r+   r  r   	conditionr;  entryr1  max_reuse_entriesrH   r,   r  r.   )r/   s   "r0   r1   rE    s<     + ++ 0+ (	+
 + 
+r3   c                	    V P                   V,          p\        V4      V8  d   \        R V RV R24      hVP                  W#34       R# )1invoke_subgraph: exceeded maximum reuse entries () for function code a?  . This most likely means a guard keeps failing on every invocation, preventing subgraph reuse. Set TORCH_LOGS='+hierarchical_compile' to identify which guard is failing. If reuse is genuinely not possible and you need more cache entries, increase the limit via the max_reuse_entries argument to nested_compile_region().N)rL  r   RuntimeErrorr  )r9   r  ru  rv  rw  entriess   &&&&& r0   add_reuse_entry#InvokeSubgraphCache.add_reuse_entry  s^     ++G4w<,,%&&:7) DIJ	 	 		)*r3   c               $    V ^8  d   QhRRRRRR/# )r+   r  r   	evaluatorzHCallable[[InvokeSubgraphReuseCondition, InvokeSubgraphReuseEntry], bool]r,   InvokeSubgraphReuseEntry | Noner.   )r/   s   "r0   r1   rE    s(      
 
)r3   c                	    V P                   P                  V. 4      p\        V4       FB  w  pw  rVV! WV4      '       g   K  V^ 8  d"   VP                  ^ VP	                  V4      4       Vu # 	  R# rr   )rL  rT  	enumerateinsertpop)r9   r  r  r|  iru  rv  s   &&&    r0   find_reuse_entry$InvokeSubgraphCache.find_reuse_entry  se     ++//<%.w%7!A!	**q5NN1gkk!n5 &8 r3   c               $    V ^8  d   QhRRRRRR/# )r+   r  r   hash_keyrH   r,   r  r.   )r/   s   "r0   r1   rE    s)     L LL+.L	(Lr3   c                	X    V P                   P                  V/ 4      P                  V4      # rk   )rM  rT  )r9   r  r  s   &&&r0   find_reuse_entry_by_key+InvokeSubgraphCache.find_reuse_entry_by_key  s(     ,,00"=AA(KKr3   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r+   r  r   r  rH   rv  r1  rw  r,   r  r.   )r/   s   "r0   r1   rE    s<     $ $$ $ (	$
 $ 
$r3   c                	    V P                   V,          p\        V4      V8  d   W%9  d   \        R V RV R24      hW5V&   R# )ry  rz  zc (hash-key path). Increase the limit via the max_reuse_entries argument to nested_compile_region().N)rM  r   r{  )r9   r  r  rv  rw  	key_caches   &&&&& r0   add_reuse_entry_by_key*InvokeSubgraphCache.add_reuse_entry_by_key  sZ     11':	y>..83L%&&:7) D+,  $(r3   )rG  rI  rK  rJ  rH  rL  rM  N)   )rS   rT   rU   rV   rI  r  r
  r  r  r  r  r(  r.  rn  rr  r}  r  r  r  rY   r.   r3   r0   rC  rC  >  sV    ,E
A.94?	S
18+* L
$ $r3   rC  c                  .    ] tR tRtR R ltR R ltRtR# )HopDispatchSetCachei  c                   V ^8  d   QhRR/# r+  r.   )r/   s   "r0   r1    HopDispatchSetCache.__annotate__  s     F F$ Fr3   c                	4    ^ RI Hp V\        4       /V n        R# )r   )invoke_subgraphN)'torch._higher_order_ops.invoke_subgraphr  rC  hop_cache_map)r9   r  s   & r0   rI  HopDispatchSetCache.__init__  s    K-/B/DEr3   c                    V ^8  d   QhRRRR/# )r+   opztorch._ops.HigherOrderOperatorr,   zHopSubgraphCache | Noner.   )r/   s   "r0   r1   r    s     & &: &?V &r3   c                	L    WP                   9  d   R # V P                   V,          # rk   r  )r9   r  s   &&r0   	get_cacheHopDispatchSetCache.get_cache  s"    '''!!"%%r3   r  N)rS   rT   rU   rV   rI  r  rY   r.   r3   r0   r  r    s    F& &r3   r  c                  z    ] tR tRt]R R l4       t]R R l4       tR R lt]R R	 l4       t]R
 R l4       t	Rt
R# )CompileContexti  c                   V ^8  d   QhRR/# )r+   r,   r  r.   )r/   s   "r0   r1   CompileContext.__annotate__  s     $ $ $r3   c                 	\    \         P                  f   \        R4      h\         P                  # )Nzcompile_context is not set)_TLScompile_contextr8   r.   r3   r0   rT  CompileContext.get  s&    ' !=>>###r3   c                   V ^8  d   QhRR/# )r+   r,   CompileContext | Noner.   )r/   s   "r0   r1   r         6 6* 6r3   c                 	$    \        \        R R4      # r  Ngetattrr  r.   r3   r0   try_getCompileContext.try_get      t.55r3   c                    V ^8  d   QhRRRR/# )r+   r>   r@   r,   r  r.   )r/   s   "r0   r1   r    s     . .#3 . .r3   c                	    Ve.   \        V\        4      '       g   \        R\        V4       24      hWn        ^ V n        . V n        R # )Nz*compile_id must be None or CompileId, got )r   r$   r8   r{  r>   r\   shape_env_guards)r9   r>   s   &&r0   rI  CompileContext.__init__  sG    !*Z*K*K <T*=M<NO  -7+-r3   c                   V ^8  d   QhRR/# )r+   r,   r@   r.   )r/   s   "r0   r1   r     s       0 r3   c                 	N    \         P                  4       p V f   R # V P                  # rk   )r  r  r>   ra   s    r0   current_compile_id!CompileContext.current_compile_id  s"    %%'<r3   c                   V ^8  d   QhRR/# )r+   r,   zTraceId | Noner.   )r/   s   "r0   r1   r    s     6 6n 6r3   c                 	    \         P                  4       p V f   R # V P                  f   R # \        V P                  V P                  4      # rk   )r  r  r>   r[   r\   ra   s    r0   current_trace_idCompileContext.current_trace_id  s:    %%'<??"t55r3   )r\   r>   r  N)rS   rT   rU   rV   r"  rT  r  rI  r  r  rY   r.   r3   r0   r  r    sU    $ $
 6 6.   6 6r3   r  c                  :    ] tR tRt$ RtR]R&   R]R&   R]R&   R	tR
# )InlinedCodeCachei  z8Cache for code-object-derived data used during inlining.r4  instructionszdict[Any, int]indexofdict[str, Any]code_optionsr.   N)rS   rT   rU   rV   rZ  rW   rY   r.   r3   r0   r  r    s    B  r3   r  c                  h   ] tR tRtRt]R R l4       t]R R l4       tR R ltR	 R
 lt	]]
R R l4       4       t]R R l4       tR R lt]]P                  R R l4       4       t]]P                  R R l4       4       t]]P                  R R l4       4       t]R R l4       t]R R l4       tRtR# )r  i  z
Provides the currently installed TracingContext, or None.

Note that it is a staticmethod, and invocations outside of `with tracing()` (see below), are valid but
will return None.
c                   V ^8  d   QhRR/# )r+   r,   TracingContext | Noner.   )r/   s   "r0   r1   TracingContext.__annotate__"  r  r3   c                 	$    \        \        R R4      # )tracing_contextNr  r.   r3   r0   r  TracingContext.try_get!  r  r3   c                   V ^8  d   QhRR/# )r+   r,   r  r.   )r/   s   "r0   r1   r  &  s     
 
 
r3   c                 	T    \         P                  4       ;p '       d   V # \        R 4      h)z<TracingContext.get() must be called within an ongoing trace.)r  r  r{  )ctxs    r0   rT  TracingContext.get%  s+     ((**3*JJ
 	
r3   c                    V ^8  d   QhRRRR/# )r+   	fake_modeFakeTensorMode | Noner,   r  r.   )r/   s   "r0   r1   r  -  s     4. 4."7 4.D 4.r3   c                	   \        4       V n        \        4       V n        \	        4       V n        \        4       V n        \        4       V n        \        4       V n	        Wn
        . V n        R V n        R V n        R V n        R V n        R V n        R V n        R V n        R V n        RV n        \+        4       V n        RV n        \1        4       V n        . V n        R V n        R # )NF)r  guards_contextrp  module_contextr  global_contextrw  previously_inlined_functionspreviously_cleaned_instructionsinlined_code_cacher  frame_summary_stackloc_in_framefw_metadataddp_optimizer_ctxaot_graph_nameparams_flatparams_flat_unwrap_subclassesparams_unwrapped_to_flat_indexoutput_strides#force_unspec_int_unbacked_size_liker   tensor_to_contextfakify_first_callr  hop_dispatch_set_cachetraced_codecudagraph_annotation)r9   r  s   &&r0   rI  TracingContext.__init__-  s    +o+o+o<@F)?Cv,?Cv09AC  :>7;=A04-1?C*@D+ DH 490!8!:
 "'&9&;#+-)-!r3   c                   V ^8  d   QhRR/# r+  r.   )r/   s   "r0   r1   r  c  s     ( (t (r3   c                	    / V P                   n        V P                  P                  4        V P                  P                  4        V P
                  P                  4        R # rk   )r  r  r  r  r  r  ra   s   &r0   r  TracingContext.clearc  sH     ,.())//1,,224%%'r3   c                    V ^8  d   QhRRRR/# )r+   kwargsr   r,   r  r.   )r/   s   "r0   r1   r  m  s     ' ' ' ; 'r3   c               +  	X  "   / p\         P                  4       pV  F  p\        W#4      W&   K  	  V P                  4        F  w  r4\	        W#V4       K  	   R x  VP                  4        F  w  r4\	        W#V4       K  	  R #   TP                  4        F  w  r4\	        Y#T4       K  	  i ; i5irk   )r  rT  r  rG   setattr)r  priorr  r  vals   ,    r0   patchTracingContext.patchk  s        "C *EJ  HCCc" '	'!KKM#& *EKKM#& *s   AB*B  'B* 'B''B*c                   V ^8  d   QhRR/# )r+   r,   ztraceback.StackSummaryr.   )r/   s   "r0   r1   r  }  s     7 71 7r3   c                 	    \         P                  4       p V f   \        P                  ! 4       # V P                  pV P
                  e   WP                  4       .,           p\        P                  P                  V4      # rk   )r  r  	tracebackStackSummaryr  r  _populate_loc_in_frame_summary	from_list)r9   r   s     r0   r  TracingContext.extract_stack|  sf    %%'<))++(((@@BCCE%%//66r3   c                   V ^8  d   QhRR/# )r+   r,   ztraceback.FrameSummaryr.   )r/   s   "r0   r1   r    s     W W0F Wr3   c                	    V P                   f   \        R4      hV P                   w  rp\        P                  ! WVRR7      # )Nzloc_in_frame must not be NoneF)lookup_line)r  r8   r  FrameSummary)r9   filenamelineno
frame_names   &   r0   r  -TracingContext._populate_loc_in_frame_summary  s@    $ !@AA'+'8'8$*%%h
PUVVr3   c                   V ^8  d   QhRR/# r  r.   )r/   s   "r0   r1   r    s      4 r3   c            	   #  	  "   \         P                  4       p \        P                  P                  P                  V R . 4      ;_uu_ 4        \        P                  P                  P                  V RR4      ;_uu_ 4         Rx   RRR4       RRR4       R#   \         d    p\        TR4      '       g   RTn        h Rp?ii ; i  + '       g   i     LG; i  + '       g   i     R# ; i5i)r  r  N
real_stack)	r  rT  unittestmockr  r   rJ   hasattrr  )tcrP   s     r0   clear_frameTracingContext.clear_frame  s      !MM&&r+@"EEMM&&r>4@@ A FE
  $ q,//#'AL)	 A@ FEEsT   AC+
4C>C	 BC
C+C"B<<CC	CCC(	"	C+c                    V ^8  d   QhRRRR/# )r+   frame_summaryztraceback.FrameSummary | Noner,   r  r.   )r/   s   "r0   r1   r    s     " "4"	$"r3   c              #  	  "   \         P                  4       pV e   VP                  P                  V 4       VP                  pR Vn         R x   T e   TP                  P                  4        Y!n        R #   \
         d.   p\        TR4      '       g   TP                  4       Tn        h R p?ii ; i  T e   TP                  P                  4        Y!n        i ; i5i)Nr  )
r  rT  r  r  r  rJ   r  r  r  r  )r  r  r  rP   s   &   r0   current_frameTracingContext.current_frame  s      !$""))-8oo		" (&&**,!O  	1l++!//1	
 (&&**,!Os6   AC
A5 &C5B- (B((B--B0 0&CCc                   V ^8  d   QhRR/# )r+   r,   z:Generator[list[tuple[int, ...] | None] | None, None, None]r.   )r/   s   "r0   r1   r    s     3 3 $ 3r3   c               #  	   "   \         P                  4       p V f   R x  R # V P                  p. V n         V P                  x  Wn        R #   Yn        i ; i5irk   )r  r  r  )r  old_output_stridess     r0   report_output_strides$TracingContext.report_output_strides  sT     
 ##%:J..	3### 2 2s   2AA AAAc               (    V ^8  d   QhRRRRRRRR/# )r+   r  r-   r  rH   r  r,   r  r.   )r/   s   "r0   r1   r    s.     K K# Ks K K Kr3   c                	<    WV3\         P                  4       n        R # rk   )r  rT  r  )r  r  r  s   &&&r0   set_current_locTracingContext.set_current_loc  s     .6z,J)r3   c                   V ^8  d   QhRR/# )r+   r,   zlist[CodeType] | Noner.   )r/   s   "r0   r1   r    s      2 r3   c                 	N    \         P                  4       p V f   R # V P                  # rk   )r  r  r  )r  s    r0   get_traced_codeTracingContext.get_traced_code  s"    ##%:~~r3   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  N)rS   rT   rU   rV   rZ  r"  r  rT  rI  r  r   r  r  r  r  r  r  r  r  r  rY   r.   r3   r0   r  r    s     6 6 
 
4.l( '  ' 7 7W   < "  "* 3  3 K K
  r3   r  c                    V ^8  d   QhRRRR/# )r+   contextr  r,   z,Generator[CompileContext | None, None, None]r.   )r/   s   "r0   r1   r1     s     + +"+1+r3   c              #     "   \        \        R R4      pV \        n         V x  V\        n        R#   T\        n        i ; i5ir  )r  r  r  )r"  old_contexts   & r0   r  r    s8      $ 148K"D+*{s   A1 A>Ac                    V ^8  d   QhRRRR/# )r+   r"  r  r,   z,Generator[TracingContext | None, None, None]r.   )r/   s   "r0   r1   r1     s     + +"+1+r3   c              #  >  "   \        \        RR4      pV \        n         V x   T eK   T P                  e=   T P                  P                  e%   T P                  P                  P                  4        T\        n        R#   \         d2   p\	        TR4      '       g   T e   T P                  4       Tn        h Rp?ii ; i  T eK   T P                  e=   T P                  P                  e%   T P                  P                  P                  4        T\        n        i ; i5i)z
This function installs the passed in tracing context as a dynamic scoped
global variable.

Calls to TracingContext.get() while not under a `with tracing()` context
will return None.
r  Nr  )
r  r  r  rJ   r  r  r  r  	shape_envcleanup)r"  r$  rP   s   &  r0   tracingr)    s      $ 148K"D+ !!-!!++7''//1*  q,''G,?"002AL !!-!!++7''//1*s5   DB  AD B<,B77B<<B? ?ADDc               $    V ^8  d   QhRRRRRR/# )r+   rK   type[T]r  r   r,   r.   )r/   s   "r0   r1   r1     s     K KG Ks Kw Kr3   c                    R # rk   r.   rK   r  s   &,r0   dataclass_with_cached_hashr.    s    HKr3   c               $    V ^8  d   QhRRRRRR/# )r+   rK   r  r  r   r,   zCallable[[type[T]], type[T]]r.   )r/   s   "r0   r1   r1     s$     ' '	' #'!'r3   c                    R # rk   r.   r-  s   &,r0   r.  r.    s     $'r3   c               $    V ^8  d   QhRRRRRR/# )r+   rK   ztype[T] | Noner  r   r,   z&type[T] | Callable[[type[T]], type[T]]r.   )r/   s   "r0   r1   r1     s$      	*-+r3   c                2   a R  V3R llpV f   V# V! V 4      # )c                    V ^8  d   QhRRRR/# )r+   	cls_innerr+  r,   r.   )r/   s   "r0   r1   0dataclass_with_cached_hash.<locals>.__annotate__  s       G r3   c                   <a \         P                  ! V 3/ SB pV P                  oR  V3R llpR pW!n        W1n        V# )c                   V ^8  d   QhRR/# r   r.   )r/   s   "r0   r1   >dataclass_with_cached_hash.<locals>.wrap.<locals>.__annotate__  s     	 	c 	r3   c                z   < \        V R 4      '       g   \        P                  V R S! V 4      4       V P                  # )r   )r  r   __setattr__r   )r9   old_hashs   &r0   r   :dataclass_with_cached_hash.<locals>.wrap.<locals>.__hash__  s0    4))""4(4.A::r3   c                   a  \         P                  ! S 4      p\        ;QJ d    . V 3R  lV 4       F  NK  	  5M! V 3R  lV 4       4      pS P                  V3# )c              3  v   <"   T F.  qP                   '       g   K  \        SVP                  4      x  K0  	  R # 5irk   )initr  r   )r  fr9   s   & r0   r  Odataclass_with_cached_hash.<locals>.wrap.<locals>.__reduce__.<locals>.<genexpr>(  s&      Q1&&!6qvv!6!6s   99)r@  fieldstupler   )r9   rB  field_valuess   f  r0   
__reduce__<dataclass_with_cached_hash.<locals>.wrap.<locals>.__reduce__#  sB     !''-F 5 Q Q55 Q QQLNNL11r3   )r@  r   r   rE  )r4  new_clsr   rE  r;  r  s   &   @r0   wrap(dataclass_with_cached_hash.<locals>.wrap  sE    ''	<V<%%	 	
	2 $'r3   r.   )rK   r  rH  s   &l r0   r.  r.    s#     * {9r3   c                      ] tR tRtR R ltR R ltR R lt]P                  R R	 l4       t	]
R
 R l4       t]P                  R R l4       tR R ltR R ltR R ltR R ltRR R lltRtR# )r   i7  c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   Source.__annotate__9  s      T r3   c                	    R # Fr.   ra   s   &r0   is_dict_keySource.is_dict_key9      r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   rL  <  s      d r3   c                	    R # rN  r.   ra   s   &r0   is_ephemeralSource.is_ephemeral<  rQ  r3   c                    V ^8  d   QhRRRR/# )r+   codegenr   r,   r  r.   )r/   s   "r0   r1   rL  ?  s     " "9 " "r3   c                	    \         hrk   NotImplementedError)r9   rW  s   &&r0   reconstructSource.reconstruct?  s    !!r3   c                   V ^8  d   QhRR/# r   r.   )r/   s   "r0   r1   rL  C  s     " "k "r3   c                	    \         hrk   rY  ra   s   &r0   r   Source.guard_sourceB  s    !!r3   c                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   rL  G  s     " " "r3   c                    \         h)a  
A template for the name of the source. Used to prevent code duplication between
`name` and `get_value`.

For non-ChainedSources, `name` and `get_value` use the returned string directly.

For ChainedSources, `name` and `get_value` expect the return to be a format string
with `{0}` present - `name` and `get_value` will apply different values to this function's
returned format string.
rY  ra   s   &r0   _name_templateSource._name_templateF  s
     "!r3   c                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   rL  U  s     # #c #r3   c                	    V P                   # rk   )rb  ra   s   &r0   r   Source.nameT  s    """r3   c               (    V ^8  d   QhRRRRRRRR/# r+   globalsr  localscachezdict[Source, Any]r,   r   r.   )r/   s   "r0   r1   rL  X  s2     
 

 
 !	

 

r3   c                	V    W9   d	   W0,          # \        V P                  W4      pWCV &   V# rk   )evalrb  )r9   ri  rj  rk  r   s   &&&& r0   	get_valueSource.get_valueX  s/     =;T((':dr3   c                    V ^8  d   QhRRRR/# )r+   fnzCallable[..., Any]r,   r   r.   )r/   s   "r0   r1   rL  d  s      / E r3   c                	`    V P                   \        P                  J d   \        h\	        W4      # rk   )r   re   r   rZ  r   )r9   rq  s   &&r0   
make_guardSource.make_guardd  s&     4 44%%Tr3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   rL  i  s     < <$ <r3   c                	6    V P                   P                  4       # rk   )r   ry   ra   s   &r0   ry   Source.is_specialized_nn_modulei  s      99;;r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   rL  l  s     @ @4 @r3   c                <    V P                   \        P                  8g  # )z+True if you can guard on attributes of this)r   re   r   ra   s   &r0   subguards_allowedSource.subguards_allowedl  s      K$?$???r3   Nc                    V ^8  d   QhRRRR/# r+   transform_fnz!Callable[[Source], Source] | Noner,   r   r.   )r/   s   "r0   r1   rL  p  s      "C v r3   c                	    Ve	   V! V 4      # V # rk   r.   )r9   r~  s   &&r0   cloneSource.clonep  s     #%%r3   r.   rk   )rS   rT   rU   rV   rO  rT  r[  r   cached_propertyr   r!  rb  r   rn  rs  ry   rz  r  rY   r.   r3   r0   r   r   7  sx    " " " " " # #

<@ r3   r   c                      ] tR tRt$ R]R&   R R ltR R lt]P                  R R	 l4       t	R
 R lt
]P                  R R l4       tR R ltRR R lltRtR# )ChainedSourceiy  r   basec                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   ChainedSource.__annotate__}  s     ' 'T 'r3   c                	6    V P                   P                  4       # rk   )r  rO  ra   s   &r0   rO  ChainedSource.is_dict_key}  s    yy$$&&r3   c                   V ^8  d   QhRR/# rg   r.   )r/   s   "r0   r1   r    s     ( (d (r3   c                	6    V P                   P                  4       # rk   )r  rT  ra   s   &r0   rT  ChainedSource.is_ephemeral  s    yy%%''r3   c                   V ^8  d   QhRR/# r   r.   )r/   s   "r0   r1   r    s     & &k &r3   c                	.    V P                   P                  # rk   )r  r   ra   s   &r0   r   ChainedSource.guard_source  s    yy%%%r3   c                   V ^8  d   QhRR/# )r+   r,   r   r.   )r/   s   "r0   r1   r    s      & r3   c                	R    T p\        V\        4      '       d   VP                  pK$  V# rk   )r   r  r  )r9   currents   & r0   get_baseChainedSource.get_base  s"    -00llGr3   c                   V ^8  d   QhRR/# r*   r.   )r/   s   "r0   r1   r    s     : :c :r3   c                	`    V P                   P                  V P                  P                  4      # rk   )rb  r/   r  r   ra   s   &r0   r   ChainedSource.name  s!    ""))$))..99r3   c               (    V ^8  d   QhRRRRRRRR/# rh  r.   )r/   s   "r0   r1   r    s2        !	
 
r3   c                	    W9   d	   W0,          # R p^ pWB9   d   R V 2pV^,          pK  V P                   P                  WV4      W$&   \        V P                  P	                  V4      W4      pW$ WcV &   V# )tmp)r  rn  rm  rb  r/   )r9   ri  rj  rk  tmpvarcounterr   s   &&&&   r0   rn  ChainedSource.get_value  s{     =;7)_FqLG,,WeDT((//7INdr3   Nc                    V ^8  d   QhRRRR/# r}  r.   )r/   s   "r0   r1   r    s      "C v r3   c                	z   R V P                   P                  V4      /p\        P                  ! V 4       F`  pVP                  R 8X  d   K  \        WP                  4      p\        V\        4      '       g   KC  VP                  V4      W#P                  &   Kb  	  \        P                  ! V 3/ VB pVe	   V! V4      pV# )r  )	r  r  r@  rB  r   r  r   r   replace)r9   r~  cloned_fieldsr@  r  results   &&    r0   r  ChainedSource.clone  s    )/1N(O##D)Avv$'C#v&&(+		,(?ff% * $$T;];#!&)Fr3   r.   rk   )rS   rT   rU   rV   rW   rO  rT  r   r  r   r  r   rn  r  rY   r.   r3   r0   r  r  y  sY    
L'( & & : :& r3   r  c                    V ^8  d   QhRRRR/# )r+   inputsr   r,   r  r.   )r/   s   "r0   r1   r1     s     > >S >,A >r3   c                   ^ RI HpHpHp \        P                  4       ;p'       d   VP                  pVe   V# . p^ RIHp \        \        V! 4       4      4       F,  w  r\        W4      '       g   K  VP                  V	RV34       K.  	  \        P                  ! V 4      p
\        V
4       F  w  r\        W4      '       d   VP                  VP                  RV34       \        V4      '       g   KG  . pV! WR7       V Uu. uF  p\        W4      '       g   K  VNK  	  ppTP!                  \        V4       UUu. uF  w  ppVP                  RV 2V3NK  	  upp4       K  	  V'       dl   V^ ,          w  pppVR,           FO  w  p	ppWYJg   K  \#        R	V R
V RV RV	 R
V RV RV RV RVP$                   RV RV RV	P$                   24      h	  V# R# u upi u uppi )ax  
Attempts to "detect" what the current fake mode is.  If there is one ambiently
available from TracingContext, we preferentially use that.  Otherwise, we
heuristically detect the fake mode via the following sources, in order of
priority:

    - Currently active fake mode on stack
    - Fake mode associated with passed in tensors (inputs does not
      have to be flattened)
)
FakeTensorr   get_plain_tensorsN _get_current_dispatch_mode_stackzactive fake modezfake tensor input)outzsubclass input :r   NNzfake mode (z) from r   z doesn't match mode (z

fake mode from z allocated at:
z
fake mode from )torch._subclasses.fake_tensorr  r   r  r  r  r  torch.utils._python_dispatchr  r  reversedr   r  pytreetree_leavesr   r  r8   r   )r  r  r   r  r"  r  
fake_modesr  r  mflat_inputs
flat_inputr  xfake_tensorsixtensordesc1i1desc2i2s   &                    r0   detect_fake_moder    s     !((**w*%%	 JM(#C#EFGa((q"4a89 H $$V,K";/j--z335H!LM(44;=Cj2.a*Q";3  .  '0&=&=
F %%'<bA&= 0  )!}	5"&rNNLAub!$!)GE7!B4?TUVTWW^_d^eefgifj k&&+WAbT1A)//AR S&&+WAbT1A!''L  + -.s   GG:Gc                   V ^8  d   QhRR/# )r+   r,   r  r.   )r/   s   "r0   r1   r1     s      / r3   c                     ^ RI Hp  ^ RIHp \	        \        V! 4       4      4       F  w  r#\        W04      '       g   K  Vu # 	  R# )zr
Inspects the dispatch mode stack for an active fake mode and returns it.
Returns None if no fake mode is active.
r   r  N)r  r   r  r  r  r  r   )r   r  r`   r  s       r0   active_fake_moder    s:    
 =M(#C#EFGa((H H r3   rk   )g
__future__r   r  r@  enumr   loggingre	threadingr  unittest.mockr	  r   abcr   collectionsr   r   r   typingr   r	   r
   r   r   r   typing_extensionsr   r   torch.utilsr   r  torch.utils._ordered_setr   r  r   torch.utils._tracebackr   r   torch.utils.weakr   	getLoggerrS   r  collections.abcr   r   r   typesr   sympy"torch._dynamo.backends.distributedr   torch._dynamo.codegenr   torch._dynamo.guardsr   &torch._functorch._aot_autograd.schemasr   r  r   r  r   compilerC   rD   r$   r[   Enumre   r   r   r   r   r#  r%  r'  r1  r5  rB  r\  rp  r~  r  r  r  r  r1  r;  rC  r  localr  r  r  r  r  r)  r.  r   r  r  r  r.   r3   r0   <module>r     s   "      	      # % ! M M 1  ) / F B 4 ! ==F/3JR< ZZ PQ 

X " $D17J 7J 27Jt7j 7<
$)) <
~	 	 d#  $   T"u' u' #u'p CL d#	 	 $	 d#	l 	 $	 d#*\ * $*

8WQZ 8( (8( (0+N#?@ +( (0$N#?@ $RC. C.L<N#89 <2 =  =F   2 W W W4G$* G$T
& 
& &#6 #6L ! ! !G GT + + + +8 
 K 
 K 
' 
'
  @ 4(= = )=B 4(6F 6 )6r>Br3   