
    qi                    v   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
mZ d dl mZ d dlmZmZmZmZ d dlmZmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlm Z  d dl!m"Z" d dl#m$Z$m%Z% d dl&m'Z'm(Z( d dl)m*Z* er
d dl+Z+d dl,m-Z- d dl.Z.d dl/m0c m1Z2 d dl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC d dlDmEZE d dlmFZF d dlmGZG d dlHmIZImJZJ d dlKmLZL d dlMmNZN d dlOmPZP d dlQmRZR ddlSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z` g dZae
e.j                  j                  gePdz  f   Zdej                   G d d             Zfej                   G d d              Zgd! Zhd"eidz  d#e2j                  d$eidz  d%e2j                  d&ekf
d'Zle.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  gZ{e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                   e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  e.j                  j                  j                  g	Zed(        Zd)ee.j                  j                  e
f   d&eee.j                  j                  e
f   d*f   fd+ZdFd,Zd-d.d/ee.j                  j                  e
f   d0ee.j                  j                  e
f   d1edz  fd2Zd3e.j                  j                  d4eWd&ee.j                  j                  eWf   fd5Zd3e.j                  j                  fd6Zd7e.j                  j                  d8eWd3e.j                  j                  d9eWd:eeg   f
d;Zd/ee.j                  j                  e
f   d0ee.j                  j                  e
f   d1edz  d<ekfd=Z G d> d.      Zd? Z	 dGd3e.j                  j                  d@dAd&dBfdCZdD ZdE Zy)H    N)defaultdict)CallableIterator)contextmanager)Anyfinal
NamedTupleTYPE_CHECKING)tracingTracingContext)autograd_not_implemented)FakeScriptObject)_deregister_op_impl_is_op_registered_to_fake_ruleregister_op_impl)FakeTensorMode)_ConstantAttributeType)#first_call_function_nn_module_stack)_PyTreeCodeGen_PyTreeInfo)immutable_dictimmutable_list)insert_deferred_runtime_asserts)ValueRanges)_build_cache_collect_all_valid_cia_ops_collect_and_set_constant_attrs_collect_param_buffer_metadata_detect_fake_mode_from_gm_fakify_params_buffers_get_decomp_for_cia_is_preservable_cia_op_name_hoo_subgraph_placeholders7_override_graph_signature_for_temp_registered_constants/_overwrite_signature_for_non_persistent_buffers)_populate_param_buffer_metadata_to_new_gm_register_constants_as_buffers_rename_without_collisions_special_op_to_preserve_ciaplaceholder_naming_pass)Verifierdetect_fake_modeunset_fake_temporarily)is_equivalentreorder_kwargsCustomDecompTable)compatibility)
PassResult)PassManager   )ArgumentSpecConstantArgumentCustomObjArgumentExportGraphSignature	InputKind	InputSpec
OutputKind
OutputSpecSymBoolArgumentSymFloatArgumentSymIntArgumentTensorArgumentTokenArgument)ExportedProgramModuleCallEntryModuleCallSignaturedefault_decompositionsc                       e Zd ZU ee   ed<   ee   ed<   ej                  ed<   ej                  ed<   dZee	   dz  ed<   d Z
y)rG   inputsoutputsin_specout_specNforward_arg_namesc                     | j                   D ]-  }|j                  |j                  k(  s|j                  |_        / | j                  D ]-  }|j                  |j                  k(  s|j                  |_        / y N)rJ   namerK   )selforiginal_nodenew_nodeios        c/home/ubuntu/crypto_trading_bot/.venv/lib/python3.12/site-packages/torch/export/exported_program.pyreplace_all_uses_withz)ModuleCallSignature.replace_all_uses_withi   sd     	'Avv+++!	'  	'Avv+++!	'    )__name__
__module____qualname__listr8   __annotations__pytreeTreeSpecrN   strrX    rY   rW   rG   rG   a   sE    ,__oo*.tCy4'.'rY   rG   c                   ,    e Zd ZU eed<   dZedz  ed<   y)rF   fqnN	signature)rZ   r[   r\   ra   r^   re   rG   rb   rY   rW   rF   rF   r   s    	H,0I"T)0rY   rF   c                 B     t        j                          fd       }|S )Nc                  T    t               5   | i |cd d d        S # 1 sw Y   y xY wrP   r.   )argskwargsfns     rW   wrapperz/_disable_prexisiting_fake_mode.<locals>.wrappery   s+    #% 	't&v&	' 	' 	's   ')	functoolswraps)rj   rk   s   ` rW   _disable_prexisiting_fake_modern   x   s%    __R' ' NrY   
spec1_typespec1_context
spec2_typespec2_contextreturnc                     | || |u xr ||k(  S t        | t        t        f      rt        |t        t        f      r||k(  S t        | t        t        f      rt        |t        t        f      r||k(  S | |u xr ||k(  S )zeTreat containers and their immutable variants as the same type. Otherwise
    compare as normal.
    )
issubclassdictr   r]   r   )ro   rp   rq   rr   s       rW   _fx_collection_equivalence_fnrw      s     Z/Z'JM],JJ*t^45*T>*; --*t^45*T>*; --#F(FFrY   c              #     K   i }t               }| j                         D ]x  \  }}|j                  j                         ||<   |j	                  |       t
        D ]3  }||j                  vs |j                  |      t        |d             5 t        |      }t        j                  j                  j                  |j                  v r/|j                  t        j                  j                  j                  =  |j                  t        j                  j                  j                        |       d }t        |      s& t        |      t        j                   ||             t"        D ](  }||j                  vs |j                  |      |       * { 	 d  |D ]_  }	|	j                  j%                          |	j                  j'                  ||	          |	j(                  j%                          t+        |	       a y # |D ]_  }	|	j                  j%                          |	j                  j'                  ||	          |	j(                  j%                          t+        |	       a w xY ww)NT)deferred_errorc                 R    |d   }|d= | 5   ||i |cd d d        S # 1 sw Y   y xY w)Noriginal_callablerb   )fake_tensor_modeoprh   ri   orig_cia_callables        rW   $_force_dispatch_to_orig_cia_callablezQ_override_composite_implicit_decomp.<locals>._force_dispatch_to_orig_cia_callable   s<     &': ;*+! :($9&9: : :s   &)r{   )setitems
