+
    &jfK                     F  a  Rc tf0 t R 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HtHt ^ RIHtHtHt ^ RI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!H"t"H#t# ^R
I$H%t%H&t&H't'H(t( ^RI)H*t*H+t+H,t, ^RIH-t-H.t.H/t/ ^RI0H1t1H2t2 Rt3] ^ k  ^ RI4t3]!Pl                  t6^t7]Pp                  ! ]94      t:]! R4      t;R R lt<R R lt=R t>R t?R R lt@R R ltA]R R l4       tB]R R l4       tBR R ltBR R  ltCRdR! R" lltDR#^ /R$ R% lltE ! R& R'4      tF ! R( R)4      tG ! R* R+4      tH ! R, R-4      tI ! R. R/4      tJR0 R1 ltKR2 R3 ltLR4 R5 ltMR6 R7 ltNR8 R9 ltOReR: R; lltPR< R= ltQRfR> R? lltR]P                  R@^ 3RA RB lltT]! RC4      tURD RE ltVRF RG ltWRHRRIRJ /RK RL lltXRM RN ltYRO RP ltZRQ RR lt[RS RT lt\RU RV lt]RW RX lt^RY RZ lt_R[ R\ lt`RgR] R^ lltaR_ R` ltbRsc]P                  Ra Rb l4       teR#   ]5 d    Rt3 ELyi ; i)ha1  Testing utilities and infrastructure for Dynamo.

This module provides a comprehensive set of testing utilities including:
- Test result collection and validation
- Graph manipulation and comparison tools
- Test case management and execution helpers
- Specialized test decorators for different Python versions and features
- RNG state management
- Compilation counting and monitoring
- Debug utilities for bytecode transformation

The utilities in this module are used across Dynamo's test suite to ensure
consistent testing patterns and proper test isolation.
N)Callable	GeneratorSequence)AnyoverloadTypeVar)	ParamSpec)patch)fx)	aot_eager)OutputGraph)config
eval_frameoptimize_assertreset)create_instructiondebug_checksis_generatortransform_code_object)CheckFunctionManager	CompileIdGuardedCode)ConvertFrameReturnDynamoFrameTypewrap_guarded_code)CompileCounterIntsame_Pc                t    V ^8  d   QhR\         P                  R,          R\         P                  R,          /# )   xNreturntorchTensor)formats   "m/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/_dynamo/testing.py__annotate__r'   ?   s,     > >t# >t(; >    c                 |    V f   R # V P                  4       P                  4       P                  V P                  4      # N)detachclonerequires_grad_requires_gradr    s   &r&   clone_mer0   ?   s.    y88:,,Q__==r(   c                0    V ^8  d   QhR\         R\         /# )r   namer!   str)r%   s   "r&   r'   r'   E   s     . . . .r(   c                 2    \         P                  ! R RV 4      # )z^_orig_mod[.] resub)r2   s   &r&   remove_optimized_module_prefixr:   E       66"B--r(   c                    aaa ^ RI Ho RoRoVVV3R lp\        P                  ! VRR7      ! V 4      ! V/ VB  SP                  S3# )    )InstructionTranslatorNc                 T   < V oSP                  4       P                  P                  oV # r*   )
current_txoutputregion_tracker)_gmargskwargsr>   gmrB   s   &*,r&   extract_graph_backend8extract_graph_and_tracker.<locals>.extract_graph_backendO   s)     .99;BBQQ
r(   T)backend	fullgraph)torch._dynamo.symbolic_convertr>   r#   compilegraph)fnrD   rE   rG   r>   rF   rB   s   &*, @@@r&   extract_graph_and_trackerrO   I   sD    D	BN 
MM/4@DdUfU88^##r(   c                     \        4       p\        P                  ! VR 7      ! V 4      ! V/ VB pWCP                  VP                  VP
                  3# ))rI   )AotEagerAndRecordGraphsr#   rL   graphs	fw_graphs	bw_graphs)rN   rD   rE   rI   results   &*,  r&   extract_graphrV   Z   sD    %'G]]7+B/@@F>>7#4#4g6G6GGGr(   c                    V ^8  d   QhR\         P                  P                  R\        R\        R\        R\        \        ,          /# )r   model
