
    &Vji                    :   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dl mZ d dlmZmZmZ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l0Z0d dl1m2c m3Z4 d dl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZE d dlFmGZG d dlmHZH d dlmIZI d dlJmKZKmLZL d dlMmNZN d dlOmPZP d dlQmRZR d dlSmTZT ddlUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb g dZcee0jd        je        geeR         f         Zfejg         G d d                      Zhejg         G d d                       Zid! Zjd"eek         d#e4jl        d$eek         d%e4jl        d&emf
d'Zne0jo        jp        jq        e0jo        jp        jr        e0jo        jp        js        e0jo        jp        jt        e0jo        jp        ju        e0jo        jp        jv        e0jo        jp        jw        e0jo        jp        jx        e0jo        jp        jy        e0jo        jp        jz        e0jo        jp        j{        e0jo        jp        j|        gZ}e0jo        jp        j~        e0jo        jp        j        e0jo        jp        j        e0jo        jp        j        e0jo        jp        j        e0jo        jp        j        e0jo        jp        j        e0jo        jp        j        e0jo        jp        j        g	Zed(             Zd)ee0j        j        ef         d&eee0j        j        ef         d*f         fd+ZdGd-Zd.d/d0ee0j        j        ef         d1ee0j        j        ef         d2ee         fd3Zd4e0jd        je        d5eYd&ee0jd        je        eYf         fd6Zd4e0jd        je        fd7Zd8e0jd        je        d9eYd4e0jd        je        d:eYd;eei         f
d<Zd0ee0j        j        ef         d1ee0j        j        ef         d2ee         d=emfd>Z G d? d/          Zd@ Z	 dHd4e0jd        je        dAdBd&dCfdDZdE ZdF ZdS )I    N)defaultdict)Iterator)contextmanager)AnyCallablefinal
NamedTupleOptionalTYPE_CHECKINGUnion)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e
                  ed<   d ZdS )rI   inputsoutputsin_specout_specNforward_arg_namesc                     | j         D ]}|j        |j        k    r|j        |_        | j        D ]}|j        |j        k    r|j        |_        d S N)rL   namerM   )selforiginal_nodenew_nodeios        W/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/export/exported_program.pyreplace_all_uses_withz)ModuleCallSignature.replace_all_uses_withi   sb     	' 	'Av+++! 	' 	'Av+++!	' 	'    )__name__
__module____qualname__listr:   __annotations__pytreeTreeSpecrP   r
   strrZ    r[   rY   rI   rI   a   s}         ,_o-1xS	*111' ' ' ' 'r[   rI   c                   4    e Zd ZU eed<   dZee         ed<   dS )rH   fqnN	signature)r\   r]   r^   rc   r`   rg   r
   rI   rd   r[   rY   rH   rH   r   s1         	HHH/3Ix+,33333r[   rH   c                 F     t          j                    fd            }|S )Nc                  d    t                      5   | i |cd d d            S # 1 swxY w Y   d S rR   r0   )argskwargsfns     rY   wrapperz/_disable_prexisiting_fake_mode.<locals>.wrappery   s    #%% 	' 	'2t&v&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   %)))	functoolswraps)rl   rm   s   ` rY   _disable_prexisiting_fake_moderp   x   s8    _R' ' ' ' ' Nr[   
spec1_typespec1_context
spec2_typespec2_contextreturnc                 *   | |
| |u o||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 o||k    S )zeTreat containers and their immutable variants as the same type. Otherwise
    compare as normal.
    )
issubclassdictr   r_   r   )rq   rr   rs   rt   s       rY   _fx_collection_equivalence_fnry      s     Z/Z'JM],JJ*t^455 .*T>*; ; . --*t^455 .*T>*; ; . --#F(FFr[   c              #     K   i }t                      }|                                 D ]`\  }}|j                                        ||<   |                    |           t
          D ]8}||j        vr- |                    |          t          |d                     9t          |          }t          j
        j        j        |j        v r|j        t          j
        j        j        =  |                    t          j
        j        j                  |           d }t          |          s, t          |          t          j        ||                     t"          D ])}||j        vr |                    |          |           *b	 d V  |D ]c}	|	j                                         |	j                            ||	                    |	j                                         t+          |	           dd S # |D ]c}	|	j                                         |	j                            ||	                    |	j                                         t+          |	           dw xY w)NT)deferred_errorc                 `    |d         }|d= | 5   ||i |cd d d            S # 1 swxY w Y   d S )Noriginal_callablerd   )fake_tensor_modeoprj   rk   orig_cia_callables        rY   $_force_dispatch_to_orig_cia_callablezQ_override_composite_implicit_decomp.<locals>._force_dispatch_to_orig_cia_callable   s     &': ;*+! : :(($9&99: : : : : : : : : : : : : : : : : :s   #'')r}   )setitems
py_kernelscopyadd(_AUTOGRAD_ALIAS_BACKEND_KEYS_TO_OVERRIDEpy_implr   r#   torch_CDispatchKeyCompositeImplicitAutogradr   r   rn   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
             rY   #_override_composite_implicit_decompr      s      L%%K(;(A(A(C(C =< =<$_$/$:$?$?$A$A[!$$$%M 	 	!$K,BBB:##$9::,[NNN  
 0<<89[=SSS&ux';'UVKEH0JKK	
 	
 	
	: 	: 	: .k:: 	)[))!8&7     - 	< 	<C+000  )##C(():;;;#	<&$ 	$ 	$BM!!!M  b!1222$$&&&####		$ 	$+ 	$ 	$BM!!!M  b!1222$$&&&####		$s   