py_kernelscopyadd(_AUTOGRAD_ALIAS_BACKEND_KEYS_TO_OVERRIDEpy_implr   r!   torch_CDispatchKeyCompositeImplicitAutogradr   r   rl   partial_BACKEND_KEYS_TO_OVERRIDEclearupdate_dispatch_cacher   )
cia_ops_to_callablesaved_tablespatched_opsop_overloaddecomp_callableoverride_dispatch_keyr~   r   keyr}   s
             rW   #_override_composite_implicit_decompr      s     L%K(;(A(A(C =<$_$/$:$:$?$?$A[!$%M 	!$K,B,BB:##$9:,[N	 0<8899[=S=SS&&uxx';';'U'UVKEHH00JJK	
	: .k:)[)!!8&7 - 	<C+000  )##C():;#	<Y=<~$ 	$BMM!MM  b!12$$&#		$+ 	$BMM!MM  b!12$$&#		$s-   A)I.,DI.?I.H  A%I.A&I++I.decomp_table.c                 J   t        t                     }i }t        | j                               D ]_  }||v r| |   ||<   |j	                  |       | |= $t        |      s0|j                         }|j                  d      rJ d       | |   ||<   a |D ]  }t        ||<    || fS )NatenzThis should be a custom op)	r   r   r]   keysremover"   rQ   
startswithr)   )r   all_preservable_cia_opsr   r}   op_nameks         rW   ,_split_decomp_table_to_cia_and_python_decompr     s     ""<">?<$$&' 7$ ((&22&6##**2.R  $B'ggiG))&1O3OO1&22&6#97@ % =!<A= ,,rY   c                      t               S )z
    This is the default decomposition table which contains decomposition of
    all ATEN operators to core aten opset. Use this API together with
    :func:`run_decompositions()`
    r2   rb   rY   rW   rH   rH   ?  s     rY   eprE   cia_to_decomppython_decomp_tablejoint_loss_indexc                   ddl m} ddlm} ddlm}m}m}	m}
m	}m
} ddlm} d } || |      s| j                         }i t        |j                  d            t        |j!                  d            }dd	lm}  ||       i t        |j                  d            t        |j!                  d            }t'        | j(                        }|t+         |       d
      }|j,                  }t/        |j0                  j2                  t4              sJ |j0                  j2                  j6                  j8                  }|J |j:                  t<        t>        fvrtA        jB                  |g      }t5        tE        ||jF                  |            |j0                  _        |jI                          tK        | jL                  | jN                  |       tQ        || jR                  | jL                  jT                        }tW        ||      }tY        |      }ddl-m.}m/} g }|j0                  j`                  D ]  }|jb                  dk(  st/        |jd                  d   tf              rwd }|jd                  d   jh                  '| jN                  |jd                  d   jj                     }n#|jd                  d   jh                  jl                  }|jo                  |       |jo                  |jd                  d           tq        |      }|5  ts        |      5   || jt                        5  tw        |      5  tA        jx                  ||jF                        } ||g |d   |d   j{                         i |      5 \  } }!}"}#}$ || |!|"||#|d|      }%|%jN                  j}                         D &'ci c]  \  }&}'|&t/        |'t~              r|$|'   n|' c}'}&|%_'        |%j                  }(|%j                  })t        |)|      })t        ||(|)       t        | jL                  |)      }) ||(|)|#      }*t        |(|)| |!|"||*       d d d        d d d        d d d        d d d        d d d         |
(        ||(        ||()       t        |(|)      \  }(})i | jR                  |j}                         D +,ci c]  \  }+},|+|vr|+|, c},}+}-|j}                         D ]J  \  }+},|+|-vr&t/        |,t        j                  j                        rJ |+|-v s5|+|vs:|-j                  |+       L |(|)|-fS | j(                  j0                  j`                  D cg c]  }|jb                  dk(  s| }.}|.D cg c]  }|jd                  d    }/}| j(                  j!                         D +0cg c]  \  }+}0|+	 }1}+}0|1D ]  }+t        | j(                  |+        t        |/      }2|2t        j                         n|2}3|rt        j                  n|}4 |	       5  |35  ts        |      5   |4       5   || j(                  |/||d u||nd       \  }(}5|(j0                  j                          d d d        d d d        d d d        d d d        d }6(j0                  j`                  D cg c]  }|jb                  dk(  s| }7}t?        |(j0                  j                         j                  d         }8t        |7      t        |.      k(  sJ t        |.|7      D ]  \  }9}:|9jj                  x|:_5        |:_T         i };t        t              }<t               }=|7D ]2  }>|>jj                  |;|>jj                  <   t        |>jj                  |<|=       4 |(j0                  j`                  D ]:  }|jb                  dk(  rt        |;|<|=|jj                  |jj                        |_5        < t        |(       ddl[m\}?m]}@ ddl^m_}A t        j                  j                  j                  s]d}Bt        |(      }C|CN @|(t        j                  |?dBi            5  t        |(Cdt        |(j0                         d
       d d d        |(jI                          t        |8 A|(            D ]  \  }D}+|+	|+D_5         t        | jL                  j                        D EFci c]C  \  }E}Ft/        |Fj                  t              s$Fj                  jj                  |7E   jj                  E }G}E}Ft        | jL                  j                        D EFcg c]E  \  }E}Ft        |Fj                   |6|Fj                  |7|E         |Fj                  |Fj                        G }H}E}Fg }It        5j                        D E+ci c]  \  }E}+|+|E
 }J}E}+t=        |5j                  j                               }K|K|8d t        |K       D cg c]  }|jj                   c}k(  sJ |5j                  j}                         D ]  \  }L}MJ|M   }E| jL                  j                  |E   }N|Nj                  t        j                  t        j                  fv sJ Nj                  t        j                  k(  rt        j                  nt        j                  }ONj                  t        j                  k(  rNj                  nNj                  jj                  }PIjo                  t        Ot        L      |P              t        | jL                  j                        D ]  \  }E}FIjo                  t        |E|k(  rt        j                  nFj                   |6Fj                  |8t        K      Ez            Gj                  |Fj                  |Fj                                      ||5j                  J |5j                  j                  }Qt        |5j                        t        | jL                  j                        k(  sJ t        | jL                  j                        D EFci c]/  \  }E}Ft/        |Fj                  t              r|5j                  E   F1 }R}E}F|8t        I      d  D ]  }Q|jj                     }SR|S   }F|Fj                  t        j                  k(  rt        j                   }TFj                  }PnJFj                  t        j                  k(  rt        j                  }TS}Pnt        dFj                         Ijo                  t        Tt        |jj                        P              t        |7      t        |.      k(  sJ t        HI      })t        |.|7      D ]  \  }U}Vt/        |Ujd                  d   t        j                        sUjd                  d   Vjd                  d<   Vj                  |)j
                  v sVj                  |)j                  v s}Ujd                  j}                         D ]  \  }W}X|XVjd                  |W<     |(|)| jR                  fS c c}'}&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c c},}+w c c}w c c}w c c}0}+w # 1 sw Y   -xY w# 1 sw Y   2xY w# 1 sw Y   7xY w# 1 sw Y   <xY wc c}w # 1 sw Y   dxY wc c}F}Ew c c}F}Ew c c}+}Ew c c}w c c}F}Ew )Nr   )_materialize_and_lift_constants)aot_export_module)2_disable_custom_triton_op_functional_decomposition_export_to_aten_ir_ignore_backend_decomps_verify_nn_module_stack_verify_placeholder_names_verify_stack_trace)ShapeEnvc                 >    |d uxs | j                   j                  d uS rP   )graph_signaturebackward_signature)r   r   s     rW   _is_joint_ir_decompzO_decompose_and_get_gm_with_new_signature_constants.<locals>._is_joint_ir_decomp\  s)    D( A!!44D@	