predictionlossexample_inputsr!   )r#   nnModuler   list)r%   s   "r&   r'   r'   `   s@     % %88??%(+%36%HK%	#Y%r(   c                 R   . pVP                  V4       VP                  V4       / p/ pV P                  4        Fq  w  rx\        V \        P                  4      '       d   \        V4      pTp	VP                  p
VP                  f   \        P                  ! V4      p
WVR,           &   WV&   Ks  	  VP                  V4       VP                  V4       / pV P                  4        F4  w  r|\        V \        P                  4      '       d   \        V4      pWV&   K6  	  VP                  V4       V Fv  p\        V\        \        34      '       d   VP                  R V 4       4       K9  \        V\        P                  4      '       g   K[  VP                  VP                  4       Kx  	  V# )Nz.gradc              3   ~   "   T F3  p\        V\        P                  4      '       g   K%  VP                  x  K5  	  R # 5ir*   )
isinstancer#   r$   grad).0inps   & r&   	<genexpr>"collect_results.<locals>.<genexpr>   s#     Xw*S%,,:W8388ws   "==)appendnamed_parametersra   r   OptimizedModuler:   rb   r#   
zeros_likenamed_bufferstupler^   extendr$   )rX   rY   rZ   r[   resultsgradsparamsr2   param
param_copyrb   buffersbufferexamples   &&&&          r&   collect_resultsrv   `   sU    GNN:NN4 EF--/eZ77881$7D
zz::##E*D $dWn!t 0 NN5NN6G++-eZ77881$7D . NN7!gt}--NNXwXX'5<<00w||, " Nr(   c                0    V ^8  d   QhR\         R\        /# r   outr!   )r   bool)r%   s   "r&   r'   r'      s     	E 	E3 	E4 	Er(   c                 `   \        V \        P                  4      '       d   V P                  # \        V \        \
        34      '       d5   \        ;QJ d    R  V  4       F  '       g   K   R# 	  R# ! R  V  4       4      # V f   R# \        V \        4      '       d   R# \        R\        V 4      4      h)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir*   )requires_bwd_passrc   r    s   & r&   re   $requires_bwd_pass.<locals>.<genexpr>   s     5A$Q''   TFDon't know how to reduce)
ra   r#   r$   r.   r^   rl   anyintNotImplementedErrortypery   s   &r&   r}   r}      s    #u||$$   	C$	'	's55ss5s5s5555		C		
8$s)
DDr(   c                X    V ^8  d   QhR\         P                  R\         P                  /# rx   r"   )r%   s   "r&   r'   r'      s     A Au|| A Ar(   c                     R # r*    r   s   &r&   reduce_to_scalar_lossr      s    >Ar(   c                    V ^8  d   QhR\         \        ,          \        \        R3,          ,          \        \        \        3,          ,          R\        /# )r   ry   .r!   )r^   r   rl   dictfloat)r%   s   "r&   r'   r'      s:      	cU38_	$tCH~	5
r(   c                     R # r*   r   r   s   &r&   r   r      s     r(   c                Z    V ^8  d   QhR\         R\        P                  \        ,          /# rx   )r   r#   r$   r   )r%   s   "r&   r'   r'      s'     E Es Eu||e'; Er(   c                   \        V \        P                  4      '       d&   V P                  4       V P	                  4       ,          # \        V \
        \        34      '       d#   \        R V  4       4      \        V 4      ,          # \        V 4      P                  R9   d   \        V P                  4      # \        V 4      P                  R8X  d   V P                  P                  4       # \        V \        4      '       d?   \        R V P                  4        4       4      \        V P                  4       4      ,          # \!        R\        V 4      4      h)z/Reduce the output of a model to get scalar lossc              3   8   "   T F  p\        V4      x  K  	  R # 5ir*   r   r~   s   & r&   re   (reduce_to_scalar_loss.<locals>.<genexpr>   s     9S(++Sr   SquashedNormalc              3   8   "   T F  p\        V4      x  K  	  R # 5ir*   r   )rc   values   & r&   re   r      s     J\E(//\r   r   )MaskedLMOutputSeq2SeqLMOutput!CausalLMOutputWithCrossAttentions)ra   r#   r$   sumnumelr^   rl   lenr   __name__r   logitsmeanr   valueskeysr   r   s   &r&   r   r      s    #u||$$wwy399;&&	C$	'	'9S99CHDD	c		   

 %SZZ00	c		/	/xx||~	C		JSZZ\JJSHHJN
 
 	
 8$s)
DDr(   c                $    V ^8  d   QhR\         /# r   r!   r3   )r%   s   "r&   r'   r'      s      3 r(   c                      \         P                  P                  \         P                  P                  \        4      R 4      p \         P                  P                  V 4      '       g   \         P                  ! V 4       V # )z../debug)ospathjoindirname__file__existsmkdir)r   s    r&   	debug_dirr      sF    77<<1:>D77>>$
Kr(   c                T    V ^8  d   QhR\         R\        P                  R\         RR/# )r   r2   codeextrar!   N)r4   typesCodeType)r%   s   "r&   r'   r'      s,     
 
S 
 
s 
D 
r(   c           
      p   \        \        P                  P                  \	        4       V 4      R 4      ;_uu_ 4       pVP                  \        P                  ! V4      P                  4        R\        P                  ! V4      P                  4        RV R24       RRR4       R#   + '       g   i     R# ; i)wz


N)	openr   r   r   r   writedisBytecodeinfo)r2   r   r   fds   &&& r&   
debug_dumpr      sz    	bggll9;-s	3	3r
||D!&&()cll4.@.D.D.F-GtE7RTU	
 
4	3	3	3s   AB$$B5	skipc                `    V ^8  d   QhR\         R\        R\        R\        R\        R\        /# )r   frame
cache_sizehooks_r   r!   )r   r   r   r   )r%   s   "r&   r'   r'      s<     %
 %
%
(+%
47%
<?%
JM%
%
r(   c                  R R lp\         P                  P                  P                  4       p\         P                  P                  P	                  R4      ;_uu_ 4        T;_uu_ 4        \        V P                  4      '       d   \        4       uuRRR4       uuRRR4       # \        V P                  4       \        V P                  V4      w  rs\        / RRR. R^ /\        4       \        4       V P                  . RR7      p\        \        V\        V P                  V4      P                   \#        ^ ^ R7      4      4      uuRRR4       uuRRR4       #   + '       g   i     M; iRRR4       R#   + '       g   i     R# ; i)	zused to debug jump updatesc                J    V ^8  d   QhR\         \        ,          R\        RR/# )r   instructionscode_optionsr!   N)r^   r   )r%   s   "r&   r'   'debug_insert_nops.<locals>.__annotate__   s%     : :$s) :3 :4 :r(   c                 r    V P                  ^ \        R4      4       V P                  ^ \        R4      4       R# )r=   NOPN)insertr   )r   r   s   &&r&   insert_nops&debug_insert_nops.<locals>.insert_nops   s.    A1%89A1%89r(   debug_insert_nopsNF_id)r   compiler_fnroot_txexportexport_constraintsframe_statelocal_scopeglobal_scopef_codetorch_function_mode_stackpackage)frame_idframe_compile_id)r#   _dynamoutilsget_metrics_contextdynamo_timedr   r   r   r   r   r   localsglobalsr   r   r   guard_managerr   )	r   r   r   r   r   r   metrics_contextr   rM   s	   &&&&$    r&   r   r      s   
: mm))==?O				)	)*=	>	>%%%' AP	>	> 	U\\"'kB!
 <<&(
 !$U\\59GG1q9
+ AP	>	>	>	>	>	>s1    E4+%E	
E4%BE	
E4E'"E44F	c                   V   a  ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )	CompileCounterc                   < V ^8  d   QhRR/# r   r!   Nr   )r%   __classdict__s   "r&   r'   CompileCounter.__annotate__   s      $ r(   c                4    ^ V n         V P                  4        R# r=   N)frame_countclearselfs   &r&   __init__CompileCounter.__init__   s    45

r(   c                   < V ^8  d   QhRS[ P                  P                  RS[S[ P                  ,          RS[RS[3,          /# r   rF   r[   r!   .r#   r
   GraphModuler^   r$   r   r   )r%   r   s   "r&   r'   r      sA      ((&&8<U\\8J	#s(	r(   c                    V ;P                   ^,          un         VP                  P                   F/  pRVP                  9   g   K  V ;P                  ^,          un        K1  	  VP
                  # )   call)r   rM   nodesopop_countforward)r   rF   r[   nodes   &&& r&   __call__CompileCounter.__call__   sM     	AHHNND " # zzr(   c                   < V ^8  d   QhRR/# r   r   )r%   r   s   "r&   r'   r      s      t r(   c                p    \         P                  '       d   \        ^ 4      V n        M^ V n        ^ V n        R# r   )r   debug_disable_compile_counterr   r   r   r   s   &r&   r   CompileCounter.clear   s*    ///03D Dr(   )r   r   N	r   
__module____qualname____firstlineno__r   r   r   __static_attributes____classdictcell__r   s   @r&   r   r      s#        r(   r   c                   V   a  ] tR tRt o V 3R lR ltV 3R lR ltV 3R lR ltRtV tR	# )
CompileCounterWithBackend   c                $   < V ^8  d   QhRS[ RR/# )r   rI   r!   Nr3   )r%   r   s   "r&   r'   &CompileCounterWithBackend.__annotate__  s        r(   c                N    ^ V n         Wn        . V n        V P                  4        R# r   )r   rI   rR   r   )r   rI   s   &&r&   r   "CompileCounterWithBackend.__init__  s    4524

r(   c                   < V ^8  d   QhRS[ P                  P                  RS[S[ P                  ,          RS[RS[3,          /# r   r   )r%   r   s   "r&   r'   r    sF     
@ 
@((&&
@8<U\\8J
@	#s(	
@r(   c                8   ^RI Hp V ;P                  ^,          un        VP                  P                   F/  pRVP
                  9   g   K  V ;P                  ^,          un        K1  	  V P                  P                  V4       V! V P                  4      ! W4      # )r   )lookup_backendr   )
backends.registryr  r   rM   r   r   r   rR   rg   rI   )r   rF   r[   r  r   s   &&&  r&   r   "CompileCounterWithBackend.__call__  sl     	6AHHNND " # 	2dll+B??r(   c                   < V ^8  d   QhRR/# r   r   )r%   r   s   "r&   r'   r    s      t r(   c                ~    \         P                  '       d   \        ^ 4      V n        M^ V n        ^ V n        . V n        R# r   )r   r   r   r   r   rR   r   s   &r&   r   CompileCounterWithBackend.clear  s1    ///03D Dr(   )rI   r   rR   r   Nr  r  s   @r&   r
  r
     s%      
@ 
@ r(   r
  c                   D   a  ] tR tRt o V 3R lR ltV 3R lR ltRtV tR# )EagerAndRecordGraphsi  c                   < V ^8  d   QhRR/# r   r   )r%   r   s   "r&   r'   !EagerAndRecordGraphs.__annotate__  s     5 5$ 5r(   c                    . V n         R # r*   rR   r   s   &r&   r   EagerAndRecordGraphs.__init__  s	    24r(   c                   < V ^8  d   QhRS[ P                  P                  RS[S[ P                  ,          RS[RS[3,          /# r   r   )r%   r   s   "r&   r'   r  "  sA      ((&&8<U\\8J	#s(	r(   c                P    V P                   P                  V4       VP                  # r*   )rR   rg   r   )r   rF   r[   s   &&&r&   r   EagerAndRecordGraphs.__call__"  s      	2zzr(   r  Nr   r  r  r  r   r   r  r  r  s   @r&   r  r    s     5 5 r(   r  c                   D   a  ] tR tRt o V 3R lR ltV 3R lR ltRtV tR# )rQ   i)  c                   < V ^8  d   QhRR/# r   r   )r%   r   s   "r&   r'   $AotEagerAndRecordGraphs.__annotate__*  s     8 8$ 8r(   c                0    . V n         . V n        . V n        R # r*   )rR   rS   rT   r   s   &r&   r    AotEagerAndRecordGraphs.__init__*  s    245757r(   c                   < V ^8  d   QhRS[ P                  P                  RS[S[ P                  ,          RS[RS[3,          /# r   r   )r%   r   s   "r&   r'   r%  /  sA     
 
((&&
8<U\\8J
	#s(	
r(   c                |   a  S P                   P                  V4       R  V 3R llpR V 3R llp\        VVVVR7      # )c                    V ^8  d   QhR\         P                  P                  R\        \         P                  ,          R\
        R\        3,          /# r   r   )r%   s   "r&   r'   6AotEagerAndRecordGraphs.__call__.<locals>.__annotate__4  @     	 	$$	6:5<<6H	c3h	r(   c                 R   < SP                   P                  V 4       V P                  # r*   )rS   rg   r   rF   r[   r   s   &&r&   fw_compiler5AotEagerAndRecordGraphs.__call__.<locals>.fw_compiler4  !     NN!!"%::r(   c                    V ^8  d   QhR\         P                  P                  R\        \         P                  ,          R\
        R\        3,          /# r   r   )r%   s   "r&   r'   r+  :  r,  r(   c                 R   < SP                   P                  V 4       V P                  # r*   )rT   rg   r   r.  s   &&r&   bw_compiler5AotEagerAndRecordGraphs.__call__.<locals>.bw_compiler:  r1  r(   )r/  r4  )rR   rg   r   )r   rF   r[   r/  r4  s   f&&  r&   r    AotEagerAndRecordGraphs.__call__/  sF     	2	 		 	 ##	
 	
r(   )rT   rS   rR   Nr"  r  s   @r&   rQ   rQ   )  s     8 8

 
r(   rQ   c                   8   a  ] tR tRt o V 3R lR ltR tRtV tR# )InductorAndRecordGraphsiH  c                   < V ^8  d   QhRR/# r   r   )r%   r   s   "r&   r'   $InductorAndRecordGraphs.__annotate__I  s     > >$ >r(   c                "    . V n         . V n        R # r*   rR   inductor_graphsr   s   &r&   r    InductorAndRecordGraphs.__init__I  s    24;=r(   c                  a a ^ RI Hu Hp S P                  P	                  V4       VP
                  oVV 3R lp\        P                  ! VRVR7      ;_uu_ 4        VP                  W4      uuRRR4       #   + '       g   i     R# ; i)r=   Nc                  X   < SP                   P                  V ^ ,          4       S! V / VB # )r=   )r=  rg   )rD   rE   old_compile_fx_innerr   s   *,r&   patched1InductorAndRecordGraphs.__call__.<locals>.patchedT  s+      ''Q0'888r(   _compile_fx_inner)new)torch._inductor.compile_fx	_inductor
compile_fxrR   rg   rD  r	   object)r   rF   r[   compile_fx_modrB  rA  s   f&&  @r&   r    InductorAndRecordGraphs.__call__M  s`    ;;2-??	9 \\.*=7KK!,,R@ LKKKs   A77B	r<  Nr"  r  s   @r&   r8  r8  H  s     > >A Ar(   r8  c                0    V ^8  d   QhR\         R\         /# r   r   r!   r3   )r%   s   "r&   r'   r'   \  s     . . . .r(   c                 2    \         P                  ! R RV 4      # )z(?m)^ *#.*\n?r6   r7   )r   s   &r&   strip_commentrO  \  r;   r(   c                0    V ^8  d   QhR\         R\         /# rM  r3   )r%   s   "r&   r'   r'   `  s     C C C Cr(   c                     R P                  V P                  R 4       Uu. uF  qP                  4       NK  	  up4      # u upi )r   )r   splitrstrip)r   lines   & r&   remove_trailing_spacerU  `  s2    99

40@A0@kkm0@ABBAs   >c                0    V ^8  d   QhR\         R\         /# rM  r3   )r%   s   "r&   r'   r'   d  s      c c r(   c                     V P                  R 4      p. pRpV F8  pVP                  4       R8X  d   V'       d   K"  RpMRpVP                  V4       K:  	  R P                  V4      # )r   Fr6   T)rR  striprg   r   )r   linesrU   	saw_blankrT  s   &    r&   _squash_blank_linesr[  d  s_    JJtEFI::<2IId  99Vr(   c                0    V ^8  d   QhR\         R\         /# )r   gm_strr!   r3   )r%   s   "r&   r'   r'   s  s     , , , ,r(   c                 D    \        V 4      p\        V4      p\        V4      # r*   )rO  rU  r[  )r]  strippedno_trailings   &  r&   normalize_gmra  s  s#     V$H'1K{++r(   c                0    V ^8  d   QhR\         R\         /# rM  r3   )r%   s   "r&   r'   r'   {  s        r(   c                6    \         P                  ! RRV 4      pV# )z%
Normalize code: remove empty lines.
z[\r\n]+r   r7   )r   normal_codes   & r&   empty_line_normalizerre  {  s     &&T40Kr(   c                    V ^8  d   QhR\         R\        R\         3,          R\        R\        R,          R\        R,          R\        R	R/# )
r   r   rN   .nargsexpected_opsNexpected_ops_dynamicexpected_frame_countr!   )r   r   r   )r%   s   "r&   r'   r'     s_     8 8
8c8 8 *	8
 *8 8 
8r(   c                    \         P                  '       g   Ve   Tp\        4       p\        V4       Uu. uF  p\        P
                  ! ^
^
4      NK  	  pp\        V4       Uu. uF  p\        P
                  ! ^
^
4      NK  	  p	pV! V!  p
V! V	!  p\        4        \        V4      ! V4      pV! V!  pV! V	!  pV! V!  pV! V	!  p\        4        V P                  \        W4      4       V P                  \        W4      4       V P                  \        W4      4       V P                  \        VV4      4       V P                  VP                  V4       Ve   V P                  VP                  V4       R # R # u upi u upi r*   )r   assume_static_by_defaultr   ranger#   randnr   r   
assertTruer   assertEqualr   r   )r   rN   rg  rh  ri  rj  actualr   args1args2correct1correct2opt_fnval1aval2aval1bval2bs   &&&&&&           r&   standard_testr{    s<    ***/C/O+F*/,7,QU[[R ,E7*/,7,QU[[R ,E75zH5zH	GV$R(FENEENEENEENE	GOOD)*OOD)*OOD)*OOD)*V'')=>,7  ! 87s    E7# E<c                    V ^8  d   QhR\         P                  R\        \        P                  ,          R\
        R\        3,          /# r   )r
   r   r^   r#   r$   r   r   )r%   s   "r&   r'   r'     s:      
(,U\\(:c3hr(   c                     V P                   # r*   )r   )rF   r[   s   &&r&   dummy_fx_compiler~    s     ::r(   c          
      T    V ^8  d   QhR\         R\         R\        R\         R\        /# )r   speeduppvalue
is_correctpvalue_thresholdr!   )r   rz   r4   )r%   s   "r&   r'   r'     s:     
, 
,
,
, 
, 	
,
 	
,r(   c                 @    V'       g   R # W8  d   V R R2# V R RVR 2# )ERRORz.3fzx SAMEzx p=z.2fr   )r  r  r  r  s   &&&&r&   format_speedupr    s4      #f%%c]$vcl++r(   cpuc                    V ^8  d   QhR\         \        ,          R\         \        ,          R\        P                  R\        \        P
                  ,          R\        R\        P                  /# )r   sizestridedtypedevice
extra_sizer!   )r   r   r#   r  r4   r  r$   )r%   s   "r&   r'   r'     s]     2 2
3-2SM2 ;;2 %,,	2
 2 \\2r(   c                    Tp\         ;QJ d    R  V  4       F  '       d   K   RM	  RM! R  V  4       4      '       d*   V\        R \        W4       4       4      ^,           ,          pVP                  '       d   V\        P
                  8X  dI   \        P                  ! ^ RV3\        P                  VR7      P                  \        P
                  4      pM|VP                  ^8X  d:    \        P                  ! V\        P                  VR7      P                  VR7      pM2\        P                  ! WRVR7      pM\        P                  ! V.W#R7      p\        P                  ! W`V4      # )c              3   *   "   T F	  q^ 8  x  K  	  R# 5ir   r   )rc   ss   & r&   re   rand_strided.<locals>.<genexpr>  s     
$Qq5$s   FTc              3   F   "   T F  w  rV^,
          V,          x  K  	  R# 5i)r   Nr   )rc   shaper  s   &  r&   re   r    s      L:Kf$$:Ks   !r  )r  r  )r  )r  r  r  )allr   zipis_floating_pointr#   float4_e2m1fn_x2randintuint8viewitemsizern  float16tozeros
as_strided)r  r  r  r  r  needed_sizert   s   &&&&&  r&   rand_stridedr    s    K
s
$
sss
$
L#d:KLLqP	
 E***]]3ekk&d5))*  ^^q  [[EMM&QTT U F [[&IF;-uLF&11r(   _Tc                $    V ^8  d   QhR\         /# r   rz   )r%   s   "r&   r'   r'     s     / /T /r(   c                  ,    \         P                  '       * # r*   )r   rl  r   r(   r&   check_dynamic_shape_capturer    s    ....r(   c                    V ^8  d   QhR\         \        \        3,          R\        R\         \        \        3,          /# )r   rN   patchesr!   )r   r   r  r   )r%   s   "r&   r'   r'     s3     	 	hr2v. 	# 	(2r6BR 	r(   c                 P   a a \         P                  ! S 4      R  V V3R ll4       pV# )c                d    V ^8  d   QhR\         P                  R\         P                  R\        /# )r   rD   rE   r!   )r   rD   rE   r  )r%   s   "r&   r'   +_make_fn_with_patches.<locals>.__annotate__  s)     ' '277 'bii 'B 'r(   c            
         < \         P                  ! 4       ;_uu_ 4       pS F,  w  r4pVP                  \        P                  ! W4V4      4       K.  	  S! V / VB uuR R R 4       #   + '       g   i     R # ; ir*   )
contextlib	ExitStackenter_contextr	   rI  )rD   rE   stackmoduleattrvalrN   r  s   *,    r&   _fn"_make_fn_with_patches.<locals>._fn  sZ    !!##u%,!c##ELLs$CD &- t&v&	 $###s   :A$$A5	)	functoolswraps)rN   r  r  s   fj r&   _make_fn_with_patchesr    s*    __R' ' ' Jr(   
xfail_prop	decoratorc                     V # r*   r   r/   s   &r&   <lambda>r    s    ar(   c                    V ^8  d   QhR\         R\        R\        R\        R\        R,          R\        \        R\        3,          .\        R\        3,          3,          R	\         /# )
r   cls
cls_prefix	fn_suffixr  r  Nr  .r!   )r   r4   r   r   )r%   s   "r&   r'   r'     sq      	  	
 d
 #s(+,hsCx.@@A 
r(   c          	      *   \        V V P                   2V P                  / 4      pVP                  Vn        \	        V 4       F  pVP                  R 4      '       d   \        W4      p\        V4      '       g   \        Wg\        W4      4       KM  V V 2p	\        V.VO5!  p
Wn        Ve(   \        W4      '       d   \        P                  ! V
4      p
\        WiV! V
4      4       K  \        Wg4      '       d   K  \        Wg\        W4      4       K  	  V# )test_)r   r   	__bases__r  dir
startswithgetattrcallablesetattrr  hasattrunittestexpectedFailure)r  r  r  r  r  r  DummyTestClassr2   rN   new_namenew_fns   &&&$$*     r&   make_test_cls_with_patchesr    s     ZL7KN"0"9"9NC??7###BB<<gc.@A	{+H*288F&O%'"*A*A!11&9Ni.?@..N'#*<=   r(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r   rN   r!   r   r   r  )r%   s   "r&   r'   r'     s,      xB' HRV,< r(   c                 \    \         P                  R8  d   V # \        P                  ! V 4      # )   )r     sysversion_infor  r   rN   s   &r&   skipIfNotPy311r    s$    
7"	==r(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r  r  )r%   s   "r&   r'   r'     s,     6 6xB' 6HRV,< 6r(   c                 h    \         P                  R8  d   V # \        P                  ! R4      ! V 4      # )r  zRequires Python 3.12+r     r  r  s   &r&   skipIfNotPy312r    s*    
7"	==01"55r(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r  r  )r%   s   "r&   r'   r'     s,      8BF+ R0@ r(   c                     \         P                  R8  g   \         P                  R8  d   \        P                  ! R4      ! V 4      # V # )r  zRequires Python 3.12)r     r  r  r  s   &r&   skipIfOnlyNotPy312r    s7    
7"c&6&6&@}}34R88Ir(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r  r  )r%   s   "r&   r'   r'     s,      Xb"f% (2r6*: r(   c                 \    \         P                  R8  d   \        P                  ! V 4      # V # )r  r  )r  r  r  r  r  s   &r&   xfailIfPy312r    s&    
7"''++Ir(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r  r  )r%   s   "r&   r'   r'   $  s,      HRV$ "b&)9 r(   c                 h    \         P                  R8  d   \        P                  ! R4      ! V 4      # V # )r  zNot supported in Python 3.12+r  r  r  s   &r&   skipIfPy312r  $  s*    
7"}}<=bAAIr(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r  r  )r%   s   "r&   r'   r'   ,  s,      xB/ HRV4D r(   c                     R V n         V # T)_expected_failure_dynamicr  s   &r&   expectedFailureDynamicr  ,  s    #'B Ir(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r  r  )r%   s   "r&   r'   r'   2  ,      hr2v&6 8BF;K r(   c                     R V n         V # r  )!_expected_failure_codegen_dynamicr  s   &r&   expectedFailureCodegenDynamicr  2      +/B(Ir(   c                t    V ^8  d   QhR\         \        \        3,          R\         \        \        3,          /# r  r  )r%   s   "r&   r'   r'   8  r  r(   c                     R V n         V # r  )!_expected_failure_dynamic_wrapperr  s   &r&   expectedFailureDynamicWrapperr  8  r  r(   c                (    V ^8  d   QhR\         RR/# )r   use_xlar!   Nr  )r%   s   "r&   r'   r'   =  s     5 5T 5d 5r(   c                 ,   \         P                  ! R 4       \        P                  ! R 4       \        '       d    \        P                  P                  R 4       V '       d5   ^ RIHu Hp VP                  R \        VP                  4       4      4       R# R# )i9  N)r#   manual_seedrandomseednptorch_xla.core.xla_modelcore	xla_modelset_rng_stater4   
xla_device)r  xms   & r&   reset_rng_stater  =  sZ    	d
KK	r
		t--
s2==?34 r(   c                    V ^8  d   QhR\         \        \        3,          R\        P                  R\        P                  R\        /# )r   frD   rE   r!   )r   r   r  rD   rE   )r%   s   "r&   r'   r'   H  s=      B "3599r(   c                     V ! V/ VB # r*   r   )r  rD   rE   s   &*,r&   &_skipped_function_for_test_reconstructr
  H  s     dfr(   c                x    V ^8  d   QhR\         \        \        P                  P                  ,          ,          /# r   )r   r^   r#   r
   r   )r%   s   "r&   r'   r'   R  s.     F Fy		@ Fr(   c               #  6   "   . s  \         x  Rs R#   Rs i ; i5i)a@  
Context manager to capture graph modules compiled by invoke_subgraph_inductor_compile.

Usage:
    with _testing_capture_invoke_subgraph_inductor_compile_gms() as captured_gms:
        # code that triggers invoke_subgraph_inductor_compile
        pass
    # captured_gms will contain the list of captured graph modules
N)6_testing_invoke_subgraph_inductor_compile_captured_gmsr   r(   r&   5_testing_capture_invoke_subgraph_inductor_compile_gmsr  Q  s&      >@:FDDAE>>s    c                b    V ^8  d   Qh/ ^ \         9   d   \        P                  R,          ;R&   # )r   Nr  )__conditional_annotations__r   
ModuleType)r%   s   "r&   r'   r'      s+      ^ # "Et "_r(   )r6   )NNr   )Tg?)F)gr  __doc__r  r   r  loggingos.pathr   r  r8   r  r   r  collections.abcr   r   r   typingr   r   r   typing_extensionsr   unittest.mockr	   r#   r
    torch._dynamo.backends.debuggingr   torch._dynamo.output_graphr   r6   r   r   r   r   bytecode_transformationr   r   r   r   guardsr   r   r   r   r   r   r   r   r   r  numpyModuleNotFoundErrorunsupportedthree	getLoggerr   logr   r0   r:   rO   rV   rv   r}   r   r   r   r   r   r
  r  rQ   r8  rO  rU  r[  ra  re  r{  r~  r  float32r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  contextmanagerr  r'   )r  s   @r&   <module>r%     s    
     	 
   9 9 ) ) '    6 2 8 8  A @ I I * # "
 $$	!t_>.$"H%P	E 
 A 
 A 
 

E,
%
PQ%
P , < 
 
>A A(.C,8B
,  !&2B T]/
	
 " EP>6
5 :> 6 F F  	Bs   "H 	H H 