G6 6A(Idecomp_table.c                    t          t                                }i }t          |                                           D ]w}||v r$| |         ||<   |                    |           | |= *t          |          r>|                                }|                    d          r
J d            | |         ||<   x|D ]}t          ||<   || fS )NatenzThis should be a custom op)	r   r   r_   keysremover$   rS   
startswithr+   )r   all_preservable_cia_opsr   r   op_nameks         rY   ,_split_decomp_table_to_cia_and_python_decompr     s     ""<">">??<$$&&'' 7 7$ (((&22&6##**2...R   $B'' 	7ggiiG))&11OO3OOO1&22&6# % = =!<A,,r[   r5   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()`
    r4   rd   r[   rY   rJ   rJ   ?  s     r[   eprG   cia_to_decomppython_decomp_tablejoint_loss_indexc                  QRSTU ddl m} ddlm} ddlm}m}m}	m}
m	}m
} ddlm} d } || |          s|                                 }i t          |                    d                    t          |                    d                    Udd	lm}  ||           i t          |                    d                    t          |                    d                    }t'          | j                  }|t+           |            d
          }|j        }t/          |j        j        t4                    sJ |j        j        j        j        }|J |j        t<          t>          fvrtA          j!        t>          d |g          }t5          tE          ||j#        |                    |j        _        |$                                 tK          | j&        | j'        |           tQ          || j)        | j&        j*                  }tW          ||          }tY          |          }ddl-m.}m/} g }|j        j0        D ]}|j1        dk    rt/          |j2        d         tf                    r_d }|j2        d         j4        | j'        |j2        d         j5                 }n|j2        d         j4        j6        }|7                    |           |7                    |j2        d                    tq          |          }|5  ts          |          5   || j:                  5  tw          |          5  tA          j<        ||j#                  } ||g |d         |d         =                                R i |          5 \  }} }!}"R ||| |!||"|d|          }#Rfd|#j'        >                                D             |#_'        |#j?        }$|#j@        }%t          |%|          }%t          ||$|%           t          | j&        |%          }% ||$|%|"          }&t          |$|%|| |!||&           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y    |
|$            ||$            ||$|%           t          |$|%          \  }$}%i | j)        Ufd|>                                D             }'U>                                D ]G\  }(})|(|'vr!t/          |)t          jG        jH                  rJ |(|'v r|(|vr|'I                    |(           H|$|%|'fS d | j        j        j0        D             }*d |*D             }+d | j                                        D             },|,D ]}(t          | j        |(           t          |+          }-|-t          jM                    n|-}.|rt          jM        n|}/ |	            5  |.5  ts          |          5   |/            5   || j        |+||d
nd||nd           \  }$Q|$j        N                                 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d Td |$j        j0        D             St?          |$j        O                                jP        d                   }0t          S          t          |*          k    sJ t          |*S          D ]\  }1}2|1j5        x|2_5        |2_S        i }3t          t                    }4t                      }5SD ]'}6|6j5        |3|6j5        <   t          |6j5        |4|5           (|$j        j0        D ]0}|j1        dk    rt          |3|4|5|j5        |j5                  |_5        1t          |$           ddlZm[}7m\}8 ddl]m^}9 t          j_        j`        ja        sud}:t          |$          };|;b |8|$t          jd        |7d|:i                    5  t          |$|;dt          |$j                   d
           d d d            n# 1 swxY w Y   |$$                                 t          |0 |9|$                    D ]\  }<}(|(|(|<_5        Sfd t          | j&        jh                  D             }=STfd!t          | j&        jh                  D             }>g }?d" t          Qji                  D             }@t=          Qjj        k                                          }A|Ad# |0d t          |A                   D             k    sJ Qjj        >                                D ]\  }B}C|@|C         }D| j&        jh        |D         }E|Ejl        t          jn        t          jo        fv sJ |Ejl        t          jo        k    rt          jq        nt          jr        }F|Ejl        t          jo        k    r|EjS        n|Ejs        j5        }G|?7                    t          |Ft          |B$          |G%                     t          | j&        jv                  D ]\  }D}H|?7                    t          |D|k    rt          jw        n|Hjl         T|Hjs        |0t          |A          |Dz                      |=x                    |HjS        |HjS                                       |5Qjy        J Qjy        jz        }It          Qji                  t          | j&        jh                  k    sJ Qfd&t          | j&        jh                  D             }J|0t          |?          d          D ]}|I|j5                 }K|J|K         }H|Hjl        t          j{        k    rt          j|        }L|HjS        }Gn;|Hjl        t          jn        k    rt          j}        }L|K}Gnt          d'|Hjl                   |?7                    t          |Lt          |j5        $          |G                     t          S          t          |*          k    sJ t          |>|?(          }%t          |*S          D ]\  }M}Nt/          |Mj2        d         t          j                  s|Mj2        d         |Nj2        d<   |NjS        |%j        v s|NjS        |%j        v r)|Mj2        >                                D ]\  }O}P|P|Nj2        |O<   |$|%| j)        fS ))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p| j         j        d uS rR   )graph_signaturebackward_signature)r   r   s     rY   _is_joint_ir_decompzO_decompose_and_get_gm_with_new_signature_constants.<locals>._is_joint_ir_decomp\  s#    D( A!4D@	
r[   F)remove_duplicate)!unwrap_tensor_subclass_parametersT)	shape_envexport)&_enable_graph_inputs_of_type_nn_module_fakify_script_objectsplaceholdervalr9   )r   _prettify_placeholder_namesdecompose_custom_triton_opsc                 V    i | ]%\  }}|t          |t                    r|         n|&S rd   )
isinstancer   ).0rf   objmap_fake_to_reals      rY   
<dictcomp>zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<dictcomp>  sP     2 2 2 !S %c+;<<!(-- 	2 2 2r[   c                 $    i | ]\  }}|v	||S rd   rd   )r   rS   pwrapped_params_bufferss      rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<dictcomp>$  s5       D!555 a555r[   c                 (    g | ]}|j         d k    |S r   r   r   nodes     rY   
<listcomp>zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<listcomp>6  s+       =8P8P8P8P8Pr[   c                 (    g | ]}|j         d          S )r   )metar   s     rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<listcomp>9  s    ???d5!???r[   c                     g | ]\  }}|S rd   rd   )r   rS   _s      rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<listcomp>;  s    MMM'$MMMr[   )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rS   zType of old_arg not supported: )	r   r;   rE   rS   rD   rC   rB   RuntimeErrortype)old_argnew_phs     rY   
update_argzF_decompose_and_get_gm_with_new_signature_constants.<locals>.update_argZ  s    g/00 		5N00 	5!v{333300 	5!v{3333!122 	5#555511 	5"4444LT']]LLMMMr[   c                 (    g | ]}|j         d k    |S r   r   r   s     rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<listcomp>g  s$    TTT47m;S;S;S;S;Sr[   )_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   c                 z    i | ]7\  }}t          |j        t                    |j        j        |         j        8S rd   )r   argr;   rS   )r   rW   specnew_placeholderss      rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<dictcomp>  sO       At$($455'*/  r[   c           
          g | ];\  }}t          |j         |j        |                   |j        |j                  <S rd   )r?   kindr   target