rY   F)remove_duplicate)!unwrap_tensor_subclass_parametersT)	shape_envexport)&_enable_graph_inputs_of_type_nn_module_fakify_script_objectsplaceholdervalr7   )r   _prettify_placeholder_namesdecompose_custom_triton_ops)decompositionstrace_jointoutput_loss_indexc                    t        | t              r| S t        | t              rt        |j                        S t        | t              rt	        |j                        S t        | t
              rt        |j                        S t        | t              rt        |j                        S t        dt        |              )NrQ   zType of old_arg not supported: )	
isinstancer9   rC   rQ   rB   rA   r@   RuntimeErrortype)old_argnew_phs     rW   
update_argzF_decompose_and_get_gm_with_new_signature_constants.<locals>.update_argZ  s    g/0N0!v{{330!v{{33!12#551"44<T']OLMMrY   )_node_metadata_hook_set_node_metadata_hook)_graph_output_nameszUFile "torch/fx/passes/runtime_assert.py", line 24, in insert_deferred_runtime_assertsstack_trace)metadatazexported program: )r   r   )kindargtargetzUnknown input kind: input_specsoutput_specs)(torch._export.passes.lift_constants_passr   torch._functorch.aot_autogradr   torch.export._tracer   r   r   r   r   r   %torch.fx.experimental.symbolic_shapesr   modulerv   named_parametersnamed_buffers7torch._functorch._aot_autograd.subclass_parametrizationr   r   graph_moduler   	_out_specr   graph_codegenr   pytree_info	orig_argsr   r]   tupler_   treespec_tupler   _in_spec	recompiler   r   	constantsr'   
state_dictnon_persistent_buffersr    r   torch._export.non_strict_utilsr   r   nodesr}   metar:   fake_valrQ   real_objappendr   r   example_inputsr   tree_unflattenvaluesr   r   gmsigr$   r&   r%   r*    _remove_unnecessary_copy_op_passr   nn	Parameterpopdelattrr-   
contextlibnullcontexteliminate_dead_codeoutput_noderh   lenzipr   r   intr   r   r(   r#   (torch._export.passes._node_metadata_hookr   r   4torch._functorch._aot_autograd.input_output_analysisr   _dynamoconfigdo_not_emit_runtime_asserts_get_shape_envrl   r   r   r   	enumerater   r   r9   r=   r   
persistentuser_inputsuser_inputs_to_mutater   r<   
USER_INPUTBUFFERr>   BUFFER_MUTATIONUSER_INPUT_MUTATIONr?   rC   r   LOSS_OUTPUTgetr   gradients_to_user_inputs	PARAMETERGRADIENT_TO_PARAMETERGRADIENT_TO_USER_INPUTAssertionErrorr;   Tensorinputs_to_parametersinputs_to_buffers)Yr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   modwrapped_params_buffersr   unwrapped_params_buffers	fake_moderM   orig_arg_namestemp_registered_constantsfake_params_buffersparams_buffers_to_node_metar   r   retracing_argsnodereal_script_objtxretracing_args_unwrappedpatched_modnew_fake_argsnew_fake_kwargsnew_fake_constant_attrsmap_fake_to_realaten_export_artifactrd   objr   new_graph_signaturer   rQ   pnew_state_dictold_placeholders	fake_args_buffers_to_removefake_mode_detfake_mode_ctx#custom_triton_ops_decomposition_ctxr   r   new_placeholdersnew_outputsold_phr   name_mapfind_available
used_namesphr   r   r   r   r   outputrU   specold_new_placeholder_mapr   r   user_inputs_indexmutation_namesoutput_name
input_name
input_specoutput_kindr   	gradientsspecssourcer   old_noderT   r   vsY                                                                                            rW   2_decompose_and_get_gm_with_new_signature_constantsrL  H  sV    Y?  ?
 r#34iik"
3'''?@"
3$$e$<="

	
 	*#.$
3'''?@$
3$$e$<=$
  .boo>	&DII ==#)),,n===++77AA ###==u-,,hZ8H+
		 	
 	((:(:BLL#N %C 2 2 I I%
!
 5YD&DS&I#
	

 IIOO 
	<Dww-'dii.0AB&*Oyy'008*,,,tyy7G7L7L*M*.))E*:*C*C*L*L"))/:"))$))E*:;
	< I& P	/P	
 323D3DEP	 BKP	 (.'<'<($ (-a0-a0779  D' '9!#'+!4050K	($$ %9$B$B$H$H$J2 !S %c+;< )- !2$. *,,&:&>&>#
 L+-F $ :/5H
 'V&&(;'# <+-D	 ('!#'yDP	 P	 P	 P	d 	 #B!"&9:"B##

mm
  8==?D!55 a
 .335 	-GD!>)%a););<<<~%77"&&t,	- &66 ..44=8P  /??d5!?I?-/__-J-J-LM'$MM! '&' %Y/M0=0EJ**,=M ' 	? ( 	 !'' 	,M:' 	,-	' 0OO.(4$4$@ d
