
    IЦiMp                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKrS SKJr  S SKJr  S SKJrJrJrJrJrJr  S SKrS SKJr  S SKrS SKJr  S SKJ r   S SKJ!r!  S SK"J#r#  S S	K$J%r%J&r&  S
SK'J(r(  S
SKJ)r)J*r*  \RV                  " \,5      r-\" S5      r.\" S5      r/\/Ra                  5       r1\1(       a  S SK2r3/ r4Sr5\1(       ah  / SQr4\3Rl                  Rn                  Rp                  Rs                  5       Ru                  SS5      r;SRy                  \4 V s/ s H	  n SU  S3PM     sn 5      r5/ SQr= " S S5      r>S r?Sr@ " S S5      rA\R                  " S5      S 5       rCSS.S  jrDS! rES" rF " S# S$\G5      rHS% rISCS& jrJ SDSSS'.S( jjrKS) rLS* rMS+ rN SDSSS'.S, jjrOS-\S.   S/S0S1S.4S2 jrPS3\.S1\\\.   /\.4   4S4 jrQ\Q" \R                  5      rS\Q" \R                  " S55      5      rU\Q" S 5      rV\Q" S5      rW\Q" S5      rX " S6 S75      rY " S8 S95      rZ " S: S;5      r[   SES<\\\   /\\   4   S=\\S>\\\\\]4      S?\\]   S1\\\\4   4
S@ jjr^SA\\S1\\./\.4   4SB jr_gs  sn f )F    N)Counter)import_module)AnyCallableDictListOptionalTypeVar)Tensor)rand_strided)is_float_dtype)StorageWeakRef)ContentStoreReaderContentStoreWriter   )config)clone_inputsget_debug_dirTztorch._inductor.config )z1//caffe2/torch/fb/sparsenn:sparsenn_operators_gpuz-//caffe2/torch/fb/sparsenn:sparsenn_operatorsz///deeplearning/fbgemm/fbgemm_gpu:sparse_ops_cpuz+//deeplearning/fbgemm/fbgemm_gpu:sparse_opszfbcode://
ztorch.ops.load_library("z"))buck2runz@mode/dev-nosanc                   *    \ rS rSrS rS rSS jrSrg)BuckTargetWriter>   c                 ,   [         R                  R                  [         R                  R                  U5      5      u  U l        U l        U R
                  R                  SS5      U l        U R                  R                  SS5       SU R                   3U l        U R                  U R                  R                  S5      S  U l        U R                  SS  U l        U R                  nX"R                  S5      S  SS  nSU S	U R                   3U l	        g )
Nz.pyr   /.zfbcode.   zfbcode/r   :)
ospathsplitabspathsubdirpy_filereplacetargetfindcmd_line_path)selffilenametmps      X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/_dynamo/debug_utils.py__init__BuckTargetWriter.__init__?   s    $&GGMM"''//(2K$L!T\ll**5"5 {{**345Qt{{mD	IIdiinnY79:	IIabM	 kk((9%'(,!#a}5    c                     SR                  [         Vs/ s H	  nSU S3PM     sn5      n[        R                  " SU R                   SU R
                   S[         SU SU R                   S	35      $ s  snf )
Nr   z	        "z",za
load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary")

python_binary(
    name="z",
    srcs = ["z"],
    compile = False,
    deps = [
        "//caffe2:torch",
        "//caffe2/functorch:functorch",
        "//triton:triton",
        "z",
    ],
    cpp_deps = [
z
    ],
    main_module = "z",
    par_style = "xar",
)
)join
extra_depstextwrapdedentr*   r(   
cur_targetr$   )r-   xextra_cpp_depss      r0   buildBuckTargetWriter.buildM   s    z#Jz!is"$5z#JK ;;- ll^ 
     II; !
 	
 $Ks   A3c                 d   [         R                  R                  U R                  S5      n[	        US5       nUR                  U R                  5       5        S S S 5        [        U R                  /-   nU(       a%  [        R                  SSR                  U5      5        U$ ! , (       d  f       NP= f)NTARGETSwzFFound an example that reproduces the error. Run this cmd to repro - %s )r#   r$   r5   r'   openwriter<   BUCK_CMD_PREFIXr,   logwarning)r-   	print_msgtarget_filefd	cmd_splits        r0   rC   BuckTargetWriter.writef   s    ggll4;;	:+s#rHHTZZ\" $ $t'9'9&::	KKX#  $#s    B!!
B/)r,   r$   r(   r'   r*   N)T)__name__
__module____qualname____firstlineno__r1   r<   rC   __static_attributes__ r3   r0   r   r   >   s    6
2r3   r   c                  (   [         R                  R                  [        5       S5      n U c-  [        R
                  " 5        S[        R                  " 5        3n [         R                  R                  U 5      (       d  [         R                  " U SS9  U $ )Nminifierz
/minifier_T)exist_ok)
r#   r$   r5   r   tempfile
gettempdirgetpassgetuserexistsmakedirs)r$   s    r0   minifier_dirr[   t   se    77<<4D|%%'(
7??3D2EF77>>$
D4(Kr3      c                      \ rS rSr\R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                  \R
                  R                   \R
                  R"                  \R
                  R$                  \R
                  R&                  \R
                  R(                  \R
                  R*                  \R
                  R,                  \R
                  R.                  \R
                  R0                  \R
                  R2                  \R
                  R4                  /r\S 5       r\S 5       rSrg)NNModuleToString   c                     [        5       nU R                  5        H5  u  p#[        U5      [        R                  ;  d  M$  UR                  U5        M7     [        U5      S:  a  [        R                  SU5        g)Nr   z-We have not tested reprs of some modules - %sT)	setnamed_childrentyper^   
safe_reprsaddlenrE   rF   )gmcant_convert_modules       r0   can_convert_to_string&NNModuleToString.can_convert_to_string   s`    u**,IAF|#3#>#>>  ( - |q KKGVr3   c                 "   SSK Jn  Sn[        R                  " S5      nU R	                  5        HY  u  pEUR                  5        n[        UR                  5       S 5      nUb  UR                  (       a  U S3nX2S-   SU SU S	3-  nM[     U R                  R                  5        H  u  pU	c  M
  U	R                  5       [        ::  a(  SS
KJn
  U
R                  [        :  d   e[!        U	5      nOh["        R$                  " U	5      (       a'  S['        U	R(                  5       SU	R*                   S3nO&S['        U	R(                  5       SU	R*                   S3nU	R                  (       a  U S3nX2S-   SU SU S3-  nM     U R,                  R                  5        HW  u  pUc  M
  SnUR                  (       a  SnS['        UR(                  5       SUR*                   U S3nX2S-   SU SU S	3-  nMY     X1" U R.                  S5       S	3-  nU$ )Nr   )
_addindent    z
            from torch.nn import *
            class Repro(torch.nn.Module):
                def __init__(self) -> None:
                    super().__init__()
            z.cuda()   zself.z = r   )
PRINT_OPTSztorch.randn(z, dtype=)ztorch.randint(1, size=zself.register_buffer('z', z)
r   z, device="cuda"ztorch.nn.Parameter(torch.randn(z))r\   )torch.nn.modules.modulern   r7   r8   rb   __repr__next
parametersis_cuda_buffersitemsnumelMAX_CONSTANT_NUMEL_INLINEtorch._tensor_strrq   	thresholdreprtorchis_floating_pointlistshapedtype_parameterscode)rg   rn   tab	model_strmodule_namerj   
module_strexample_parambuffer_namebufferrq   
tensor_str
param_nameparammaybe_devices                  r0   convertNNModuleToString.convert   s    6OO
	 $&#4#4#6K"OO-.J !!2!2!4d;M(]-B-B *|73
E7%}C
|2FFI $7 $&;;#4#4#6K~||~!::8!++/HHHH!&\
((00+D,>+?x~UVW
 -T&,,-?,@VWX  ~~ *|73
E7"8STWXXI# $7& "$!5!5!7J}L}}0:4;L:MXV[VaVaUbcobpprsJE7%
|3zl"EEI "8  	
277A./r22	r3   rQ   N) rL   rM   rN   rO   r   nnLinearConv1dConv2dConv3dBatchNorm1dBatchNorm2dBatchNorm3d	LayerNormDropoutSoftmaxReLUGELUIdentity	MaxPool2d	EmbeddingTanhConvTranspose1dGLULSTMFlattenAdaptiveAvgPool2drd   staticmethodrk   r   rP   rQ   r3   r0   r^   r^      s0     ""+J0 	 	 ; ;r3   r^   c                  J   [         R                  R                  5       (       d  gSn  [        R                  " SS/5      nUR                  5       R                  S5      nSR                  U Vs/ s H  o3S;  d  M
  SU S	3PM     sn5      nX S3-  n [        S [        [         R                  R                  5       5       5       5      nU S-  n UR                  5        H  u  pgU SU SU S	3-  n M     U S-  n U $ s  snf ! [        [        R                  4 a    U S
-  n  Nf = f)Nz:# torch.cuda.is_available()==False, no GPU info collected
z# CUDA Info: 
nvccz	--versionr   r   )r   # z 
z# nvcc not found
c              3   `   #    U  H$  n[         R                  R                  U5      v   M&     g 7fN)r   cudaget_device_name).0is     r0   	<genexpr>,_cuda_system_info_comment.<locals>.<genexpr>   s&      /O!

""1%%/Os   ,.z# GPU Hardware Info: 
z : )r   r   is_available
subprocesscheck_outputdecoder%   r5   FileNotFoundErrorCalledProcessErrorr   rangedevice_country   )r   cuda_version_outcuda_version_linesscomment	gpu_namesnamecounts           r0   _cuda_system_info_commentr      s-   ::""$$L!I*%22FK3HI-446<<TB''0BT0B1tm;Rs#;0BTUy^#	  /4UZZ5L5L5N/O I **I (r$s5'--	 )I Uz<<= *))	*s*   AD  .	C;;
C;D  ;D   D"!D"F)stable_outputc           	      h   SS K nSS KnU (       a  gUR                  R                  R                  R                  5       nSUR                  R                  R                  5        SUR                  R                  R                  5        SUR                  R                  R                  5        SU S3	$ )Nr   z*# config omitted due to stable_output=Truez~import torch._dynamo.config
import torch._inductor.config
import torch._functorch.config
import torch.fx.experimental._config
r   )
torch._functorch.configtorch._inductor.configfxexperimental_configcodegen_config_dynamor   	_inductor
_functorch)r   r   experimental_configs      r0   generate_config_stringr      s    "!;((//77FFH
 $$& ' (&&( ) *'') * +  	 	r3   c                  R    [         R                  R                  [        5       S5      $ )Nzminifier_launcher.py)r#   r$   r5   r[   rQ   r3   r0   get_minifier_repro_pathr     s    77<<(>??r3   c                 b   [        5       n[        R                  SU5        [        (       a  [	        U5      R                  5          [        US5       nUR                  U 5        S S S 5        g ! , (       d  f       g = f! [         a&  n[        R                  S5        [        S5      UeS nAff = f)NzWriting minified repro to:
%sr@   r   z(Could not write to {minified_repro_path})
r   rE   rF   use_buckr   rC   rB   OSError	exceptionNotImplementedError)contentsminified_repro_pathrI   es       r0   helper_for_dump_minifyr     s    13KK02EFx,-335U%s+rHHX ,++  Ub!"LMSTTUs6   A> A-$A> -
A;7A> ;A> >
B.!B))B.c                       \ rS rSrSrg)AccuracyErrori$  rQ   N)rL   rM   rN   rO   rP   rQ   r3   r0   r   r   $  s    r3   r   c                     [        U 5      n[        [        U 5      5       HE  n[        X   [        R
                  5      (       d  M&  X   R                  X   R                  5        MG     U$ )z
This clone inputs is different from utils clone_input. In case of minifier,
all the tensors are leaf tensors while creating a new graph. So, we set the
requires_grad field w/o checking the leafness of the tensor.
)r   r   rf   
isinstancer   r   requires_grad_requires_grad)example_inputscloned_inputsidxs      r0   clone_inputs_retaining_gradnessr   (  sX     !0MS()m(%,,77--n.A.O.OP * r3   c                 V   SSK JnJnJn  [        R
                  " U 5      n U(       d  [        U5      n[        U S5      (       a  U R                  S5        [        U S5      (       a  U " U5      OU " U6 nU(       a  U$ U" U5      (       a  U" U5      nUR                  5         U" XSU5      $ )z
Runs a forward and possibly backward iteration for a given mod and args.

When disable_clone is True, we will use args as-is without cloning.
This is higher fidelity but we may destroy the args in the process.
r   )collect_resultsreduce_to_scalar_lossrequires_bwd_pass	zero_gradT_boxed_callN)
testingr   r   r   copydeepcopyr   hasattrr   backward)	rg   argsonly_fwddisable_cloner   r   r   outlosss	            r0   run_fwd_maybe_bwdr   5  s     SR	r	B.t4r;
T b-00"T(b$iC
$S)2D$//r3   require_fp64ignore_non_fpc          	         SSK Jn  [        XU5      nSn[        R                  (       a8   [        [        R                  " U 5      [        U5      5      u  p[        XU5      n [        XU5      nU" UUU[        R                  SUS9nU$ ! [         a*    U(       a  [        S5      e[        R                  S5         N[f = f! [         a  n[        R                  S5         SnAgSnAff = f)	aI  
Check two models have same accuracy.

require_fp64: if True, raise an error if we unable to calculate the fp64 reference
ignore_non_fp: if True, do not compare outputs which are not floating point.  This
    is mostly useful for the minifier (which wants to avoid quantizing floating point
    error into integer/boolean error)
r   )sameNzfCould not generate fp64 outputs, workaround with torch._dynamo.config.same_two_models_use_fp64 = FalsezCould not generate fp64 outputszWhile minifying the program in accuracy minification mode, ran into a runtime exception which is likely an unrelated issue. Skipping this graph.T)tol	equal_nanr   )utilsr   r   r   same_two_models_use_fp64cast_to_fp64r   r   r   	ExceptionRuntimeErrorrE   rF   r   repro_tolerance)rg   opt_gmr   r   r   r   r   reffp64_ref
fp64_modelfp64_examplesresr   passings                 r0   same_two_modelsr  P  s    " 
B
9CH&&
	;(4b!#B>#R)%J )HMH
A ""#G N7  	;"|  KK9:	;   	$	

 s)   7B
 #C 
1B>=B>
C*C%%C*c                    U R                   R                   GH@  nUR                  S:X  a  UR                  [        R
                  R                  R                  R                  :X  a}  [        UR                  5      S:X  d   e[        UR                  S   5      (       aE  UR                  S   [        R                  :w  a$  UR                  S   [        R                  4Ul
        UR                  S:X  d  M  UR                  R                  S5      nUc  M  [        U5      (       d  GM  [        UR                  5      n[        R                  US'   X1l        GMC     U R                   R!                  5         U R#                  5         U $ )Ncall_functionrp   r   r   r   )graphnodesopr*   r   opsprimsconvert_element_typedefaultrf   r   r   float64kwargsgetdictlint	recompile)modelnoder   
new_kwargss       r0   cast_dtype_args_to_fp64r    s   !!GG&uyyCCKKKtyy>Q&&&diil++		!0M!YYq\5==9	77o%KKOOG,E ^E%:%:!$++.
&+mm
7#( " 
KK	OOLr3   c                    ^  SSK Jn  UR                  T 5      nT [        R                  :X  a  [        U5      nU" U 4S jU5      nX4$ )Nr   )tree_mapc                    > [        U [        R                  5      (       a&  U R                  5       (       a  U R	                  T5      $ U $ r   )r   r   r   r   to)r:   r   s    r0   <lambda>cast_to.<locals>.<lambda>  s<    a&&1+>+>+@+@ $$u+ r3   )torch.utils._pytreer!  r#  r   r  r  )r   r  inputsr!  s   `   r0   cast_tor(    sI    ,HHUOE (.	 		F =r3   c                 6    [        [        R                  X5      $ r   )r(  r   r  )r  r'  s     r0   r  r    s    5==%00r3   c          	           U" [         R                  " U 5      [        U5      5      n[        U UUUUUS9(       + $ ! [         a  n[
        R                  S5         S nAgS nAff = f)Nr   zWhile minifying the program in accuracy minification mode, ran into a runtime exception which is likely an unrelated issue. Skipping this graphF)r   r   r   r  r  rE   r   )rg   r   compiler_fnr   r   r   compiled_gmr   s           r0   backend_accuracy_failsr-    su    !MM">~N
 #%'
 
 	
   	#	

 s   8; 
A$AA$strideztorch._prims_common.StrideTyper   ztorch._prims_common.ShapeTypereturnc                8    U b  U $ [         R                  " U5      $ r   )r   make_contiguous_strides_for)r.  r   s     r0   _stride_or_defaultr2    s    
 '6UU-N-Nu-UUr3   dc                    ^  U 4S j$ )Nc                    > U b  U $ T$ r   rQ   )r:   r3  s    r0   r$  _mk_defaulter.<locals>.<lambda>  s    !-Q.Q.r3   rQ   )r3  s   `r0   _mk_defaulterr7    s	    ..r3   cpuc                   :    \ rS rSrS	S jrSSS.S jrS rS rSrg)
NopInputReaderi  Nc                     SU l         g )Nr   total)r-   s    r0   r1   NopInputReader.__init__  s	    
r3   device
dtype_hintc                .    U =R                   S-  sl         g )Nr   r<  )r-   storage_hashnbytesr@  rA  s        r0   storageNopInputReader.storage  s    

a
r3   c                     g r   rQ   r-   r   r  s      r0   tensorNopInputReader.tensor      r3   c                     g r   rQ   rH  s      r0   symintNopInputReader.symint  rK  r3   r<  r/  N	rL   rM   rN   rO   r1   rE  rI  rM  rP   rQ   r3   r0   r:  r:    s     7;t r3   r:  c                   V    \ rS rSrSSS.S jjrSSS.S jr SSSSSS.S jjrS	 rS
rg)InputReaderi  N)pbarc                x    Uc  [         R                  S5        Ub  [        U5      OS U l        / U l        X l        g )Nz0no save_dir specified, will generate random data)rE   rF   r   storer   rS  )r-   save_dirrS  s      r0   r1   InputReader.__init__  s7    
 KKJK5=5I'1t
		r3   r?  c                   U R                   b  U R                   R                  S5        [        U5      n[        U5      nU R                  bP  UbM   U R                  R                  U5      nX5R                  :w  a   [        R                  SX5R                  5        U$ [        R                  SU5        X$R                  -  4n[        S US9n[        XgXC5      R                  5       $ ! [         a     NUf = f)Nr   zdevice mismatch: %s != %sz1could not load %s, generating random data insteadr   )rS  update_device_or_default_dtype_or_defaultrU  read_storager@  rE   rF   r   itemsizer2  r   untyped_storage)r-   rC  rD  r@  rA  rE  r   r.  s           r0   rE  InputReader.storage  s    99 IIQ#F+&z2
::!l&>
**11,? ^^+KK ;V^^T GV...0#D6E:>NNPP % s   C% %
C21C2)storage_offsetr   r   is_leafc                ,   [        X2S9n[        U5      n[        U5      n[        U5      n[	        U5      n[
        R                  " / XQR                  US9n	[
        R                  " 5          U	R                  XX#5        S S S 5        U(       dk  [
        R                  " 5          U	R                  [
        R                  S9n	S S S 5        [
        R                  " 5          U	R                  XX#5        S S S 5        [
        R                  R                  R                  U	5      U:X  d   e[
        R                   R#                  X5        U R$                  R'                  U	5        U	$ ! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f)NrY  )r   r@  r   )memory_format)r2  _storage_offset_or_defaultr\  _is_leaf_or_default_requires_grad_or_defaultr   rI  r@  no_gradset_enable_gradclonepreserve_format_subclasses
meta_utilssafe_is_leaf_utilsset_tensor_metadatar   append)
r-   rE  r   r.  ra  r   r   rb  metadatats
             r0   rI  InputReader.tensor#  s    $F83NC!%(%g.1-@LLeNN-
 ]]_FF7E: ""$GG%*?*?G@ %w> !  ++88;wFFF((5		 _ %$ s$   +E#"E4F#
E14
F
Fc                 <    U R                   R                  U5        U$ r   )r   rr  )r-   vals     r0   rM  InputReader.symintD  s    		
r3   )r   rS  rU  r   rP  rQ   r3   r0   rR  rR    s>    	d 	 7;t Q4 	 Br3   rR  c                   d    \ rS rSrSS.S jrS rSSS.S\4S	 jjrSS
 jrS r	SS jr
SS jrSrg)InputWriteriU  Fstable_hashc                    / U l         [        R                  " 5       U l        Xl        Ub	  [        XS9OS U l        0 U l        g )Nr{  )_lines	itertoolsr   storage_counterrV  r   rU  seen_storages)r-   rV  r|  s      r0   r1   InputWriter.__init__V  sC    (0  # xA 	

  r3   c                 r    S/nUR                  S U R                   5       5        UR                  S5        U$ )Nzdef load_args(reader):c              3   ,   #    U  H
  nS U 3v   M     g7f)ro   NrQ   )r   ls     r0   r   $InputWriter.lines.<locals>.<genexpr>f  s     1[4s[s   zload_args._version = 0)extendr~  rr  )r-   rs     r0   linesInputWriter.linesb  s8    $
 	
1T[[11 	
)*r3   NrA  device_hintr/  c          
      X   [        U5      nU R                  R                  U5      nUb  U$ S[        U R                  5       3nSn[        S 5      [        U5      :w  a  SU< 3nSnUR                  nUR                  S:X  a  Uc   eUn[        S 5      U:w  a  SU< 3nUR                  5       n	S n
U R                  b5  UR                  R                  S:w  a  U R                  R                  U5      n
U R                  R                  U SU
< SU	< U U S35        XPR                  U'   U$ )	Nbufr   z, dtype_hint=metaz	, device=z = reader.storage(, rr   )r   r  r  ru   r  r\  r@  rc   r[  rD  rU  write_storager~  rr  )r-   r_  rA  r  wsvmaybe_dtype_hintr   r@  rD  rC  s              r0   rE  InputWriter.storageq  s@   O,""2&=H$t++,-.T"&7
&CC!.zn=  '';;& *** Fd#v-&vj1L '')::!o&<&<&A&AV&K::33ODLc#L#32fZ~N^M__`a	
 "#2r3   c                 t   SSK Jn  U R                  UR                  5       UR                  UR
                  S9n/ n[        S UR                  S9UR                  5       :w  a1  UR                  [        [        UR                  5       5      5      5        [        S 5      UR                  :w  a  UR                  SUR                  < 35        U" [        S 5      UR                  5       :H  5      (       d#  UR                  SUR                  5       < 35        [        R                   R#                  U5      nU(       a&  UR%                  S UR'                  5        5       5        [)        S 5      UR*                  :w  a  UR                  SUR*                  < 35        [        R,                  R.                  R1                  U5      n[3        S 5      U:w  a  UR                  S	U< 35        U R4                  R                  S
SR7                  U[        [        UR                  5      5      /UQ5      -   SU 3-   5        g )Nr   )statically_known_truer  rY  zdtype=zstorage_offset=c              3   6   #    U  H  u  pU S U< 3v   M     g7f)=NrQ   )r   kr  s      r0   r   %InputWriter.tensor.<locals>.<genexpr>  s     I1H1#Qqe1Hs   zrequires_grad=zis_leaf=zreader.tensor(r  )  # )%torch.fx.experimental.symbolic_shapesr  rE  r_  r   r@  r2  r   r.  rr  strtupler\  re  ra  r   rp  get_tensor_metadatar  ry   rg  r   rm  rn  ro  rf  r~  r5   )r-   r   rt  r  rE  r   tensor_metadatarb  s           r0   rI  InputWriter.tensor  s   O,,AGG  
 d!''2ahhj@KKE!((*-./T"agg-KK&,-$&t,0@0@0BB
 
 KK/!*:*:*<)?@A,,::1=KKI1F1F1HII$T*aoo=KK.(;<=##..;;A>t$/KK(7+./ii#eAGGn"5==>?dVn	
r3   c                 *   U R                   R                  SU S[        U5       35        [        U[        [
        45      (       a  U R                   R                  S5        [        U5       H  u  p4U SU S3n[        U[        R                  5      (       a  U R                  XT5        M?  [        U[        [        R                  45      (       a  U R                  XT5        Mw  U R                  XT5        M     U R                   R                  S5        g g )Nr   z# was unsupported type for dumping: z"""[])r~  rr  rc   r   r   r  	enumerater   r   rI  intSymIntrM  unsupported)r-   r   argr   aname_is         r0   r  InputWriter.unsupported  s    Rv%HcTU cD%=))KKu%!# 61#Qa..KK*C#677KK*$$V/ ' KKu% *r3   c                 J    U R                   R                  SU< SU S35        g )Nzreader.const(r  z!, filtered out during compilation)r~  rr  )r-   r   s     r0   constInputWriter.const  s'    D85.OP	
r3   c                     [        U[        R                  5      (       a  UR                  R                  nU R
                  R                  SU< SU 35        g )Nzreader.symint(r  )r   r   r  r  hintr~  rr  )r-   r   rw  s      r0   rM  InputWriter.symint  s?    c5<<((((--C^C7%v>?r3   )r~  rV  r  r  rU  rO  )rL   rM   rN   rO   r1   r  r  rE  rI  r  r  rM  rP   rQ   r3   r0   rz  rz  U  s8    05 
  6:t PS 8
<&$
@r3   rz  funcr@  
sym_shapesdefault_sym_shapec           	         ^^^^ SSK Jn  UR                  5        VVs0 s H  u  pVXe_M	     nnnSR                  UR	                  5       5      n[
        R                  " U 5      n	SU S3n
SU S3nSn " S	 S
5      n0 nT=(       d    0 mUU4S jmS[        4UU4S jjnU R                  nUR                  5        H  u  nnUS:X  a  M  [        R                  " UU5      nU(       a>  UR                  5       u  nn[        UR                  S5      5      nUU   nU" UU5      UU'   [        R                  " UU5      nU(       d  M  T" UR                  S5      5      UU'   M     S[
        R                  " U 5      R                   ;   aq  U" 5       nUUS'   [        R"                  " X5       HK  nUR                  5       u  nnnn[        UR                  S5      5      nUU   n[%        UUU" UU5      5        MM     U$ s  snnf )a  
Takes in a function which has been printed with print_readable() and constructs kwargs to run it.

Handles Tensor inputs, Symints, and a graph module which might have tensor constants.

Consider a function `forward` defined as follows:

def forward(self, primals_1: "f32[1001, 6]", primals_2: "f32[s0]", primals_3: "Sym(s0)",):
    _tensor_constant0: "i64[4190]" = self._tensor_constant0
    # Further implementation

kwargs = aot_graph_input_parser(forward)
forward(**kwargs)
r   )dtype_abbrs|z(_tensor_constant\d+): \"(z0)\[\s*(.*?)\s*\]\" = self\.(_tensor_constant\d+)(z)\[\s*(.*?)\s*\]zSym\((s\d+)\)c                       \ rS rSrSrSrg)/aot_graph_input_parser.<locals>.TensorContaineri  z#Container for tensors as attributesrQ   N)rL   rM   rN   rO   __doc__rP   rQ   r3   r0   TensorContainerr    s    -r3   r  c                 |   >^  [         R                  " T T;   =(       d    TS LU 4S j5        TR                  T T5      $ )Nc                     > T  S3$ )Nz; not in symbolic_shapes and default sym shape not passed inrQ   )rM  s   r0   r$  =aot_graph_input_parser.<locals>.get_sym_int.<locals>.<lambda>  s    vhYZr3   )r   _checkr  )rM  r  r  s   `r0   get_sym_int+aot_graph_input_parser.<locals>.get_sym_int  s9    j A$5T$AZ	
 ~~f&788r3   r/  c                   > / n/ n[        U 5       Hj  u  pEUR                  5       nSU;   a,  T" U5      nUR                  U5        UR                  U5        MG  U(       d  MP  UR                  [        U5      5        Ml     UR                  (       a  [
        R                  O[
        R                  nU" X!T
S9nU H"  n	[
        R                  R                  X5        M$     U$ )Nr   )r   r@  )
r  striprr  r  r   r   randnzerosr   mark_dynamic)r   r   resolved_shapedynamic_dimsr   dimr   constructorr   r3  r@  r  s             r0   
gen_tensor*aot_graph_input_parser.<locals>.gen_tensor  s    &FA))+Ccz$%%a(##A&3"))#c(3 ' &+%<%<ekk%++.fEAMM&&s. 
r3   ,r   r-   )torch.fx.graphr  ry   r5   valuesinspect	getsourcer   __annotations__researchgroupsr  r%   group	signaturerv   finditersetattr)r  r@  r  r  r  keyvalue	dtype_mapdtype_patternsourcetensor_assignment_regextensor_regexsym_shape_regexr  r  r  annotationsr   
annotationmatch	data_type	shape_strr   r   	container	attr_nameri   r  s    ```                       @r0   aot_graph_input_parserr    s   * +.9.?.?.AB.A
.AIBHH[//12M t$F "<M?Jz{&67L&O. .  F!rJ9F  * &&K(..0zH		,
3#(<<> Iy)//#./Ei(E&ue4F5M		/:65'A7F5M 1  ""4(333#%	"v[[!8AE16.Iy)Q)//#./Ei(EIy*UE*BC	 B MS Cs   G:r.   c                    ^ ^ [         R                  " 5       m[        R                  R	                  [        R                  R                  T 5      5      m U4S jnU U4S jn[        R                  " U5        U$ )z
Decorator to cProfile a given function and save the result to disk on process exit.

Args:
    filename: filename to save profile to
c                 J   >^  [         R                  " T 5      U U4S j5       nU$ )Nc                     > TR                  5          T" U 0 UD6TR                  5         $ ! TR                  5         f = fr   )enabledisable)r   r  fnprofs     r0   wrapper3profile_to_file.<locals>.decorator.<locals>.wrapper7  s1    KKM4*6*s   + =)	functoolswraps)r  r  r  s   ` r0   	decorator"profile_to_file.<locals>.decorator6  s%    			 
	 r3   c            	         > TR                  T 5        [        R                  R                  [        R
                  " ST  ST  S35      5        g )Nz!                Wrote profile to z+, view with:

                    snakeviz z

                )
dump_statssysstderrrC   r7   r8   )r.   r  s   r0   save_it profile_to_file.<locals>.save_itA  sK    !

OO""* ,&Z (		
r3   )cProfileProfiler#   r$   r&   
expanduseratexitregister)r.   r  r  r  s   `  @r0   profile_to_filer  ,  sR     Dwwrww11(;<H	
 OOGr3   )FF)F)r   NN)`r  r   r   r  rW   r  r  loggingr#   r  r   r  rU   r7   collectionsr   	importlibr   typingr   r   r   r   r	   r
   r   torch._prims_common_prims_commonr   torch._subclasses.meta_utilsr   torch._dynamo.testingr   r    torch.multiprocessing.reductionsr   torch.utils._content_storer   r   r   r   r   r   	getLoggerrL   rE   r   inductor_config	is_fbcoder   libfb.py.build_infolibfbr6   extra_importspy
build_info	BuildInfoget_build_ruler)   r9   r5   rD   r   r[   r{   r^   	lru_cacher   r   r   r   r  r   r   r   r  r  r(  r  r-  r2  r7  float32r\  r@  r[  re  rg  rf  r:  rR  rz  r  r  r  r  )r:   s   0r0   <module>r     s	           	 	  
    # ? ?  # #  . . ; M  . !CL   89$$& 
J $$..==?GG	SWXJIITA!9!B?TUM 63 3l  a aH T 0 -2 (@U	I 	
0> 	7 7t*$1 	 RV56V +V &	V/Q /8Xa[M1$45 / "%--0 "5<<#67 *1- )%0 #E*   E Ehq@ q@l +/'+	`
DL>4</
0`` c3h(`  }	`
 
#s(^`F#c #hsAv&6 #i Us   *I5