persistent)r   rW   r   r   r   s      rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<listcomp>  s_        At 	IJtx!1!!455KO		
 	
  r[   c                     i | ]\  }}||	S rd   rd   )r   rW   rS   s      rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<dictcomp>  s    WWWWQqWWWr[   c                     g | ]	}|j         
S rd   r   r   s     rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<listcomp>  s    WWWDdiWWWr[   r   )r   r   r   c                 f    i | ]-\  }}t          |j        t                    j        |         |.S rd   )r   r   rE   user_inputs)r   rW   r   r   s      rY   r   zF_decompose_and_get_gm_with_new_signature_constants.<locals>.<dictcomp>  sI     
 
 
4$(N33
'*D
 
 
r[   z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   modulerx   named_parametersnamed_buffers7torch._functorch._aot_autograd.subclass_parametrizationr   r!   graph_moduler   	_out_specr   graph_codegenr   pytree_info	orig_argsr   r_   tuplera   rb   r   _in_spec	recompiler   r   	constantsr)   
state_dictnon_persistent_buffersr"   r    torch._export.non_strict_utilsr   r   nodesr   r   r<   fake_valrS   real_objappendr   r   example_inputsr   tree_unflattenvaluesr   gmsigr&   r(   r'   r,   !_remove_unneccessary_copy_op_passr   nn	Parameterpopdelattrr/   
contextlibnullcontexteliminate_dead_codeoutput_noderj   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_envrn   r   r   r   	enumerater   r   user_inputs_to_mutater   r   r>   
USER_INPUTBUFFERr@   BUFFER_MUTATIONUSER_INPUT_MUTATIONr   rA   rE   r   LOSS_OUTPUTgetr   gradients_to_user_inputs	PARAMETERGRADIENT_TO_PARAMETERGRADIENT_TO_USER_INPUTAssertionErrorr=   Tensorinputs_to_parametersinputs_to_buffers)Vr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   modr   unwrapped_params_buffers	fake_moderO   orig_arg_namestemp_registered_constantsfake_params_buffersparams_buffers_to_node_metar   r   retracing_argsr   real_script_objtxretracing_args_unwrappedpatched_modnew_fake_argsnew_fake_kwargsnew_fake_constant_attrsaten_export_artifactr  new_graph_signaturer  new_state_dictrS   r   old_placeholders	fake_argsbuffers_to_removefake_mode_detfake_mode_ctx#custom_triton_ops_decomposition_ctxnew_outputsold_phr   name_mapfind_available
used_namesphr   r   r   r   r   outputold_new_placeholder_mapr   r   user_inputs_indexmutation_namesoutput_name
input_namerW   
input_specoutput_kindr   r   	gradientsspecssourcer   old_noderV   r   vr   r   r   r   r   sV                                                                                    @@@@@rY   2_decompose_and_get_gm_with_new_signature_constantsr^  H  s    YXXXXX??????                ?>>>>>
 
 
 r#344 R7iikk"