O 	$$&' ' ' '&N *,T477m;STT-22883G3G3I3N3Nq3Q-RK  C(8$9999.0@A 2&,kk1fm2 H%0%5N5J :GGRWWnj9:  
77m#.nj$))TYY
	
 $B' Y==;;1 	 #2&	 (!!'=+2N  0()LRXX)V(WX	 LLNK)<R)@A FK !!3!3!?!?@At$(($45 	'*///  !!3!3!?!?@ At 	IItxx!1!!45KKOO		
K  L 1:/:U:U0VWWQqWW/??DDFGNK@U#nBU4VWDdiiWWWW#2#H#H#N#N#P 
Zj)''33A6
9#7#79I9I"JJJJ )"2"22 &&// 	 )"2"22 $$ 	
 	 "4	

. R//<<= 
4*+/?*?
&&TYY488[^1Dq1H%IJ'++DKKE	

 #11===#66OO	?../3r7I7I7U7U3VVVV %R%7%7%C%CD
4$((N3 ''*D0
 

  L 1 34 	Dtyy)F=DyyI///!77i222!88$';DII;%GHH"		2	&  C(8$9999.l ""24DE 	%((--.=#+==#7HMM%  OO2GGG"5"G"GG ++- %1#$a %	% "BMM11K	27D DP	 P	 P	 P	 P	 P	 P	 P	F$ @M' ' ' ' ' ' ' '@ UP *" XWJ
s*  yy*y6Ax7	;4x*/"x$A+x*<x7	yyy,y+y1y1%y6y;z(zz;z	zz&z(z5&z52&z:6A{#A
{
{{4{$x**x4/x7	7y<yy	yy	yy(zzzzz%	 z((z2:{r   r-  c                    | j                  |j                               5  | j                  j                  D ]  }|j                  dk(  st        j                  |j                        \  }}|D ]  }t        |t        j                  j                        s(|j                  |j                  v s|j                  |j                  v sY|j                  dk(  si|j                  t        j                   j"                  j$                  j&                  u s|j)                  |j                  d          | j                  j+                  |         | j-                          ddd       | |fS # 1 sw Y   | |fS xY w)zQ
    Removes redundant copy_ node that was introduced due to mutated buffer.
    r>  call_functionr7   N)_set_replace_hookget_replace_hookr   r   r}   r_   tree_flattenrh   r   r   fxNoderQ   buffers_to_mutateparameters_to_mutater   opsr   r   defaultrX   
erase_noder   )r   r-  r"  rh   r2  outs         rW   r   r     s+    
		1BBD	E HHNN 	5Dww(" --dii8a 
5C!#uxx}}5$7$I$II88':'O'OO  FFo5 #

eiinn.A.A.I.I I55chhqkBHH//4
5	5 	  """!  """s+   *E-AE-0E-E-:E-AE--E9c           	         | j                  |j                               5  | j                         D ]  }t        |t        j
                  j                        s)i }i }t        |j                  j                        D ]  }|j                  dk(  r|j                  t        j                  u r|j                  \  }}||    d| }	|	|v rc|j                  ||	          |D ].  }
|
j                   |
j                   j                  |||	          0 |j                  j#                  |       |||	<   |	||<   |j$                  ||<     	 d d d        y # 1 sw Y   y xY w)NrN  .)rO  rP  modulesr   r   rR  GraphModuler]   r   r   r}   r   operatorgetitemrh   rX   re   rX  rQ   )r   r   module_call_graphr   node_idgetitemsr"  rI  idxnew_identrys              rW    _common_getitem_elimination_passrf  )  sG    
		o>>@	A .jjl 	.Ffehh&:&:;02G13HV\\//0 .77o-$++AQAQ2Q"&))KFC '0#7F)228F3CD%6 "E$: % E E$((6*:!""
 //5+/((.$(IIGDM!.	.. . .s   CE.AEEold_gmold_graph_signaturer   old_module_call_graphc                    t        j                  |      }| j                  j                  D ci c]  }|j                  | }}i j
                  j                  i |j
                  |j                  }i }	d}
| j                  j                  D cg c]  }|j                  dk(  s|j                    }}t        t        fd|            }|j                  j                  D cg c]  }|j                  dk(  s|j                    }}|j                  j                  D ]  }|j                  j                  dg       x}r|j                  |	|d   j                  <   >|j                  dk(  sN|j                  |v r]|j                  |j                  v rv|j                  |v st        |j                  t              sJ ||
   }t        |t              sJ |j                  |	|<   |
dz  }
 t!        t              }|j#                         D ]X  \  }}|j%                  d      s|v s||	|<   "dj'                  |j)                  d      dd       }||   j+                  |       Z |D ]x  }|j,                  }|g |j.                  |j0                  D ]H  }|j                  |v rt3        d	|j                   d
      |j                  |	v r|	|j                     |_        N|j                  |v s]||j                     }|j                  dk(  s||j                  t4        j6                  j8                  j:                  j<                  t4        j6                  j8                  j:                  j>                  t4        j6                  j8                  j:                  j@                  fv s|jB                  d   j                  }||	vrt3        d	| d
      |	|   |_        K { |S c c}w c c}w c c}w )Nr   r   c                 ,    | vxr | j                   vS rP   )input_tokens)xold_graph_params_buffersrh  s    rW   <lambda>z0_get_updated_module_call_graph.<locals>.<lambda>d  s$    a77 :,999 rY   	from_noder7   zparametrizations.r[  zIt looks like z is a tensor subclass. Preserving submodule that takes subclass parameter is not supported in inference IR because we desugar them, resulting in more tensorsrN  )"r   deepcopyr   r   rQ   r  r  r}   r   r]   filterr   r  rl  r   ra   r   r   r   joinsplitr   re   rJ   rK   
