
    sgn                        U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ d dlmZ d dlmZmZmZmZ d dlZd dlmZ d dlmZ d dlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z, d dl-m.Z. d dl/m0Z0m1Z1 d d	l2m3Z3 d
dl4m5Z5  ejl                  e7      Z8 ed      Z9e9ju                         Z;de<fdZ=ddddZ>ddddddddZ?dddZ@de<fdZA	 	 	 	 	 d*de<fdZBd+dZC	 d+ddddZD ej                  ed      ZFd ZGeC ej                  eDdd      eDdZHee<eej                  egeJf   f   eKd <   d! ZLd" ZMd# ZNd$ ZOd% ZPdd&ddddd'd(eeJe<f   fd)ZQy),    N)import_module)TemporaryFile)AnyCallableDictUnion)_cuda_system_info_commentAccuracyErrorbackend_accuracy_failsBuckTargetWritercast_to_fp64extra_importsgenerate_config_stringhelper_for_dump_minifyInputReaderInputWriterMAX_CONSTANT_NUMEL_INLINEminifier_dirNNModuleToStringNopInputReadersame_two_models)clone_inputscounterssame)make_fx)fx_placeholder_targetshas_free_symbols)tqdm   )configztorch._inductor.configcompiler_namec                 F     t        j                          fd       }|S )a]  
    Minifier for Fx Graph modules after Aot Autograd has finished. We wrap both
    forward and backward call separately with the backend compiler_fn - like
    inductor or nvfuser. Intercepting after Aot Autograd presents neat
    abstraction, where all the params are lifted as graph inputs, making it easy
    to save the graph as a string.
    c                    	
 ddl m t        j                  fi |}ddlm}  |       	t        j                   j                        t        j                  dv sJ 	  |       

fd	} 	
fd
t        j                  dk(  r|}d|_        |S 
S # t        $ r}t        j                  dk(  r~t        j                  dk(  r"t        t        j                                n4t        j                  dk(  r!t!        t        j                                t"        j%                  d        d }~ww xY w)Nr   )FakeTensorMode)get_aot_graph_name)dynamoaotNr'      r   CompilerErrorc                     t         j                  dk7  r |       S t        j                  d       5   |       cd d d        S # 1 sw Y   y xY w)Nr'   )repro_after)r    r+   patch)real_inputsinner_compiled_fninner_debug_fns    P/var/www/html/venv/lib/python3.12/site-packages/torch/_dynamo/repro/after_aot.pydeferred_for_real_inputszLwrap_compiler_debug.<locals>.debug_wrapper.<locals>.deferred_for_real_inputsk   sG     !!U*(55$/ 3%k23 3 3s   AAc                            }| D cg c]/  }t        |t        j                        r|j                  |      n|1 }}t        j
                  dk(  r!t        t        j                        | 	       t        j
                  dk(  r	dk7  rt        d      t        | dt        j                         }|rit        j                  d       t        t        j                        | 	 d       t        t        j                        | 	 d       t        d	       |       S 	  |       }
D ]J  }t        |t        j                        s|j                   s+t        j"                  j%                           |S  |S c c}w # t&        $ ro}t        j
                  d
k(  r"t        t        j                        |	        t        j
                  dk(  r!t        t        j                        |	        d}~ww xY w)ai  
            Aot Autograd fw_compiler and bw_compiler can have fake tensors. So,
            example_inputs can be fake tensors. We can call compiler_fn (which is
            inductor or nvfuser) with fake tensors but the actually compiled_fn
            should be called with real tensors. Therefore, the actual invocation
            is deferred.
                  inductorz4Accuracy minification is supported for inductor onlyTonly_fwdignore_non_fpz-Accuracy failed for the AOT Autograd graph %s	_accuracyBad accuracy detectedr(   r   N)
isinstancetorchTensorfrom_tensorr    repro_leveldump_to_minifyfxGraphModuleNotImplementedErrorr   repro_ignore_non_fplogwarningdump_compiler_graph_stater
   is_cudacudasynchronize	Exception)r-   	fake_modexcopy_tensor_attrsfailedoutarger$   r!   example_inputsgm