3'''??@@"
3$$e$<<=="

	
 	
 	
 	
 	
 	
 	*)#...$
3'''??@@$
3$$e$<<==$
  .bo>>	&DIIII =#),n=====+7A ###=u--udXJ??H+ 
 
	 	
 	((:BL#NNN %C 2 I%
 %
!
 5YDD&DS&I&I#
	
 	
 	
 	
 	
 	
 	
 	

 IO 
	< 
	<Dw-''di.0ABB <&*Oy'08*,,ty7G7L*M*.)E*:*C*L"))/::::"))$)E*:;;;I&& P	 P	/ P	 P	
 3223DEEP	 P	 BKKP	 P	 (.'<( ($ ('-a0-a07799    D' '9'9!#'+!4050K	( 	( 	($2 2 2 2 %9$B$H$H$J$J2 2 2$. *,&:&>#
 L+-F  $ :/5H  
 'V&(;' '# <;+-D 	 ('!#'  yD D D D D D D D D D D D D D DP	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	 P	d 	 ###B!!"&9:::"C##
 #

m
   7==??  
 .3355 	- 	-GD!>))%a);<<<<<~%%777"&&t,,,&66 .4   @?.>???IMMR_-J-J-L-LMMM! ' '&&&& %Y//M0=0EJ*,,,=M '	@
? ( 	 !!' '' ' 	,M::' ' 	,+--	' ' 0/O. 0 <%$4$@  d
 
 
O 	$$&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '&N N N UTTTT-2283G3G3I3I3Nq3Q-R-RK   C(8$9$99999.0@AA 2 2&,k1fmm H%0%5%5N55J : :GRWnj9999 
 
7m##.nj$)TY
 
		
 $B'''        YXXXXX=; 1 	 #2&&	 ((!'=+2N      0X)LRX)V)VXX	                  LLNNNK)<)<R)@)@AA  FK    !3!?@@       !!3!?@@  K L XW	/:U0V0VWWW/?DDFFGGNWWK@U#nBUBU@U4VWWWWWWW#2#H#N#N#P#P 
 
Zj)'3A6
9#79I"JJJJJ )"222 &&/ 	 )"222 $ 	
 	 "444  	
 	
 	
 	
 R/<== 
 
4*+/?*?*?
&&TY
48[^1D1Dq1H%IJJ'++DKEE 	
 	
 	
 	
 #1===#6O	?.//3r7I7U3V3VVVVV
 
 
 
$R%7%CDD
 
 

  L 1 1 3 34 	 	Dty)F=DyI///!7i222!8$%GDI%G%GHHH"	222       C(8$9$99999.l   ""24DEE 	% 	%((-.== 	8#+=#7HM%  O2GGG"5"GGG ++-- % %1#$a  "BM11s4  >RQ6Q/AQ	;B*P1%Q	1P55Q	8P59Q	<QQQQQQ6Q##Q6&Q#'Q6*R6Q:	:R=Q:	>RRR;Z$>ZY6:Y	Y6Y##Y6&Y#'Y6*Z6Y::Z=Y:>ZZ$Z	Z$Z	Z$$Z(+Z(7)a,,a03a0r  rC  c                 n   |                      |                                          5  | j        j        D ]}|j        dk    rt          j        |j                  \  }}|D ]}t          |t          j
        j                  r|j        |j        v s|j        |j        v ri|j        dk    r^|j        t          j        j        j        j        k    r:|                    |j        d                    | j                            |           |                                  ddd           n# 1 swxY w Y   | |fS )zQ
    Removes redundant copy_ node that was introduced due to mutated buffer.
    rQ  call_functionr9   N)_set_replace_hookget_replace_hookr   r  r   ra   tree_flattenrj   r   r   fxNoderS   buffers_to_mutateparameters_to_mutater   opsr   r   defaultrZ   
erase_noder  )r  rC  r   rj   r   outs         rY   r  r    sj    
		1BBDD	E	E  HN 	5 	5Dw("" -di88a 
5 
5C!#ux}55 	5$7$III8':'OOO  Fo55 #
ein.A.I I I55chqkBBBH//444
                """s   C4D((D,/D,c           	         |                      |                                          5  |                                 D ]}t          |t          j        j                  s"i }i }t          |j        j	                  D ]}|j
        dk    r|j        t          j        k    r|j        \  }}||          d| }	|	|v rc|                    ||	                    |D ]*}
|
j        !|
j                            |||	                    +|j                            |           |||	<   |	||<   |j        ||<   	 d d d            d S # 1 swxY w Y   d S )Nr`  .)ra  rb  modulesr   r   rd  GraphModuler_   r   r  r   r   operatorgetitemrj   rZ   rg   rj  rS   )r  r   module_call_graphr   node_idgetitemsr   r[  idxnew_identrys              rY    _common_getitem_elimination_passrx  )  s    
		o>>@@	A	A . .jjll 	. 	.Ffeh&:;; 02G13HV\/00 . .7o--$+AQ2Q2Q"&)KFC '77#77F))228F3CDDD%6 " "E$: % E E$((6*:!" !" !" //5555+/((.$(IGDMM!.	.. . . . . . . . . . . . . . . . . .s   DEEEold_gmold_graph_signaturer   old_module_call_graphc                    t          j        |          }d | j        j        D             }i j        j        i |j        |j        }i }d}	d | j        j        D             }
t          t          fd|
                    }
d |j        j        D             }|j        j        D ]}|j        	                    dg           x}r|j
        ||d         j
        <   5|j        dk    rj|j        |v sa|j        |j        v sS|j        |v rJt          |j
        t                    sJ |
|	         }t          |t                    sJ |j
        ||<   |	d	z  }	t!          t                    }|                                D ]o\  }}|                    d
          s
|v r|||<   $d                    |                    d          d	d                   }||                             |           p|D ]}|j        }|g |j        |j        D ]}|j
        |v rt3          d|j
         d          |j
        |v r||j
                 |_
        ?|j
        |v r||j
                 }|j        dk    r|j        t4          j        j        j        j        t4          j        j        j        j        t4          j        j        j        j         fv r6|j!        d         j
        }||vrt3          d| d          ||         |_
        |S )Nc                     i | ]
}|j         |S rd   r   r   s     rY   r   z2_get_updated_module_call_graph.<locals>.<dictcomp>O  s    @@@TD@@@r[   r   c                 2    g | ]}|j         d k    |j        S r   r   r   r   s     rY   r   z2_get_updated_module_call_graph.<locals>.<listcomp>_  s-       dg6N6N6N6N6Nr[   c                     | vo| j         vS rR   )input_tokens)xold_graph_params_buffersrz  s    rY   <lambda>z0_get_updated_module_call_graph.<locals>.<lambda>d  s!    a77 :,99 r[   c                 2    g | ]}|j         d k    |j        S r   r  r   s     rY   r   z2_get_updated_module_call_graph.<locals>.<listcomp>i  s-       $']2J2J2J2J2Jr[   	from_noder   r9   zparametrizations.rm  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 tensorsr`  )"r   deepcopyr   r  r1  r2  r_   filterr   r*  rS   r   r   r  r   rc   r   r   r   joinsplitr  rg   rL   rM   
ValueErrorr   rh  r   todtype_layoutdevicedtyperj   )ry  rz  r  r   r{  new_module_call_graph	old_nodesnew_graph_params_buffers
provenanceuser_input_counterold_user_input_namesnew_user_input_namesr   historyold_nameold_param_to_desugaredrS   r   
old_targetrw  rg   r  r\  r  s    `                     @rY   _get_updated_module_call_graphr  F  s    !M*?@@@@V\-?@@@I 

2 

/  

. 

+  "$J  & 2    : : : : : 	
 	
   "    , ,immK4447 	,+/9Jwr{'((
 W%%777;/">>>;"666%di5555534FGH%h44444+/9Jx(&!+&
 )..06688 < <f  !455 	<///#'
4 &,,s"3"3AbD"9::J":.55d;;;; ' '4 '4O	89#8i&78 #	4 #	4A v/// [QV [ [ [   v###AF+ 9$$$QV,;/11hoIN%2IN%,IN%+J 7 7
 "*q!1!6J!33(cZ c c c   (
3AFG#	4J ! r[   r   c          
      8   t          | ||||          \  }}}t          | j        | j        ||| j                  }|j                            | j        j                   t          || j                  }	t          ||j
        |||	|| j        | j                  }
|
S )Nr   r   r   r   )rootr   r   r  range_constraintsrr  r  r  )r^  r  r   r   rr  r   r   _get_updated_range_constraintsr  rG   r   r  r  )r   r   r   r   r   r  rC  r  r  new_range_constraintsexported_programs              rY   _decompose_exported_programr    s     	;
#/)$?	 	 		
 ;



  GNN2?'(((:

 
 'h+//(,	 	 	 r[   c                   H   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edf         e	e
ef         f                  ed	<   	 e	e
ef         ed
<   	 eee                  ed<   	 ee
         ed<   	 	 dNdddeej        j        e	e
ef         f         dej        j        dede	e
eej        ej        j        f         f         dddee         deeeedf         e	e
ef         f                  dee	e
ef                  deeee                           fdZe ed          d                         Zej         ed          d                         Ze ed          d                         Zej         ed          d                         Ze ed          d                          Zej         ed          d!                         Ze ed          d"                         Z e j         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&j         ed          d*                         Z&e ed          d+                         Z'e'j         ed          d,                         Z'e ed          d-                         Z(e(j         ed          d.                         Z(e ed          d/                         Z)e)j         ed          d0                         Z)e ed          d$efd1                        Z*e*j         ed          d2                         Z*e ed          d$e
fd3                        Z+e+j         ed          d4                         Z+e ed          d5                         Z,e,j         ed          d6                         Z,e ed          d7                         Z-e-j         ed          d8                         Z-e ed          d9                         Z.e.j         ed          d:                         Z.d; Z/d<ed=ed$efd>Z0d<ed=ed$efd?Z1d$e
fd@Z2dOd$ej        j        fdBZ3dC Z4e5	 	 dPdDee	ej6        j7        e8f                  dEe9d$d fdF            Z:dGe;d$d fdHZ<dI Z= ed          dJ             Z>e?dK             Z@ddddL	 dQdMZAdS )RrG   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._example_inputs
_constants
_verifiers_guards_codeN)	verifiersr  r   r   r  r  dict[sympy.Symbol, Any]rr  r  r  r  c	                ^   t           j        j                                        |_        t          ||          | _        t          |t           j        j                  r$| j        j	        
                    |j	                   t          | j        ||           || _        || _        || _        |J || _        || _        |pi | _        |	pt$          g}	t'          d |	D                       sJ |	| _        |                                  t-          t/          | j                            | _        d S )Nc              3   @   K   | ]}t          |t                    V  d S rR   )rw   r-   )r   r]  s     rY   	<genexpr>z+ExportedProgram.__init__.<locals>.<genexpr><  s,      >>q:a**>>>>>>r[   )r   rd  r   CodeGenr   _create_graph_module_for_exportr  r   ro  r   r   rx  r  r  r  r  r  r  r-   allr  validate_convert_guards_to_coder"  r  )
rT   r  r   r   r  r  rr  r  r  r  s
             rY   __init__zExportedProgram.__init__  s#    //11<T5IIdEH011 	6#**49555(1B	
 	
 	
 7F+5CT ,,,9J-#/r+(	>>I>>>>>>>>#3N4CU4V4VWWr[   F)is_backward_compatiblec                     | j         S rR   )r  rT   s    rY   r   zExportedProgram.graph_moduleC  s     !!r[   c                      t          d          )Nz7Unable to set ExportedProgram's graph_module attribute.r   rT   values     rY   r   zExportedProgram.graph_moduleH  s     TUUUr[   c                     | j         j        S rR   )r   r   r  s    rY   r   zExportedProgram.graphM  s      &&r[   c                      t          d          )Nz0Unable to set ExportedProgram's graph attribute.r  r  s     rY   r   zExportedProgram.graphR  s     MNNNr[   c                     | j         S rR   )r  r  s    rY   r   zExportedProgram.graph_signatureW  s     $$r[   c                      t          d          )Nz:Unable to set ExportedProgram's graph_signature attribute.r  r  s     rY   r   zExportedProgram.graph_signature\  s     WXXXr[   c                     | j         S rR   )r  r  s    rY   r  zExportedProgram.state_dicta  s     r[   c                      t          d          )Nz5Unable to set ExportedProgram's state_dict attribute.r  r  s     rY   r  zExportedProgram.state_dictf  s     RSSSr[   ru   c              #   F   K   |                                  D ]	\  }}|V  
dS )zH
        Returns an iterator over original module's parameters.
        N)r   )rT   r   params      rY   
parameterszExportedProgram.parametersk  s<      
 --// 	 	HAuKKKK	 	r[   c              #   J   K   | j         j        D ]}|| j        |         fV  dS )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  )rT   
param_names     rY   r   z ExportedProgram.named_parameterss  sB       .9 	: 	:Jdoj999999	: 	:r[   c              #   F   K   |                                  D ]	\  }}|V  
dS )zC
        Returns an iterator over original module buffers.
        N)r   )rT   r   bufs      rY   bufferszExportedProgram.buffers|  s<      
 ((** 	 	FAsIIII	 	r[   c              #      K   t          | j        j                  }| j        j        D ])}||v r|| j        |         fV  || j        |         fV  *dS )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  )rT   r  buffer_names      rY   r   zExportedProgram.named_buffers  s       "%T%9%P!Q!Q/7 	@ 	@K444!4>+#>>>>>>!4?;#??????		@ 	@r[   c                     | j         S rR   )r  r  s    rY   r  z!ExportedProgram.range_constraints       &&r[   c                      t          d          )Nz<Unable to set ExportedProgram's range_constraints attribute.r  r  s     rY   r  z!ExportedProgram.range_constraints       J
 
 	
r[   c                     | j         S rR   )r  r  s    rY   rr  z!ExportedProgram.module_call_graph  r  r[   c                      t          d          )Nz<Unable to set ExportedProgram's module_call_graph attribute.r  r  s     rY   rr  z!ExportedProgram.module_call_graph  r  r[   c                     | j         S rR   )r  r  s    rY   r  zExportedProgram.example_inputs  s     ##r[   c                 H   |	|| _         d S t          |t                    rIt          |          dk    r6t          |d         t                    rt          |d         t                    st          d          |\  }}ddlm}  |||| j        j	                   || _         d S )N   r   r9   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  rx   r  _unliftr  	call_specrN   )rT   r  rj   rk   r  s        rY   r  zExportedProgram.example_inputs  s    
 =#(D F ue$$		E

a58U++  58T**   B  
 f000000D&$.*@AAA$r[   c                     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                   P    e Zd ZU eej                 ed<   eej                 ed<   dS )+ExportedProgram.call_spec.<locals>.CallSpecrN   rO   N)r\   r]   r^   r
   ra   rb   r`   rd   r[   rY   CallSpecr    s8         fo....v//////r[   r  r   )rN   rO    )r	   r  rr  rf   rg   rN   rO   )rT   r  s     rY   r  zExportedProgram.call_spec  s    	0 	0 	0 	0 	0z 	0 	0 	0 t%&&!++8D48888%a(,2222x*1-7?+A.8A
 
 
 	
r[   c                      t          d          )Nz4Unable to set ExportedProgram's call_spec attribute.r  r  s     rY   r  zExportedProgram.call_spec       QRRRr[   c                     | j         d         S Nr   r  r  s    rY   verifierzExportedProgram.verifier  s     q!!r[   c                      t          d          )Nz3Unable to set ExportedProgram's verifier attribute.r  r  s     rY   r  zExportedProgram.verifier  s     PQQQr[   c                 8    | j         J | j         d         j        S r  )r  dialectr  s    rY   r  zExportedProgram.dialect  s"     ***q!))r[   c                      t          d          )Nz2Unable to set ExportedProgram's dialect attribute.r  r  s     rY   r  zExportedProgram.dialect  s     OPPPr[   c                     | j         S rR   r  r  s    rY   r  zExportedProgram.verifiers       r[   c                      t          d          )Nz4Unable to set ExportedProgram's verifiers attribute.r  r  s     rY   r  zExportedProgram.verifiers  r  r[   c                     | j         S rR   r  r  s    rY   tensor_constantsz ExportedProgram.tensor_constants  r  r[   c                      t          d          )Nz;Unable to set ExportedProgram's tensor_constants attribute.r  r  s     rY   r  z ExportedProgram.tensor_constants  s     I
 
 	
r[   c                     | j         S rR   r  r  s    rY   r  zExportedProgram.constants  r  r[   c                      t          d          )Nz4Unable to set ExportedProgram's constants attribute.r  r  s     rY   r  zExportedProgram.constants  r  r[   c                     | j         j        }|t          ||          }t          j        ||f          \  }}|                     |           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)
        Nc              3   &   K   | ]}|d          V  dS )r9   Nrd   )r   r  s     rY   r  z<ExportedProgram._get_flat_args_with_check.<locals>.<genexpr>&  s&      <<1!A$<<<<<<r[   )r  rN   r3   ra   tree_flatten_with_path_check_input_constraintsr  )rT   rj   rk   rN   flat_args_with_pathreceived_spec	flat_argss          rY   _get_flat_args_with_checkz)ExportedProgram._get_flat_args_with_check  s     .(#FG44F-3-J6N.
 .
*] 	%%&9:::<<(;<<<<<	-''r[   rj   rk   c                    | j         j        }|                     ||          \  }}|+t          ||t                    st          d| d|           g }| j        j        D ]}|j        t          j
        k    r|j        t          j        t          j        fv rU|j        du r&|                    | j        |j                            f|                    | j        |j                            |j        t          j        t          j        fv r%|                    | 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)))
        Nz>Trying to flatten user inputs with exported input tree spec: 
z-
but actually got inputs with tree spec of: 
F)r  rN   r  r2   ry   r  r   r   r   r>   r%  r,  r&  r   r  r  r   r  CONSTANT_TENSOR
CUSTOM_OBJr  )rT   rj   rk   rN   r  r  additional_inputsinput_s           rY   _graph_module_flat_inputsz)ExportedProgram._graph_module_flat_inputs)  sz    .(#'#A#A$#O#O 	=}7$A(
 (
 ## # !# #   *6 	H 	HF{i222# !   $-- &,,T^FM-JKKKK%,,T_V]-KLLLL)$!   "(()FGGG!"344 !9,,r[   c                      t          d          )Nz\Unable to call ExportedProgram directly. You should use `exported_program.module()` instead.r  )rT   rj   rk   s      rY   __call__zExportedProgram.__call__W  s    B
 
 	
r[   c                     | j                             dd                              dd          }t          | 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replacerc   r   r  )rT   r   r   strings       rY   __str__zExportedProgram.__str__]  s    (77 8 
 

'$
!
! 	 d233;;D(KK== = /= = #'"8= = = 	 r[   Tc                     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.

        r9   )&_unlift_exported_program_lifted_states)check_guardsTmodec                      t          d          )Nz%Calling train() is not supported yet.NotImplementedErrorrT   r  s     rY   _trainz&ExportedProgram.module.<locals>._trainy  s    %&MNNNr[   c                      t          d          )Nz$Calling eval() is not supported yet.r  r  s     rY   _evalz%ExportedProgram.module.<locals>._eval|  s    %&LMMMr[   T)r  r  booltypes
MethodTypetraineval)rT   r  r  r   r  r  s         rY   r   zExportedProgram.modulej  s     	DCCCCC77<XXX	O 	Ot 	O 	O 	O 	O	N 	Nd 	N 	N 	N 	N '77&uf55r[   c                     t          d t          | j        j                  D             t	          | j        j                            S )Nc              3   J   K   | ]\  }}|j         t          j        k    |V  d S rR   r   r>   r%  )r   rW   ss      rY   r  z=ExportedProgram._num_lifted_params_buffers.<locals>.<genexpr>  sB        Aq6Y111 1111 r[   )nextr#  r  r   r  r  s    rY   _num_lifted_params_buffersz*ExportedProgram._num_lifted_params_buffers  sQ     %d&;&GHH  
 %122
 
 	
r[   r   r   c                     |t                      nt          |          }t          |t                    r|                                }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  )rJ   rx   r   r5   materializer   r  )rT   r   r   _decomp_tabler   r   s         rY   run_decompositionsz"ExportedProgram.run_decompositions  s    P )5(<"$$$$|BTBT 	 m%677 	8)5577M" 9GG	
 +' 3!(C
 
 
 	
r[   passesc                    t          t          |                    }ddlm}  |            5   || j                  }d d d            n# 1 swxY w Y   ||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                   |S )Nr   )r   old_signaturenew_gmru   c           	         g }t          |j        j                  D ]\  }}|j        dk    r n|t	          | j                  k     s
J d            | j        |         }t          |j        t          t          f          r|j        n! t          |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                  }|                    t)          |	j        ||	j                             t+          ||          }
|
S )zO
            Update the graph signature's user_input/user_outputs.
            r   z-Number of inputs changed after transformationr  rQ  r   z.Number of outputs changed after transformationr   )r#  r   r  r   r  r   r   r   r;   r<   r   rS   r  r?   r   r   r   r_   rj   r   rA   r=   )r*  r+  new_input_specsrW   r   old_input_specr   r  new_output_specsold_output_specnew_signatures              rY   _get_updated_graph_signaturezKExportedProgram._transform_do_not_use.<locals>._get_updated_graph_signature  s-    !O$V\%788  47m++E3}899999C :99 "/!:1!= "&*-=?P,Q =N&& 2n011$)<<   &&&+&-&1	     v|12226K>X----!$[%5a%899  43}9:::::D ;:: #0"<Q"? "'+.>@Q-R >O'' 3o12249==  !''3S/:PQQ    1+:J  M ! r[   	r  r   r   r  r  rr  r  r  r  )r8   r_   r   r   r   modifiedr=   r   rd  ro  rG   r   r   r  r  r  r   r  r  r  r  r  r   r   )rT   r(  pmr   restransformed_gmr2  transformed_eps           rY   _transform_do_not_usez%ExportedProgram._transform_do_not_use  s   f&& 	@?????$$&& 	( 	("T&''C	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(-0_))$BS)))T...s|.K7	!/7	!H(7	! "7	! 7	! 7	! 7	!r ) &88$n  <&  #mD,CDD.nn
 
 
  	#(//0A0FGGG#(//0@0EFFFs   A

AAc                     ddl m} d | j        j        D             }d t	          || j        j                  D             } |||| j                   d S )Nr   )"_check_input_constraints_for_graphc                 (    g | ]}|j         d k    |S r   r   )r   r   s     rY   r   z<ExportedProgram._check_input_constraints.<locals>.<listcomp>3  s$    MMMaqt}7L7L7L7L7Lr[   c                 B    g | ]\  }}|j         t          j        k    |S rd   r   )r   r   r!  s      rY   r   z<ExportedProgram._check_input_constraints.<locals>.<listcomp>4  s6     
 
 
1v--- ---r[   )torch._export.utilsr;  r   r  r  r   r   r  )rT   r  r;  placeholdersinput_placeholderss        rY   r  z(ExportedProgram._check_input_constraints0  s    JJJJJJMM4:#3MMM
 
L$*>*JKK
 
 

 	+* 3T5K	
 	
 	
 	
 	
r[   c                 .    |                                   d S rR   )	_validater  s    rY   r  zExportedProgram.validate=  s    r[   c                     t          | j                  dk    s
J d            | j        D ]} |                                |             d S )Nr   z0ExportedProgram must have at least one verifier.)r  r  check)rT   r]  s     rY   rB  zExportedProgram._validateB  s\    4>""Q&&&> '&&  	 	AACCIIdOOOO	 	r[   )r  r  r  c                    t          ||j        |||n| j        t          j        | j                  t          j        | j                  | j        ||n| j        ||n| j	        	  	        S )Nr3  )
rG   r   r  r   r  r  r  r  r  r  )rT   r   r   r  r  r  s         rY   _updatezExportedProgram._updateK  sw     $+%/%;zz"mD,BCC"mD,CDD.#,#8iidn#,#8iidn

 

 

 
	
r[   )NNr  )NF)ru   rG   )Br\   r]   r^   __doc__r   rd  ro  r`   r=   rx   rc   r   r_   rH   r
   r  r   r   r-   r   r  ModuleGraphr0  r  r  propertyr6   r   setterr   r   r  r   r  r   r  r   r  rr  r  r  r  r  r  r  r  r  r  r  r  r   r#  rp   _opsOperatorBaser   r  r'  PassTyper9  r  r  r   rB  rF  rd   r[   rY   rG   rG     sd
          8''''O****Mc3hU9999E_----JeE#s(OT#s(^$CDEEEELS001111:T(^$$$$Is) LPAE%X 59%X %X %XEHOT#s(^34%X x~%X .	%X
 eEL%(2D$DEEF%X 5%X  0%X !uS#XS#X'F!GH%X D&<!<=>%X Dh01%X %X %X %XN ]%000" " 10 X" ]%000V V 10 V ]%000' ' 10 X' \]%000O O 10 \O ]%000% % 10 X% ]%000Y Y 10 Y ]%000    10 X  ]%000T T 10 T ]%000HUX%78    10 ]%000:(5eh6H1H+I"J : : : 10: ]%000%,/    10 ]%000
@xc5<.?(@A 
@ 
@ 
@ 10
@ ]%000' ' 10 X' ]%000
 
 10 

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

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

 ]%000  10 X ]%000S S 10 S( ( (.,-c ,-3 ,-3 ,- ,- ,- ,-\
c 
S 
S 
 
 
 
     58+?    2
 
 
 $ KO,1D
 D
tEJ$;X$EFGD
 &*D
 
	D
 D
 D
 $#D
LZX Z:K Z Z Z Zx
 
 
 ]%000  10   U 
 
 

 
 
 
 
 
r[   c                     d | j         j        D             }ddlm}  ||          }||j        S |D ]*}t          |t          j                  r|j        j        c S +d S )Nc                 ^    g | ]*}|j                             d d          |j         d          +S )r   N)r   r*  r   s     rY   r   z"_get_shape_env.<locals>.<listcomp>b  s?       9==%%1 		%111r[   r   r.   )	r   r  torch._guardsr/   r   r   r   SymIntr   )r  valsr/   r5  r]  s        rY   r"  r"  a  s     HN  D
 /.....  &&I"" $ $a&& 	$6####	$$ $r[   old_range_constraintsz!Optional[dict[sympy.Symbol, Any]]r  c                     |J t          |           i S t          j        |          }fd|                                D             }j                                        D ]\  }}|j        vr	||vr|||<   |S )Nc                 .    i | ]\  }}|j         v||S rd   )replacements)r   r   r]  r   s      rY   r   z2_get_updated_range_constraints.<locals>.<dictcomp>|  s3       Aay?U6U6U16U6U6Ur[   )r"  r   r   var_to_rangerW  )r  rT  r  r   r]  r   s        @rY   r  r  q  s     !,,,r""I		"788   *0022   &,,.. % %1I***q8I/I/I#$a r[   c                    	 t           j                            | |          }ng# t          $ rZ t	          j        d           t           j                            | t           j                                                  }||_        Y nw xY w|S )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   rd  ro  SyntaxErrorwarningswarnrI  _graph)r  r   r  s      rY   r  r    s    X!!$..    	G	
 	
 	
 X!!$(8(899			 Is    # A!BBc                     | g S d | j                                         D             t          j        j        j                            | j         d | j                   fd| j        D             S )Nc                 J    h | ] \  }}t          d  |D                       |!S )c              3   `   K   | ])}t          |t          j        j        j                   V  *d S rR   )r   r   r  r[  ConstantSource)r   r[  s     rY   r  z4_convert_guards_to_code.<locals>.<setcomp>.<genexpr>  sK       
 
 65=#7#FGGG
 
 
 
 
 
r[   )r  )r   varsourcess      rY   	<setcomp>z*_convert_guards_to_code.<locals>.<setcomp>  sX       C 
 
!
 
 
 
 
  r[   c                 *    |                                  S rR   r   )r!  s    rY   r  z)_convert_guards_to_code.<locals>.<lambda>  s    AFFHH r[   c                     g | ];}|j         j                                      !                    |j                   <S rd   )exprfree_symbolsissubsetdoprint)r   guard