ValueErrorr   rV  r   todtype_layoutdevicedtyperh   )rg  rh  r   r   ri  new_module_call_graphr"  	old_nodesnew_graph_params_buffers
provenanceuser_input_counterold_user_input_namesnew_user_input_nameshistoryold_nameold_param_to_desugaredrQ   r   
old_targetre  re   rm  rJ  rn  s    `                     @rW   _get_updated_module_call_graphr  F  s    !MM*?@-3\\-?-?@TD@I@ 

2
2 

/
/  

.
. 

+
+  "$J & 2 2dgg6N   : 	
 !#$'']2J   ,iimmK4474+/99Jwr{''(
 WW%77;;/">">>;;"66%dii55534FGH%h444+/99Jx(&!+&#,, ).0668 <f  !45//#'
4 &,,s"3Ab"9:J":.55d;< ' '4OO	89##8i&7&78 #	4A vv// $QVVH -Z [  vv##AFF+ 9$$QVV,;;/1hooIINN%%22IINN%%,,IINN%%++J 7
 "*q!1!6!6J!3(,ZL 9b c  (
3AFG#	4	'4R ! S A s   O/O4+O4,O9O9r   c          
      t   t        | ||||      \  }}}t        | j                  | j                  ||| j                        }|j
                  j                  | j                  j
                         t        || j                        }	t        ||j                  |||	|| j                  | j                        }
|
S )Nr   r   r   r   )rootr   r   r   range_constraintsr`  r   r   )rL  r  r   r   r`  r   r   _get_updated_range_constraintsr  rE   r   r   r   )r   r   r   r   r   r   r-  r   r{  new_range_constraintsexported_programs              rW   _decompose_exported_programr    s     	;
#/)$?		
 ;



 GGNN2??''(:


 'hh+//((,,	 rY   c                   	   e Zd ZU dZej
                  j                  ed<   	 eed<   	 e	e
ef   ed<   	 ded<   	 ee   ed<   	 eeedf   e	e
ef   f   d	z  ed
<   	 e	e
ef   ed<   	 eee      ed<   	 ee
   ed<   	 	 dMd	ddej$                  j&                  e	e
ef   z  dej
                  j(                  dede	e
ej*                  ej$                  j,                  z  f   dddee   deeedf   e	e
ef   f   d	z  de	e
ef   d	z  deee      d	z  fdZe ed      d               Zej6                   ed      d               Ze ed      d               Zej6                   ed      d               Ze ed      d                Zej6                   ed      d!               Ze ed      d"               Zej6                   ed      d#               Z ed      d$eej$                  j,                     fd%       Z  ed      d$eee
ej$                  j,                  f      fd&       Z! ed      d$eej*                     fd'       Z" ed      d$eee
ej*                  f      fd(       Z#e ed      d)               Z$e$j6                   ed      d*               Z$e ed      d+               Z%e%j6                   ed      d,               Z%e ed      d-               Z&e&j6                   ed      d.               Z&e ed      d/               Z'e'j6                   ed      d0               Z'e ed      d$efd1              Z(e(j6                   ed      d2               Z(e ed      d$e
fd3              Z)e)j6                   ed      d4               Z)e ed      d5               Z*e*j6                   ed      d6               Z*e ed      d7               Z+e+j6                   ed      d8               Z+e ed      d9               Z,e,j6                   ed      d:               Z,d; Z-d<ed=ed$efd>Z.d<ed=ed$efd?Z/d$e
fd@Z0dNd$ej
                  j                  fdAZ1dB Z2e3	 	 dOdCe	ejh                  jj                  e6f   d	z  dDe7d$d fdE       Z8dFe9d$d fdGZ:dH Z; ed      dI        Z<e=dJ        Z>d	d	d	dK	 dPdLZ?y	)QrE   a  
    Package of a program from :func:`export`. It contains
    an :class:`torch.fx.Graph` that represents Tensor computation, a state_dict containing
    tensor values of all lifted parameters and buffers, and various metadata.

    You can call an ExportedProgram like the original callable traced by
    :func:`export` with the same calling convention.

    To perform transformations on the graph, use ``.module`` property to access
    an :class:`torch.fx.GraphModule`. You can then use
    `FX transformation <https://pytorch.org/docs/stable/fx.html#writing-transformations>`_
    to rewrite the graph. Afterwards, you can simply use :func:`export`
    again to construct a correct ExportedProgram.
    _graph_module_graph_signature_state_dictzdict[sympy.Symbol, ValueRanges]_range_constraints_module_call_graph.N_example_inputs
_constants
_verifiers_guards_code)	verifiersr  r   r   r   r  dict[sympy.Symbol, Any]r`  r   r   r  c	                X   t         j                  j                  j                         |_        t        ||      | _        t        |t         j                  j                        r/| j                  j                  j                  |j                         t        | j                  ||       || _        || _        || _        |J || _        || _        |xs i | _        |	xs t$        g}	t'        d |	D              sJ |	| _        | j+                          t-        | j                        | _        y )Nc              3   <   K   | ]  }t        |t                y wrP   )ru   r+   ).0rK  s     rW   	<genexpr>z+ExportedProgram.__init__.<locals>.<genexpr><  s     >q:a*>s   )r   rR  r   CodeGenr   _create_graph_module_for_exportr  r   r]  r   r   rf  r  r  r  r  r  r  r+   allr  validate_convert_guards_to_coder  )
rR   r  r   r   r   r  r`  r   r   r  s
             rW   __init__zExportedProgram.__init__  s     //1<T5IdEHH001##**4995(1B	
 7F+5CT ,,,9J-#/r+(	>I>>>>#3D4F4FGrY   F)is_backward_compatiblec                     | j                   S rP   )r  rR   s    rW   r   zExportedProgram.graph_moduleC  s     !!!rY   c                     t        d      )Nz7Unable to set ExportedProgram's graph_module attribute.r   rR   values     rW   r   zExportedProgram.graph_moduleH  s     TUUrY   c                 .    | j                   j                  S rP   )r   r   r  s    rW   r   zExportedProgram.graphM  s       &&&rY   c                     t        d      )Nz0Unable to set ExportedProgram's graph attribute.r  r  s     rW   r   zExportedProgram.graphR  s     MNNrY   c                     | j                   S rP   )r  r  s    rW   r   zExportedProgram.graph_signatureW  s     $$$rY   c                     t        d      )Nz:Unable to set ExportedProgram's graph_signature attribute.r  r  s     rW   r   zExportedProgram.graph_signature\  s     WXXrY   c                     | j                   S rP   )r  r  s    rW   r   zExportedProgram.state_dicta  s     rY   c                     t        d      )Nz5Unable to set ExportedProgram's state_dict attribute.r  r  s     rW   r   zExportedProgram.state_dictf  s     RSSrY   rs   c              #   D   K   | j                         D ]	  \  }}|  yw)zH
        Returns an iterator over original module's parameters.
        N)r   )rR   r2  params      rW   
parameterszExportedProgram.parametersk  s)     
 --/ 	HAuK	    c              #   h   K   | j                   j                  D ]  }|| j                  |   f  yw)z
        Returns an iterator over original module parameters, yielding
        both the name of the parameter as well as the parameter itself.
        N)r   r  r   )rR   
param_names     rW   r   z ExportedProgram.named_parameterss  s7      ..99 	:Jdooj999	:s   02c              #   D   K   | j                         D ]	  \  }}|  yw)zC
        Returns an iterator over original module buffers.
        N)r   )rR   r2  bufs      rW   bufferszExportedProgram.buffers|  s)     
 ((* 	FAsI	r  c              #      K   t        | j                  j                        }| j                  j                  D ]-  }||v r|| j                  |   f || j
                  |   f / yw)z
        Returns an iterator over original module buffers, yielding
        both the name of the buffer as well as the buffer itself.
        N)r   r   r   r  r   r   )rR   r   buffer_names      rW   r   zExportedProgram.named_buffers  sm      "%T%9%9%P%P!Q//77 	@K44!4>>+#>>>!4??;#???		@s   A'A)c                     | j                   S rP   )r  r  s    rW   r  z!ExportedProgram.range_constraints       &&&rY   c                     t        d      )Nz<Unable to set ExportedProgram's range_constraints attribute.r  r  s     rW   r  z!ExportedProgram.range_constraints       J
 	