graph_namer.   
orig_graphs           r0   r/   zBwrap_compiler_debug.<locals>.debug_wrapper.<locals>.inner_debug_fnt   s    '(I %! -7q%,,,G	%%a(QN! ! !!Q&NN2z2K !!Q& J.-N  -%!"("<"<  KKG .r:6#(/3
 #r:6#(/3
 ((?@@ -[99+K8C- "%c5<<8S[[!JJ224!J	" Je!f ! ))Q.1NN2z:-)   ++q0&NN2z:-)
 s0   4F-'F F " F F 	HA*G>>HT)torch._subclassesr$   	functoolspartialtorch._functorch.aot_autogradr%   copydeepcopygraphr    r+   rK   r?   rG   rA   rB   r@   rE   error_boxed_call)rT   rS   kwargscompiler_fnr%   rR   r1   compiled_fnr$   rU   r.   r/   rV   r!   unconfigured_compiler_fns   ``      @@@@@r0   debug_wrapperz*wrap_compiler_debug.<locals>.debug_wrapperD   s)   4''(@KFKD')
 ]]288,
!!%<<<<	 !,B ?,	3L	 L	\ &2K&*K#$$c  	 !!U*%%*-r:6&%
 ''1,"r:6&%
 		/*#	s   &	B   	E )BD;;E )rX   wraps)rc   r!   rd   s   `` r0   wrap_compiler_debugrf   ;   s,     __-.B% /B%H     Fstable_outputsave_dirc                Z   t        j                  dt        |       dt         d      }|s|dt        j
                  j                   dz  }t        t        j
                  d      r!|dt        j
                  j                   dz  }t        t        j
                  d	      r!|d
t        j
                  j                   dz  }|t               z  }|t        j                  |       z  }d }t        |      }t        t        |       |      D ]r  \  }}t!        |t"        t        j$                  f      r|j'                  ||       9t!        |t        j(                        r|j+                  ||       ft-        d|        |dj/                  |j1                               dz   z  }|dz  }|S )Nz
import torch
from torch import tensor, device
import torch.fx as fx
from torch._dynamo.testing import rand_strided
from math import inf
import torch._inductor.inductor_prims

)ri   z!

isolate_fails_code_str = None

z


        z# torch version: 
rI   z# torch cuda version: git_versionz# torch git version: z


c                 &    t        d | D              S )Nc              3      K   | ]6  }t        |t        j                        r|j                  j                  n| 8 y wN)r;   r<   SymIntnodehint).0is     r0   	<genexpr>zIgenerate_compiler_repro_string.<locals>.hint_if_symint.<locals>.<genexpr>   s*     R1Jq%,,$?QVV[[QFRs   <>)tuple)rM   s    r0   hint_if_symintz6generate_compiler_repro_string.<locals>.hint_if_symint   s    RPQRRRrg   z,arg is neither SymInt/int nor torch.Tensor, zmod = Repro()
)textwrapdedentr   r   r<   version__version__hasattrrI   rm   r	   r   convertr   zipr   r;   intrq   symintr=   tensor	TypeErrorjoinlines)	rT   argsri   rj   	model_strrx   writerplaceholderrQ   s	            r0   generate_compiler_repro_stringr      s    m4 5 6  		I" ()B)B(C2FF	5==&)1%--2D2D1ERHHI5==-001J1J0K6RRI.00	!))"--IS "F 6r :DA RScC./MM+s+U\\*MM+s+J3%PQQR 6<<>*T11I""Irg   run)ri   rj   commandaccuracytracing_mode	check_strc                b   t        d |D              r| j                  d       y | j                  t        ||||             |d|v }|d}t        d |D              rd}| j                  d       | j                  d	       | j                  d
|d|d|d|d|	d|d|d|d|	d       y )Nc              3      K   | ]<  }t        |t        j                  j                  j                  j
                         > y wrp   )r;   r<   rA   experimental_backward_stateBackwardState)rt   rQ   s     r0   rv   z#save_graph_repro.<locals>.<genexpr>  s5       	3--==KKLs   AAzGRepro is not generated due to existence of BackwardState in graph inputrh   r9   realc              3   2   K   | ]  }t        |        y wrp   )r   )rt   as     r0   rv   z#save_graph_repro.<locals>.<genexpr>"  s     1q"1s   symboliczif __name__ == '__main__':
z8    from torch._dynamo.repro.after_aot import run_repro
zE    with torch.no_grad():
        run_repro(mod, load_args, accuracy=z
, command=z, save_dir=z, tracing_mode=z, check_str=z_)
        # To run it separately, do 
        # mod, args = run_repro(mod, load_args, accuracy=z, command='get_args', save_dir=z)
        # mod(*args))anywriter   )
fdrT   r   r!   ri   rj   r   r   r   r   s
             r0   save_graph_repror     s        	U	
 	HH&'		
 -/1D11%LHH+,HHHIHH66>\G; W<|.>l9- XDDL< P<|.>l9- X	 rg   )r   c          	      X   t         j                  j                  t               d      }t         j                  j	                  |      st        j
                  |d       t         j                  j                  |t        | j                  j                         d      }t        j                  dt        | j                  j                        |       t        |d      5 }t        || ||||       d d d        t        j                         }t         j                  j                  |d      }	 t        j                  ||       t        j                  d	|       t         rt#        |      j%                          y y # 1 sw Y   xY w# t&        $ r t        j                  d
|       Y y w xY w)NcheckpointsTexist_ok.pyz&Writing checkpoint with %s nodes to %sw)rj   r   zrepro.pyz(Copying repro file for convenience to %szNo write permissions for %s)ospathr   r   existsmakedirslenr]   nodesrE   rF   openr   getcwdshutilcopyfileuse_buckr   r   OSError)	rT   r   r!   r   subdir	file_namer   curdir
repro_paths	            r0   rG   rG   1  s2   WW\\,.-8F77>>&!
FT*VBHHNN(;'<C%@AIKK0#bhhnn2Ey 
i	 
D-&8	

 YY[Ffj1J?	:.>
KY'--/ 
 
  ?1:>?s   E;.AF ;FF)(F)c                 :   t        j                         }t        j                  j	                  t               d      }t        j                  j                  |      st        j                  |d       t        || |||d       t        |j                               S )Nr   Tr   minify)rj   r   )ioStringIOr   r   r   r   r   r   r   r   getvalue)rT   r   r!   rP   r   s        r0   r@   r@   M  sd    
++-CWW\\,.-8F77>>&!
FT*S"dMFHU!#,,.11rg   c                 n   |i }t         j                  j                  t        j                         d      }t         j                  j	                  |      st        j
                  |d       t         j                  j                  |t        t        j                               d d  d      }	t        |	d      5 }
t        |
| |||d|||	       d d d        t         j                  j                         }i ||}t               t               }}t        rt        |	      j!                  d	
      }nd|	g}t#        j$                  |||||      }|j'                          |j)                  d       |j)                  d       t+        t-        j.                  |j1                         j3                  d      d      t4        j6                         t+        t-        j.                  |j1                         j3                  d      d      t4        j8                         |j:                  dk7  S # 1 sw Y   ]xY w)NisolateTr      r   r   minifier-query)rj   r   r   r   r   F)	print_msgpython)cwdstdoutstderrenvr   zutf-8z>>  )prefix)file)r   r   r   r   r   r   struuiduuid4r   r   environr[   r   r   r   r   
subprocessPopenwaitseekprintry   indentreaddecodesysr   r   
returncode)fx_gr   r!   r   rj   r   r   r   r   r   r   new_envr   r   cmdps                   r0   isolate_failsr   W  s    {WW\\"))+y1F77>>&!
FT*VDJJL(9"1(='>c%BCI	i	 
$%
	

 jjooG  C G"_moFFy)//%/@#	A FFH
KKN
KKN	,,W5fECJJ 
,,W5fECJJ <<1S
 
s   :H**H4c                   	 d	|D ]-  }t        |t        j                        s|j                  s+d	 n 	fd}ddlm} 	  | | }t        |t        t        f      sJ t        d |D              rJ 	  |        	  || |      } ||        |        y# t        $ r Y yw xY w# t        $ r2}||t        |      vrY d }~yt        t        |             Y d }~yd }~ww xY w)NFTc                  H     rt         j                  j                          y y rp   )r<   rI   rJ   )has_cudas   r0   synczinductor_fails.<locals>.sync  s    JJ""$ rg   r   compile_fx_innerc              3   H   K   | ]  }t        |t        t        f        y wrp   )r;   rw   list)rt   rM   s     r0   rv   z!inductor_fails.<locals>.<genexpr>  s     Dz!eT]3Ds    ")r;   r<   r=   rH   torch._inductor.compile_fxr   rw   r   r   rK   reprr   )
r   r   r   rQ   r   r   resultcompile_modrR   r   s
            @r0   inductor_failsr     s    H c5<<(S[[H
%
 <t&5$-000DVDDDDD 	F&tT2D      Yd1g%=d1g	s0   1B <B$ 	B! B!$	C-CCCrequire_fp64r8   c                .    ddl m} t        | ||||      S )Nr   r   r   )r   r   backend_aot_accuracy_fails)r   r   r   r   r8   r   s         r0   inductor_accuracy_failsr     s#     <%!# rg   T)r7   c                    t        |j                               rJ |j                         D ]3  \  }}|j                         t        kD  st
        j                  d|       5 t        |d      st
        j                  d       n/|j                  dkD  r t
        j                  d|j                         t               } ||       t        d|j                        5 }t        | j                  |      } ||       |j                  }d d d         t        || j                   	       }d
t"        j$                  j&                  _        ||fS # 1 sw Y   FxY w)NzConstant %s was not serialized, generated random data instead. If you think this is affecting you, please comment on https://github.com/pytorch/pytorch/issues/100468_versionzzload_args does not have a _version attribute, please file a bug to PyTorch and describe how you generate this repro scriptr   zload_args is version %s, but this version of PyTorch only supports version 0.  We will try to run it anyway but there may be an incompatibility; if so, try upgrading your version of PyTorch.zLoading inputsdesctotal)rj   pbar)r   T)r   named_parametersnamed_buffersnumelr   rE   rF   r}   r   r   r   r   r   rj   r   r   r   r<   	_inductorr    generate_intermediate_hooks)	optionsmod	load_argsnb
nop_readerr   input_readerr   s	            r0   repro_commonr     s;   3'')***!!# 177900KKC 	 9j)>	

 !KK@ ""	  !Jj	#:+;+;	< !"G,<,<4H,  ! :'#G$8$8
94
@C9=EOO69! !s   ,EE) r   strict_accuracyACCURACY_FAILSc                     t        | ||      \  }}t        j                  t        | j                     | j
                        } |||      rt        j                  d       y t        j                  d       y )Nr   r(   r   )r   rX   rY   r   r   r   r   exit)r   r   r   r   fail_fns        r0   repro_minifier_queryr  	  s\    Wc95ICw''(G4E4EG sDrg   c                 j   ddl m} t        | ||      \  }}| j                  dk7  rdnd}t        j
                  j                         dk\  rdnd}dt        |      i}| j                  r>t        j                  t        ||| j                  | j                  | j                  	      }nt        | j                     } |||t        j                  || j                  
      t        j                  t         |      | j                  | j"                  | j$                  | j&                  | j(                  	       y )Nr   )minifierr   inductor_accuracyr5   r   r(   CUDA_VISIBLE_DEVICES)r   r!   rj   r   r   r   )r!   )module_fails
dump_staterj   offload_to_diskskip_offloadskip_sanitymax_granularity)functorch.compiler  r   r   r<   rI   device_countr   r   rX   rY   r   rj   r   r   r   rG   r
  skip_saving_eager_intermediatesr  r  )	r   r   r   r  r   r!   favored_deviceenv_variablesr  s	            r0   repro_minifyr    s   *Wc95IC+2+;+;r+A'zM**113q8QaN+S-@AM  (('%%%% --
 &g&6&67&&|w?P?PQ$$%]
 !!//<<''//rg   c                 R    ddl m} ddlm} t	         ||      \  }}t        d      5   |||      }d d d        t        d   d   }t                fd}t        j                  j                  j                   j                   j                  	      t        j                  j                  j                   j                        t        |      }	 ||      5  t        d
|      5  |	       |	rJ 	 d d d        d d d        d fd}
 j                   s?t        |      }	 ||
      5  t        d|      5  |	       |	rJ 	 d d d        d d d         G fddt"        j$                        } j&                  s]t)        t+        j,                  |      t        |            \  }}	t        d|      5  ||d      j/                  |	       d d d        |	rJ  G fddt"        j$                        } j                   s]t)        t+        j,                  |      t        |            \  }}	t        d|      5  ||      j/                  |	       |	rJ 	 d d d         G fddt"        j$                        }t        d|      5  ||      j/                  |       d d d        |rJ y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   &xY w# 1 sw Y   xY w# 1 sw Y   hxY w)Nr   r   )intermediate_hook	Compiling)r   r5   intermediate_hooksc                     j                  |        j                  s0j                  t        j                  j                  d|       |       j                  d       y )Nr5   r(   )add"skip_saving_inductor_intermediateswrite_tensorr   r   r   update)namevalknown_namesr   r   r   s     r0   	save_hookz repro_analyze.<locals>.save_hookK  sB    99Z >DArg   )stable_hashzSaving inductor intermediatesr   c                     t        t        |             D cg c]  }| |   ||   k7  s| }}|D cg c]  }| |   ||   f }}|sy dj                  d |D              S c c}w c c}w )Nz and c              3   0   K   | ]  \  }}| d |   yw)z != N )rt   r   r   s      r0   rv   z8repro_analyze.<locals>.compare_tuples.<locals>.<genexpr>d  s     F$!Q1#T!Fs   )ranger   r   )tuple1tuple2ru   diff_indicesdiff_valuess        r0   compare_tuplesz%repro_analyze.<locals>.compare_tuples]  sq    #(V#5PafQi9OPP7CD!q	6!9-DD<<F+FFF QDs   A A A%c                     j                  |      }j                  t        j                  j	                  d|             } ||      }|j                  d|  d| d       j                  d       y )Nr5   zNONDETERMINISTIC INDUCTOR at  ()r(   )compute_tensor_metadataread_tensor_metadatar   r   r   r   r  )	r  r  metameta2reasonr*  r   readerr   s	        r0   
check_hookz!repro_analyze.<locals>.check_hookf  sk    --c2++BGGLLT,JKe,JJ6tfBvhaHIArg   zChecking inductor determinismc                   2     e Zd Zd fdZ fdZ xZS )#repro_analyze.<locals>.WriterInterpc                 2    t         |   |       || _        y rp   )super__init__r   )selfr   r   	__class__s      r0   r9  z,repro_analyze.<locals>.WriterInterp.__init__w  s    GS! DKrg   c                     t         |   |      }|j                  }|v rKj                  d       j	                  t
        j                  j                  | j                  |      |       |S )Nr(   )	r8  run_noder  r  r  r   r   r   r   )r:  r   rr  r;  r  r   r   s       r0   r=  z,repro_analyze.<locals>.WriterInterp.run_node{  sV     #A66D{"A##BGGLLd$CQGHrg   )returnN)__name__
__module____qualname__r9  r=  __classcell__)r;  r  r   r   s   @r0   WriterInterpr6  v  s    	!	 	rg   rD  zSaving float64 intermediatesfloat64c                   *     e Zd Z fdZ xZS )(repro_analyze.<locals>.ExactReaderInterpc                 .   t         |   |      }|j                  }|	v rtj                  |      }j	                  t
        j                  j                  d|            } ||      }|
j                  d| d| d       
j                  d       |S )NrE  zNONDETERMINISTIC FLOAT64 at r,  r-  r(   )
r8  r=  r  r.  r/  r   r   r   r   r  )r:  r   r>  r  r0  r1  r2  r;  r*  r  r   r3  r   s          r0   r=  z1repro_analyze.<locals>.ExactReaderInterp.run_node  s     #A66D{"55a833BGGLLD4QR'e4%JJ!=dV2fXQOPAHrg   r@  rA  rB  r=  rC  )r;  r*  r  r   r3  r   s   @r0   ExactReaderInterprG    s    
	 
	rg   rJ  zChecking float64 determinismc                   &     e Zd Z fdZ xZS )#repro_analyze.<locals>.ReaderInterpc                    t         |   |      }|j                  	v rj                  t        j
                  j                  d            }j                  t        j
                  j                  d            }d
fd}t        |||t        j                  j                  j                  d|      ssJ 
j                  d       |S )Nr5   rE  Fc                 >    dj                  d d| |z          y )NTzDIVERGED at z: )r   )msgr   loggedr  r   s     r0   	log_errorz?repro_analyze.<locals>.ReaderInterp.run_node.<locals>.log_error  s%    !FJJdV2cDj\BCrg   T)tol	equal_nanrQ  r(   )r8  r=  r  read_tensorr   r   r   r   r<   _dynamor    repro_tolerancer  )r:  r   r>  r5   rE  rQ  rP  r  r;  r  r   r3  s         @@r0   r=  z,repro_analyze.<locals>.ReaderInterp.run_node  s     #A66D{"!--bggll:t.LM ,,RWW\\)T-JKD
 ,,<<"' "M6AHrg   rI  )r;  r  r   r3  s   @r0   ReaderInterprL    s    	 	rg   rW  zChecking divergence)r   r   torch._inductor.hooksr  r   r   r   setr<   utils_content_storeContentStoreWriterrj   r!  ContentStoreReaderr   skip_check_deterministicrA   Interpreter!skip_saving_float64_intermediatesr   r[   r\   	boxed_run)r   r   r   r   r  r   compiledr   r   new_argsr4  rD  new_modrJ  rW  r*  r  r   r3  r   s   `              @@@@@r0   repro_analyzere  9  s   ;7Wc95IC 
;	 /#C./Z !56E%K [[''::g&9&9 ; F [[''::7;K;KLFD!H	9	% t,E( 	|8	 G ++%z* 	 D0-
 	 X<x		  	  r~~  44(s);\$=OP5UC 	At),66x@	A| BNN  ++(s);\$=OP5UC 	 tg&00:<x	  r~~ 4 
(	6 *$S##D)*O8ts/ /$   2	  	  	  	 .	A 	A*	  	 @* *sw   
K$K2K K:K7K*K7LLLKK	KK'*K4	/K77LLLL&c                 *    t        | ||      \  }}||fS rp   )r   )r   r   r   r   s       r0   repro_get_argsrg    s    Wc95IC9rg   c                 h  	 ddl m} t        | ||      \  }ddlm}  ||      	| j
                  dk7  r)t        |	dt        j                        sYt        d      d}D ]-  }t        |t        j                        s|j                  s+d} n  	t                    }|r |        	fd	S )
Nr   r   )rJ   r   Tr6   r:   Fc                  &     t                     S rp   )r   )r   rb  s   r0   <lambda>zrepro_run.<locals>.<lambda>  s    8DJ' rg   )r   r   r   
torch.cudarJ   r   r   r    rD   r
   r;   r<   r=   rH   r   )
r   r   r   r   rJ   	need_syncrQ   refr   rb  s
           @@r0   	repro_runrn    s    ;Wc95IC&T*H2  44
   788	 	C#u||, 		 tDz"M''rg   r   )r   r   rj   r   
patch_coder   r   c                L   |D ]  }	t         j                  d|	        du rdndu rd|t         j                  d       t        j                  d| d| d	d
dd|dt        j                        }
fd}|
j                  ddd      }|j                  dd      } ||       |j                  dd      } ||       |j                  dd      } ||       |j                         }|j                  dddd       |j                  ddd d!"       |j                  d#dd$%       |j                  d&dd'%       |j                  d(dd)%       |j                  d*t        d d+,       |j                  d-t        |d.,       |j                  d/d0      } ||       |j                  d1dd2%       |j                  d3dd4%       |j                  d5dd6%       |j                  d7dd8%       |j                  d9      } ||       |j                  d-t        |d.,       d }t        t        j                        d:k  r|gt        j                  d:d  }|
j                  |      }t        t         t"        t$        t&        d;} ||j(                     || |      S )<NzPUnrecognized kwarg %s; perhaps this repro was made on a newer version of PyTorchTr   Fr   zHpatch_code no longer works on this version of PyTorch, silently ignoringzAn after_aot repro script, typically triggering a bug in PyTorch Inductor.
When run with no arguments, this script defaults to running 'z8'.
Extra flags may be available; to find out more, try 'zr --help'.
There are also alternate subcommands available, see below.

default settings on this script:
  accuracy=z
  tracing_mode=z
  save_dir=z
  check_str=rl   )descriptionformatter_classc                 B   | j                         }|j                  ddddd       |j                  dddd	       |j                  d
dddd       | j                  dt        dd       | j                  dddd d       | j                  dt        dd       y )Nz--no-accuracyr   store_constr   z>do not test accuracy, just run the module and see if it errors)destactionconstdefaulthelpz
--accuracya  test if the RMSE between the compiled module and the fp64 reference is greater
than eager and the fp64 reference. This is usually more reliable than the
standard allclose test, as we expect numeric differences from compiling, often
improving accuracy over eager.  RMSE test allows for compiled module to
diverge greatly from eager, as long as this divergence moves it closer to the
'true' mathematical value of the network.  Caveats: (1) double precision can
still suffer from rounding error, so it is not a perfect reference (see for
example 'Herbie: Automatically Improving Floating Point Accuracy') for
approaches that detect the necessary working precision and compute it in
arbitrary precision floating point; unfortunately, this is not practical for
tensor computation; (2) if there are not enough samples in the output being
compared, we may get unlucky and have an unlucky greater RMSE than eager; this
could be overcome by applying a more rigorous statistical test at some
p-value, which we leave for future work.
)rv  rw  rx  ry  z--strict-accuracyr   a  by default, when doing accuracy minification we will reject reductions which
change the divergence from a floating point divergence to a integral/boolean
divergence.  This is because some operations like ReLU involve temporarily
sharp boundaries that smooth out again afterwards; without requiring
divergence on floating point, the minifier will often fixate on divergent
boolean tensor even though this is not the true source of the divergence.
However, rejecting these reductions makes it more difficult for the minifier
to make process.  Using this option will let the minifier progress for ALL
divergences--you just might not end up with a useful repro in the end.z
--save-dirDIRz!directory where saved inputs live)typerx  metavarry  z--no-save-dirrj   z(don't use any directory for saved inputs)ru  rv  rw  ry  z--tracing-modez{real,fake,symbolic}z>how to trace the repro module into a GraphModule with metadata)r{  r|  rx  ry  )add_mutually_exclusive_groupadd_argumentr   )parseraccuracy_groupr   rj   r   s     r0   common_flagszrun_repro.<locals>.common_flags  s    <<>## Q 	$ 	
 	##  	$ 	
, 	## #	J 	$ 	
$ 	4 	 	
 	 ; 	 	
 	* Q 	 	
rg   r   z{run,minify,analyze})ru  r|  requiredr   zjust run the repro)ry  r   zrun the minifier on the reproget_argszget the argsz	--isolate
store_truez9run in separate processes to avoid interference (default))rv  rx  ry  z--no-isolater   store_falsez3speed up by running all compilation in same process)ru  rv  ry  z!--skip-saving-eager-intermediatesz+skip saving eager intermediates on --minify)rv  ry  z--offload-to-diskzYduring minification, offload delta debugging intermediates to disk.  Use if you're OOMingz--skip-sanityz@skip sanity check at beginning of minification on original graphz--max-granularityz;start at this granularity and work down; must be power of 2)r{  rx  ry  z--check-strzBrequire minified program to fail with error containing this stringanalyzez&run the accuracy analyzer on the reproz$--skip-saving-inductor-intermediatesz/skip saving inductor intermediates on --analyzez#--skip-saving-float64-intermediatesz!skip saving float64 intermediatesz--skip-check-deterministicz/skip checking that the network is deterministicz--stable-hashz>use SHA-1 checksum instead of fast (but possibly unsound) hashr   r(   )r   r  r   r   r  )rE   rF   argparseArgumentParserRawTextHelpFormatteradd_subparsers
add_parserr}  r~  r   r   r   r   argv
parse_argsr  re  r  rn  rg  r   )r   r   r   r   rj   r   ro  r   r`   kr  r  
subparsers
parser_runparser_minifyparser_get_argsparser_minify_isolateparser_analyzeparser_minifier_queryr   r   COMMAND_FNSs      ```                r0   	run_repror    s     
^	

 4	U	V	
 $$>>EY G66=Y ? + / + ,  !55F F
P && 6 ' J &&! ' J ))6 * M  ++J^+LO!)FFH&&H	 '  &&B	 '  +:   h  
 O  
 J	   Q	    **@ + N  .>   
 -0   
 $>   
 M    '11 &'&&Q	 '  D
388}'#((12,'%G ."K (;w'i@@rg   )NNNNNrp   )Rr  r[   rX   r   loggingr   r   r   r   ry   r   	importlibr   tempfiler   typingr   r   r   r   r<   torch.fxrA   torch.nnnntorch._dynamo.debug_utilsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   torch._dynamo.utilsr   r   r   "torch.fx.experimental.proxy_tensorr   %torch.fx.experimental.symbolic_shapesr   r   	torch.hubr   r   r    	getLoggerr@  rE   inductor_config	is_fbcoder   r   rf   r   r   rG   r@   r   r   r   rY   r   r   r   Modulebool__annotations__r  r  re  rg  rn  r  r$  rg   r0   <module>r     s      	  	   
   # " - -       " = < 6   g!   89$$&N Nl ?Dd -l -` DH ?82C 2 	9 9B H 05U /Y../EPTU (X 	
 "	!!d$ /
?S(BIIs#3T#9::; 
"JEP
(J !#_A
 D#I_Arg   