local_vars
py_printers     rY   r   z+_convert_guards_to_code.<locals>.<listcomp>  sR       :"++J775:&&  r[   )var_to_sourcesr   r   rd  experimentalsymbolic_shapesShapeGuardPythonPrinterguards)r   rl  rm  s    @@rY   r  r    s    	 %4::<<  J &6NN "4"4i6N J    %   r[   )ru   r5   rR   )r  r   dataclassesrn   rp  r  r[  collectionsr   collections.abcr   r   typingr   r   r   r	   r
   r   r   rQ  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_pytreera   r>  r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   torch._export.verifierr-   r/   r1   torch.export._tree_utilsr2   r3   torch.export.decomp_utilsr5   torch.fx._compatibilityr6   torch.fx.passes.infra.pass_baser7   "torch.fx.passes.infra.pass_managerr8   r   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   __all__rd  ro  rN  	dataclassrI   rH   rp   r   Contextr  ry   r   r   AutogradCPUAutogradCUDAAutogradMetaAutogradXLAAutogradLazyAutogradIPUAutogradXPUAutogradMPSAutogradHPUAutogradPrivateUse1AutogradPrivateUse2AutogradPrivateUse3r   CPUCUDAMetaXLALazyIPUXPUMPSHPUr   r   rx   rL  rM  r  r   rJ   r  r^  r  rx  r_   r  r  rG   r"  r  r  r  rd   r[   rY   <module>r     sx                   # # # # # # $ $ $ $ $ $ % % % % % % S S S S S S S S S S S S S S S S S S 1 1 1 1 1 1 1 1 B B B B B B ? ? ? ? ? ?         
 9 8 8 8 8 8 ; ; ; ; ; ; ? ? ? ? ? ? 6 6 6 6 6 6 6 6 I I I I I I I I J J J J J J  <
 LLL;;;;;;  $ $ $ $ $ $ $ $ $                                   $ , + + + + + * * * * * * @ @ @ @ @ @ B B B B B B B B 7 7 7 7 7 7 1 1 1 1 1 1 6 6 6 6 6 6 : : : : : :                             "   UX)*HZ,@@A ' ' ' ' ' ' ' '  4 4 4 4 4 4 4 4
  GG>G G >	G
 
G G G G: 
H$	H%	H%	H$	H%	H$	H$	H$	H$	H,	H,	H,, (, 
H	H	H	H	H	H	H	H	H
  P$ P$ P$f)-uz.89)-
4
'12C78)- )- )- )-X   E2E2 
/9:E2 ej5x?@	E2
 smE2 E2 E2 E2P##3G#
58!556# # # #2.. . . .:r!H r!-r! 	r! *	r!
  0r! r! r! r!j4 
/9:4 ej5x?@	4
 sm4 "&4 4 4 4nl	
 l	
 l	
 l	
 l	
 l	
 l	
 l	
^$ $ $$ BF >    .  *    r[   