rY   c                     | j                   S rP   )r  r  s    rW   r`  z!ExportedProgram.module_call_graph  r  rY   c                     t        d      )Nz<Unable to set ExportedProgram's module_call_graph attribute.r  r  s     rW   r`  z!ExportedProgram.module_call_graph  r  rY   c                     | j                   S rP   )r  r  s    rW   r   zExportedProgram.example_inputs  s     ###rY   c                    ||| _         y t        |t              r4t        |      dk(  r&t        |d   t              rt        |d   t              st        d      |\  }}ddlm}  |||| j                  j                         || _         y )N   r   r7   zqExample inputs should be a tuple containing example arguments (as a tuple), and example kwargs (as a dictionary).)_check_inputs_match)
r  r   r   r   rv   rv  _unliftr  	call_specrL   )rR   r  rh   ri   r  s        rW   r   zExportedProgram.example_inputs  s    
 =#(D  ue$E
a58U+58T*B 
 f0D&$..*@*@A$rY   c                 8    G d dt               }t        | j                        dk(  r
 |d d       S | j                  d   j                  dk(  sJ  || j                  d   j                  j
                  | j                  d   j                  j                        S )Nc                   V    e Zd ZU ej                  dz  ed<   ej                  dz  ed<   y)+ExportedProgram.call_spec.<locals>.CallSpecNrL   rM   )rZ   r[   r\   r_   r`   r^   rb   rY   rW   CallSpecr    s     __t++oo,,rY   r  r   )rL   rM    )r	   r   r`  rd   re   rL   rM   )rR   r  s     rW   r  zExportedProgram.call_spec  s    	-z 	- t%%&!+D488%%a(,,222**1-77??++A.88AA
 	
rY   c                     t        d      )Nz4Unable to set ExportedProgram's call_spec attribute.r  r  s     rW   r  zExportedProgram.call_spec       QRRrY   c                      | j                   d   S Nr   r  r  s    rW   verifierzExportedProgram.verifier  s     q!!rY   c                     t        d      )Nz3Unable to set ExportedProgram's verifier attribute.r  r  s     rW   r  zExportedProgram.verifier  s     PQQrY   c                 P    | j                   J | j                   d   j                  S r  )r  dialectr  s    rW   r  zExportedProgram.dialect  s)     ***q!)))rY   c                     t        d      )Nz2Unable to set ExportedProgram's dialect attribute.r  r  s     rW   r  zExportedProgram.dialect  s     OPPrY   c                     | j                   S rP   r  r  s    rW   r  zExportedProgram.verifiers       rY   c                     t        d      )Nz4Unable to set ExportedProgram's verifiers attribute.r  r  s     rW   r  zExportedProgram.verifiers  r  rY   c                     | j                   S rP   r  r  s    rW   tensor_constantsz ExportedProgram.tensor_constants  r  rY   c                     t        d      )Nz;Unable to set ExportedProgram's tensor_constants attribute.r  r  s     rW   r  z ExportedProgram.tensor_constants  s     I
 	
rY   c                     | j                   S rP   r  r  s    rW   r   zExportedProgram.constants  r  rY   c                     t        d      )Nz4Unable to set ExportedProgram's constants attribute.r  r  s     rW   r   zExportedProgram.constants  r  rY   c                     | j                   j                  }|t        ||      }t        j                  ||f      \  }}| j                  |       t        d |D              }||fS )a  Flatten args, kwargs using pytree, then, check specs.

        Args:
            args: List[Any] original args passed to __call__
            kwargs: Dict[str, Any] original kwargs passed to __call

        Returns:
            A tuple of (flat_args, received_spec)
            flat_args is flattened args / kwargs
            received_spec is the pytree spec produced while flattening the
            tuple (args, kwargs)
        c              3   &   K   | ]	  }|d      yw)r7   Nrb   )r  rm  s     rW   r  z<ExportedProgram._get_flat_args_with_check.<locals>.<genexpr>&  s     <1!A$<s   )r  rL   r1   r_   tree_flatten_with_path_check_input_constraintsr   )rR   rh   ri   rL   flat_args_with_pathreceived_spec	flat_argss          rW   _get_flat_args_with_checkz)ExportedProgram._get_flat_args_with_check  so     ..((#FG4F-3-J-J6N.
*] 	%%&9:<(;<<	-''rY   rh   ri   c                    | j                   j                  }| j                  ||      \  }}|"t        ||t              st        d| d|       g }| j                  j                  D ]  }|j                  t        j                  k(  r"|j                  t        j                  t        j                  fv r`|j                  du r)|j                  | j                  |j                             |j                  | j"                  |j                             |j                  t        j$                  t        j&                  fv s|j                  | j                  |j                              t)        |      }||z   S )a,  Transform args, kwargs of __call__ to args for graph_module.

        self.graph_module takes stuff from state dict as inputs.
        The invariant is for ep: ExportedProgram is
        ep(args, kwargs) ==
          ep.postprocess(ep.graph_module(ep.graph_module_flat_inputs(args, kwargs)))
        z>Trying to flatten user inputs with exported input tree spec: 
z-
but actually got inputs with tree spec of: 
F)r  rL   r  r0   rw   rv  r   r   r   r<   r  r  r  r  r   r   r   r   CONSTANT_TENSOR
CUSTOM_OBJr   )rR   rh   ri   rL   r  r  additional_inputsinput_s           rW   _graph_module_flat_inputsz)ExportedProgram._graph_module_flat_inputs)  sf    ..((#'#A#A$#O 	=}7$A(
 Q) @ /#  **66 	HF{{i222##  !  $$- &,,T^^FMM-JK%,,T__V]]-KL))$$!  "(()FG#	H$ ""34 !9,,rY   c                     t        d      )Nz\Unable to call ExportedProgram directly. You should use `exported_program.module()` instead.r  )rR   rh   ri   s      rW   __call__zExportedProgram.__call__W  s    B
 	
rY   c                     | j                   j                  dd      j                  dd      }t        | j                        j                  dd      }d| d| d| j
                   d}|S )NF)print_outputcolored
z
    zExportedProgram:
    z
Graph signature: z
Range constraints: )r   print_readablereplacera   r   r  )rR   r   r   strings       rW   __str__zExportedProgram.__str__]  s    ((77 8 

'$
! 	 d223;;D(K. !  /0 1""&"8"8!9= 	 rY   c                     ddl m}  || |      }ddt        fd}ddt        fd}t        j                  ||      |_        t        j                  ||      |_        |S )a  
        Returns a self contained GraphModule with all the parameters/buffers inlined.

        - When `check_guards=True` (default), a `_guards_fn` submodule is generated
          and a call to a `_guards_fn` submodule is inserted right after placeholders
          in the graph. This module checks guards on inputs.
        - When `check_guards=False`, a subset of these checks are performed by a
          forward pre-hook on the graph module. No `_guards_fn` submodule is generated.

        r7   )&_unlift_exported_program_lifted_states)check_guardsmodec                     t        d      )Nz%Calling train() is not supported yet.NotImplementedErrorrR   r  s     rW   _trainz&ExportedProgram.module.<locals>._trainy  s    %&MNNrY   c                     t        d      )Nz$Calling eval() is not supported yet.r  r   s     rW   _evalz%ExportedProgram.module.<locals>._eval|  s    %&LMMrY   T)r  r  booltypes
MethodTypetraineval)rR   r  r  r   r  r  s         rW   r   zExportedProgram.modulej  s_     	D7<X	Ot 	O	Nd 	N ''7&&uf5rY   c                     t        d t        | j                  j                        D        t	        | j                  j                              S )Nc              3   `   K   | ]&  \  }}|j                   t        j                  k(  r| ( y wrP   )r   r<   r  )r  rU   ss      rW   r  z=ExportedProgram._num_lifted_params_buffers.<locals>.<genexpr>  s.      Aq66Y111 s   ,.)nextr  r  r   r   r  s    rW   _num_lifted_params_buffersz*ExportedProgram._num_lifted_params_buffers  sC    %d&;&;&G&GH
 %%112
 	
rY   r   r   c                     |
t               n
t        |      }t        |t              r|j	                         }t        |      \  }}t        | ||d|      S )a  
        Run a set of decompositions on the exported program and returns a new
        exported program. By default we will run the Core ATen decompositions to
        get operators in the
        `Core ATen Operator Set <https://pytorch.org/docs/stable/torch.compiler_ir.html>`_.

        For now, we do not decompose joint graphs.

        Args:
            decomp_table:
             An optional argument that specifies decomp behaviour for Aten ops
             (1) If None, we decompose to core aten decompositions
             (2) If empty, we don't decompose any operator


        Some examples:

        If you don't want to decompose anything

        .. code-block:: python

            ep = torch.export.export(model, ...)
            ep = ep.run_decompositions(decomp_table={})

        If you want to get a core aten operator set except for certain operator, you can do following:

        .. code-block:: python

            ep = torch.export.export(model, ...)
            decomp_table = torch.export.default_decompositions()
            decomp_table[your_op] = your_custom_decomp
            ep = ep.run_decompositions(decomp_table=decomp_table)
        Nr  )rH   rv   r   r3   materializer   r  )rR   r   r   _decomp_tabler   r   s         rW   run_decompositionsz"ExportedProgram.run_decompositions  sk    P )5(<"$$|BT 	 m%67)557M" 9G	
 +' 3!(C
 	
rY   passesc                 T   t        t        |            }ddlm}  |       5   || j                        }d d d        |j                  n| j                  }|J || j                  u r|j
                  s| S dt        dt        j                  j                  dt        fd}t        ||j                   || j                  |      | j                  t        || j                        t!        j"                  | j$                        | j&                  | j(                  | j*                  	      }|j                  j,                  j/                  | j                  j,                         |j                  j,                  j/                  |j                  j,                         |S # 1 sw Y   jxY w)Nr   )r   old_signaturenew_gmrs   c           	         g }t        |j                  j                        D ]  \  }}|j                  dk7  r n|t	        | j
                        k  sJ d       | j
                  |   }t        |j                  t        t        f      r|j                  n$ t        |j                        |j                        }|j                  t        |j                  ||j                  |j                                 t#        |j                  j                        d   }|j                  dk(  sJ g }t        |j$                  d         D ]  \  }}|t	        | j&                        k  sJ d       | j&                  |   }	t        |	j                  t        t        f      r|	j                  n$ t        |	j                        |j                        }|j                  t)        |	j                  ||	j                                t+        ||      }
|
S )zO
            Update the graph signature's user_input/user_outputs.
            r   z-Number of inputs changed after transformationrq  r>  r   z.Number of outputs changed after transformationr   )r  r   r   r}   r   r   r   r   r9   r:   r   rQ   r   r=   r   r   r  r]   rh   r   r?   r;   )r  r  new_input_specsrU   r"  old_input_specr   r   new_output_specsold_output_specnew_signatures              rW   _get_updated_graph_signaturezKExportedProgram._transform_do_not_use.<locals>._get_updated_graph_signature  s     !O$V\\%7%78 477m+3}8899 C9 "/!:!:1!= "&**-=?P,Q #&& 2n001$))<   &&&++&--&11	0 v||11226K>>X---!$[%5%5a%89 43}99:: D: #0"<"<Q"? "'++.>@Q-R $'' 3o112499=  !''33S/:P:PQ  1+:JM ! rY   	r  r   r   r   r  r`  r   r   r  )r6   r]   r   r   r   modifiedr;   r   rR  r]  rE   r   r   r   r  r  r   rr  r  r   r   r  r   r   )rR   r  pmr   restransformed_gmr  transformed_eps           rW   _transform_do_not_usez%ExportedProgram._transform_do_not_use  sq   f& 	@$& 	(T&&'C	(-0_))$BSBS))) T...s||K7	!/7	!HH((7	! "7	!r ) &&8$$n <&& #mmD,C,CD..nnnn
  	##((//0A0A0F0FG##((//0@0@0E0EFm	( 	(s   FF'c                 R   ddl m} | j                  j                  D cg c]  }|j                  dk(  s| }}t        || j                  j                        D cg c]$  \  }}|j                  t        j                  k(  r|& }}} |||| j                         y c c}w c c}}w )Nr   )"_check_input_constraints_for_graphr   )torch._export.utilsr&  r   r   r}   r   r   r   r   r<   r  r  )rR   r  r&  r.  placeholdersr  input_placeholderss          rW   r  z(ExportedProgram._check_input_constraints2  s    J#'::#3#3Maqtt}7LMM L$*>*>*J*JK
1vv--- 
 

 	+ 3T5K5K	
 N
s   BB)B#c                 $    | j                          y rP   )	_validater  s    rW   r  zExportedProgram.validate?  s    rY   c                     t        | j                        dkD  sJ d       | j                  D ]  } |       j                  |         y )Nr   z0ExportedProgram must have at least one verifier.)r   r  check)rR   rK  s     rW   r+  zExportedProgram._validateD  sE    4>>"Q& 	
>	
&  	ACIIdO	rY   )r   r   r  c                $   t        ||j                  |||n| j                  t        j                  | j
                        t        j                  | j                        | j                  ||n| j                  ||	      S | j                  	      S )Nr  )
rE   r   r   r   rr  r  r  r   r   r  )rR   r   r   r   r   r  s         rW   _updatezExportedProgram._updateM  s     $$+%/%;z"mmD,B,BC"mmD,C,CD..#,#8idnn#,#8i

 
	
 ?Cnn

 
	
rY   )NNr  )NF)rs   rE   )@rZ   r[   r\   __doc__r   rR  r]  r^   r;   rv   ra   r   r]   rF   r   r   r   r+   r   ModuleGraphr  r   r  propertyr4   r   setterr   r   r   r   r  r   r  r   r  r`  r   r  r  r  r  r  r   r  r  r  r  r   r  rn   _opsOperatorBaser   r  r  PassTyper$  r  r  r   r+  r/  rb   rY   rW   rE   rE     sE    88'''O**Mc3hU99E_--J5c?DcN:;dBBLS0011:T(^$$Is) IM>B%H 26%HhhooS#X.%H xx~~%H .	%H
 ellUXX-?-???@%H 5%H  0%H eCHotCH~=>E%H 334t;%H X'$.%HN %0" 1 " %0V 1 V %0' 1 ' \\%0O 1 O %0% 1 % %0Y 1 Y %0  1   %0T 1 T %0HUXX%7%78  1 %0:(5ehh6H6H1H+I"J : 1: %0%,,/  1 %0
@xc5<<.?(@A 
@ 1
@ %0' 1 ' %0
 1 

 %0' 1 ' %0
 1 

 %0$ 1 $ %0% 1 %2 %0
 1 
 %0S 1 S %0"# " 1 " __%0R 1 R %0* * 1 * ^^%0Q 1 Q %0 1  %0S 1 S %0 1  %0
 1 

 %0 1  %0S 1 S(.,-c ,-3 ,-3 ,-\
c 
S 
S 
 588+?+? 2
 $ HL,1D
5::22H<=DD
 &*D
 
	D
 $D
L\X \:K \|
 %0 1   
 

rY   c                 P   | j                   j                  D cg c]-  }|j                  j                  dd       |j                  d   / }}ddlm}  ||      }||j                  S |D ]4  }t        |t        j                        s|j                  j                  c S  y c c}w )Nr   r   r,   )r   r   r   r  torch._guardsr-   r   r   r   SymIntr"  )r   r"  valsr-   r  rK  s         rW   r  r  c  s     HHNN99==%1 			%D 
 / &I""" $a&66###$s   2B#old_range_constraintszdict[sympy.Symbol, Any] | Noner  c                 <   |J t        |       }|i S t        j                  |      }|j                         D ci c]  \  }}||j                  vs|| }}}|j                  j                         D ]  \  }}||j                  vs||vs|||<     |S c c}}w rP   )r  r   r   replacementsvar_to_range)r   r<  r   r  r   rK  s         rW   r  r  s  s     !,,,r"I			"78*002Aay?U?U6U1  &&,,. %1I***q8I/I#$a % s   BBc                    	 t         j                  j                  | |      }|S # t        $ r^ t	        j
                  dd       t         j                  j                  | t         j                  j                               }||_        Y |S w xY w)NzUnable to execute the generated python source code from the graph. The graph module will no longer be directly callable, but you can still run the ExportedProgram, and if needed, you can run the graph module eagerly using torch.fx.Interpreter.r  )
stacklevel)r   rR  r]  SyntaxErrorwarningswarnr2  _graph)r  r   r   s      rW   r  r    s}    XX!!$." I!   	G 	
 XX!!$(89	I!s    $ A#B
Bc                 (   t        |       }|g S |j                  j                         D ch c]  \  }}t        d |D              r| }}}t        j
                  j                  j                  j                  |j                  d |j                        }|j                  D cg c]B  }|j                  j                  j                  |      r|j                  |j                        D }}|D cg c]	  }d|vs| c}S c c}}w c c}w c c}w )Nc              3   z   K   | ]3  }t        |t        j                  j                  j                          5 y wrP   )r   r   r  rI  ConstantSource)r  rI  s     rW   r  z*_convert_guards_to_code.<locals>.<genexpr>  s2      
 65==#7#7#F#FGG
s   9;c                     | j                   S rP   r   )r  s    rW   ro  z)_convert_guards_to_code.<locals>.<lambda>  s
    AFF rY   z	L['self'])r  var_to_sourcesr   r  r   rR  experimentalsymbolic_shapesShapeGuardPythonPrinterguardsexprfree_symbolsissubsetdoprint)r   r   varsources
local_vars
py_printerguardrets           rW   r  r    s
   |,I	 &44::<C 
!
 
 	J  &&66NN  "2I4L4LJ
 %%::""++J7 	5::&C   #?ek&>E??% @s   D&AD
3	D=D)rs   r3   rP   )r   r   dataclassesrl   r^  r  rC  collectionsr   collections.abcr   r   r   typingr   r   r	   r
   r9  r   r   torch._higher_order_ops.utilsr   "torch._library.fake_class_registryr   torch._subclasses.fake_implsr   r   r   torch._subclasses.fake_tensorr   torch.fx._symbolic_tracer   torch.fx._utilsr   torch.fx.graphr   r   torch.fx.immutable_collectionsr   r   torch.fx.passes.runtime_assertr   sympytorch.utils._sympy.value_rangesr   r   torch.utils._pytreeutils_pytreer_   r'  r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   torch._export.verifierr+   r-   r/   torch.export._tree_utilsr0   r1   torch.export.decomp_utilsr3   torch.fx._compatibilityr4   torch.fx.passes.infra.pass_baser5   "torch.fx.passes.infra.pass_managerr6   r   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   __all__rR  r]  r7  	dataclassrG   rF   rn   r   Contextr  rw   r   r   AutogradCPUAutogradCUDAAutogradMetaAutogradXLAAutogradLazyAutogradIPUAutogradXPUAutogradMPSAutogradHPUAutogradPrivateUse1AutogradPrivateUse2AutogradPrivateUse3r   CPUCUDAMetaXLALazyIPUXPUMPSHPUr   r   rv   r5  r6  r   r   rH   r   rL  r   rf  r]   r  r  rE   r  r  r  r  rb   rY   rW   <module>r     s          # . % 8 8 1 B ? 
 9 ; ? 6 I J 
 ;  $ $    $ , * @ B 7 1 6 :   " UXX))*J,==> ' ' '  1 1 1
GtG>>G tG >>	G
 
G: 
HH$$	HH%%	HH%%	HH$$	HH%%	HH$$	HH$$	HH$$	HH$$	HH,,	HH,,	HH,,, (, 
HH	HH	HH	HH	HH	HH	HH	HH	HH
  P$ P$f)-uzz..89)-
4

''12C78)-XE2E2 

//9:E2 ejj55x?@	E2
 DjE2P##3G#
588!556#2..:r!HH  r!-r! 	r! *	r!
  0r!j4 

//9:4 ejj55x?@	4
 Dj4 "&4nn	
 n	
b$$ ?C; .,@rY   