
    N jk                     ,   S SK r S SKJrJr  S SKJrJr  S SKJrJ	r	  S SK
Jr  S SKJrJr  S SKJr  \(       a
  S SKrS SKJr  / S	Qr\ R*                   " S
 S5      5       r\ R*                   " S S5      5       r\ R*                   " S S5      5       r\ R*                   " S S5      5       r\ R*                   " S S5      5       r\ R*                   " S S5      5       r\ R*                   " S S5      5       r\	\\\\\\\4   r " S S\5      r\ R*                   " S S5      5       r " S S\5      r \ R*                   " S S5      5       r!\ R*                   " S  S!5      5       r"\ R*                   " S" S#5      5       r#S$ r$S%\4S& jr%S'S(S)S*S+\&\'   S%S#4S, jr(g)-    N)
CollectionMapping)autoEnum)TYPE_CHECKINGUnionFakeScriptObject)get_opaque_type_nameis_opaque_type)is_fake)GraphSignature)ConstantArgumentCustomObjArgumentExportBackwardSignatureExportGraphSignature	InputKind	InputSpec
OutputKind
OutputSpecSymIntArgumentSymFloatArgumentSymBoolArgumentTensorArgumentc                        \ rS rSr% \\S'   Srg)r       name N__name__
__module____qualname____firstlineno__str__annotations____static_attributes__r       m/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/export/graph_signature.pyr   r           
Ir'   r   c                        \ rS rSr% \\S'   Srg)TokenArgument%   r   r   Nr   r   r'   r(   r+   r+   %   r)   r'   r+   c                        \ rS rSr% \\S'   Srg)r   *   r   r   Nr   r   r'   r(   r   r   *   r)   r'   r   c                        \ rS rSr% \\S'   Srg)r   /   r   r   Nr   r   r'   r(   r   r   /   r)   r'   r   c                        \ rS rSr% \\S'   Srg)r   4   r   r   Nr   r   r'   r(   r   r   4   r)   r'   r   c                   >    \ rS rSr% \\S'   \\S'   Sr\S-  \S'   Srg)r   9   r   	class_fqnNfake_valr   )	r    r!   r"   r#   r$   r%   r6   r
   r&   r   r'   r(   r   r   9   s    
IN(,H%,r'   r   c                   B    \ rS rSr% \\S'   \\-  \-  \-  S-  \S'   Sr	g)r   @   r   Nvaluer   )
r    r!   r"   r#   r$   r%   intfloatboolr&   r   r'   r(   r   r   @   s     
I;#d**r'   r   c                   h    \ rS rSr\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r	\" 5       r
Srg)r   Q   r   N)r    r!   r"   r#   r   
USER_INPUT	PARAMETERBUFFERCONSTANT_TENSOR
CUSTOM_OBJTOKENr&   r   r'   r(   r   r   Q   s,    JIVFfOJFEr'   r   c                   Z    \ rS rSr% \\S'   \\S'   \S-  \S'   Sr\	S-  \S'   S r
S rS	rg)
r   Z   kindargNtarget
persistentc           
      .   U R                   [        R                  :X  a  U R                  c  [	        S5      e[        U R                  [        [        [        [        [        [        [        45      (       d!  [	        S[        U R                  5       35      eg )Nz,Failed to specify persistent flag on BUFFER.expected valid arg type, got )rG   r   rA   rJ   AssertionError
isinstancerH   r   r   r   r   r   r   r+   typeselfs    r(   __post_init__InputSpec.__post_init__a   s{    99	(((&$%STTHH  !
 
 !#@dhh@P!QRR
r'   c                    U R                   c  SOSU R                    S3nU R                  c  SOSU R                   3n[        U R                  R                  5       S[        U R
                  R                  5       U U 3$ )N 	 target=''z persistent=: )rI   rJ   r$   rH   r   rG   )rQ   rI   rJ   s      r(   __str__InputSpec.__str__s   sp    {{*)DKK=0J??2R,tFW8X
dhhmm$%RDIINN(;'<VHZLQQr'   r   )r    r!   r"   r#   r   r%   ArgumentSpecr$   rJ   r<   rR   rY   r&   r   r'   r(   r   r   Z   s1    
O	$J"Jt"S$Rr'   r   c                       \ rS rSr\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r	\" 5       r
\" 5       r\" 5       rSrg)r   y   r   N)r    r!   r"   r#   r   USER_OUTPUTLOSS_OUTPUTBUFFER_MUTATIONPARAMETER_MUTATIONGRADIENT_TO_PARAMETERGRADIENT_TO_USER_INPUTUSER_INPUT_MUTATIONrD   r&   r   r'   r(   r   r   y   s>    &K&KfO F!V&FEr'   r   c                   F    \ rS rSr% \\S'   \\S'   \S-  \S'   S rS r	Sr
g)	r      rG   rH   NrI   c           
          [        U R                  [        [        [        [
        [        [        [        45      (       d  [        SU R                   35      eg )NrL   )
rN   rH   r   r   r   r   r   r+   r   rM   rP   s    r(   rR   OutputSpec.__post_init__   sN    HH  !
 
 !#@
!KLL
r'   c                     U R                   c  SOSU R                    S3n[        U R                  R                  5       S[        U R                  R                  5       U 3$ )NrU   rV   rW   rX   )rI   r$   rH   r   rG   )rQ   rI   s     r(   rY   OutputSpec.__str__   sP    {{*)DKK=0Jdhhmm$%RDIINN(;'<VHEEr'   r   )r    r!   r"   r#   r   r%   r[   r$   rR   rY   r&   r   r'   r(   r   r      s$    
	$JMFr'   r   c                   H    \ rS rSr% \\\4   \S'   \\\4   \S'   \\S'   Srg)r      gradients_to_parametersgradients_to_user_inputsloss_outputr   N)r    r!   r"   r#   dictr$   r%   r&   r   r'   r(   r   r      s$    !#s(^+"38n,r'   r   c                      \ rS rSr% Sr\\   \S'   \\   \S'   \	S\
\   4S j5       r\	S\
\   4S j5       r\	S\
\   4S j5       r\	S\
\   4S	 j5       r\	S\
\   4S
 j5       r\	S\
\\-  \-  \-  S-     4S j5       r\	S\
\\-  \-  \-  S-     4S j5       r\	S\\\4   4S j5       r\	S\\\4   4S j5       r\	S\\\4   4S j5       r\	S\\\4   4S j5       r\	S\\\4   4S j5       r\	S\\\4   4S j5       r\	S\\\4   4S j5       r\	S\S-  4S j5       r\	S\\\4   S-  4S j5       r \	S\
\   4S j5       r!\	S\
\   4S j5       r"S S jr#S\S\4S jr$S!S jr%S r&Sr'g)"r      a  
:class:`ExportGraphSignature` models the input/output signature of Export Graph,
which is a fx.Graph with stronger invariants guarantees.

Export Graph is functional and does not access "states" like parameters
or buffers within the graph via ``getattr`` nodes. Instead, :func:`export`
guarantees that parameters, buffers, and constant tensors are lifted out of
the graph as inputs.  Similarly, any mutations to buffers are not included
in the graph either, instead the updated values of mutated buffers are
modeled as additional outputs of Export Graph.

The ordering of all inputs and outputs are::

    Inputs = [*parameters_buffers_constant_tensors, *flattened_user_inputs]
    Outputs = [*mutated_inputs, *flattened_user_outputs]

e.g. If following module is exported::

    class CustomModule(nn.Module):
        def __init__(self) -> None:
            super(CustomModule, self).__init__()

            # Define a parameter
            self.my_parameter = nn.Parameter(torch.tensor(2.0))

            # Define two buffers
            self.register_buffer("my_buffer1", torch.tensor(3.0))
            self.register_buffer("my_buffer2", torch.tensor(4.0))

        def forward(self, x1, x2):
            # Use the parameter, buffers, and both inputs in the forward method
            output = (
                x1 + self.my_parameter
            ) * self.my_buffer1 + x2 * self.my_buffer2

            # Mutate one of the buffers (e.g., increment it by 1)
            self.my_buffer2.add_(1.0)  # In-place addition

            return output


    mod = CustomModule()
    ep = torch.export.export(mod, (torch.tensor(1.0), torch.tensor(2.0)))

Resulting Graph is non-functional::

    graph():
        %p_my_parameter : [num_users=1] = placeholder[target=p_my_parameter]
        %b_my_buffer1 : [num_users=1] = placeholder[target=b_my_buffer1]
        %b_my_buffer2 : [num_users=2] = placeholder[target=b_my_buffer2]
        %x1 : [num_users=1] = placeholder[target=x1]
        %x2 : [num_users=1] = placeholder[target=x2]
        %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%x1, %p_my_parameter), kwargs = {})
        %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add, %b_my_buffer1), kwargs = {})
        %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%x2, %b_my_buffer2), kwargs = {})
        %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, %mul_1), kwargs = {})
        %add_ : [num_users=0] = call_function[target=torch.ops.aten.add_.Tensor](args = (%b_my_buffer2, 1.0), kwargs = {})
        return (add_1,)

Resulting ExportGraphSignature of the non-functional Graph would be::

    # inputs
    p_my_parameter: PARAMETER target='my_parameter'
    b_my_buffer1: BUFFER target='my_buffer1' persistent=True
    b_my_buffer2: BUFFER target='my_buffer2' persistent=True
    x1: USER_INPUT
    x2: USER_INPUT

    # outputs
    add_1: USER_OUTPUT

To get a functional Graph, you can use :func:`run_decompositions`::

    mod = CustomModule()
    ep = torch.export.export(mod, (torch.tensor(1.0), torch.tensor(2.0)))
    ep = ep.run_decompositions()

Resulting Graph is functional::

    graph():
        %p_my_parameter : [num_users=1] = placeholder[target=p_my_parameter]
        %b_my_buffer1 : [num_users=1] = placeholder[target=b_my_buffer1]
        %b_my_buffer2 : [num_users=2] = placeholder[target=b_my_buffer2]
        %x1 : [num_users=1] = placeholder[target=x1]
        %x2 : [num_users=1] = placeholder[target=x2]
        %add : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%x1, %p_my_parameter), kwargs = {})
        %mul : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%add, %b_my_buffer1), kwargs = {})
        %mul_1 : [num_users=1] = call_function[target=torch.ops.aten.mul.Tensor](args = (%x2, %b_my_buffer2), kwargs = {})
        %add_1 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%mul, %mul_1), kwargs = {})
        %add_2 : [num_users=1] = call_function[target=torch.ops.aten.add.Tensor](args = (%b_my_buffer2, 1.0), kwargs = {})
        return (add_2, add_1)

Resulting ExportGraphSignature of the functional Graph would be::

    # inputs
    p_my_parameter: PARAMETER target='my_parameter'
    b_my_buffer1: BUFFER target='my_buffer1' persistent=True
    b_my_buffer2: BUFFER target='my_buffer2' persistent=True
    x1: USER_INPUT
    x2: USER_INPUT

    # outputs
    add_2: BUFFER_MUTATION target='my_buffer2'
    add_1: USER_OUTPUT

input_specsoutput_specsreturnc                 :    [        S U R                   5       5      $ )Nc              3      #    U  HR  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  UR                  v   MT     g 7fN)rG   r   r@   rN   rI   r$   .0ss     r(   	<genexpr>2ExportGraphSignature.parameters.<locals>.<genexpr>  sD      
%vv,,,  !((C( AHH%   "AA	Atuplers   rP   s    r(   
parametersExportGraphSignature.parameters  "     
%%
 
 	
r'   c                 :    [        S U R                   5       5      $ )Nc              3      #    U  HR  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  UR                  v   MT     g 7frx   )rG   r   rA   rN   rI   r$   ry   s     r(   r|   /ExportGraphSignature.buffers.<locals>.<genexpr>"  sD      
%vv)))  !((C( AHH%r~   r   rP   s    r(   buffersExportGraphSignature.buffers   r   r'   c                 :    [        S U R                   5       5      $ )Nc              3      #    U  Hc  nUR                   [        R                  :X  d  M#  UR                  S L d  M4  [	        UR
                  [        5      (       d  MU  UR
                  v   Me     g7f)FN)rG   r   rA   rJ   rN   rI   r$   ry   s     r(   r|   >ExportGraphSignature.non_persistent_buffers.<locals>.<genexpr>+  sW      
%vv)))  ||u$  !((C(	 AHH%s   "A-A-A-A-r   rP   s    r(   non_persistent_buffers+ExportGraphSignature.non_persistent_buffers)  s"     
%%
 
 	
r'   c                 :    [        S U R                   5       5      $ )Nc              3      #    U  HR  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  UR                  v   MT     g 7frx   )rG   r   rB   rN   rI   r$   ry   s     r(   r|   ?ExportGraphSignature.lifted_tensor_constants.<locals>.<genexpr>6  sD      
%vv222  !((C( AHH%r~   r   rP   s    r(   lifted_tensor_constants,ExportGraphSignature.lifted_tensor_constants4  r   r'   c                 :    [        S U R                   5       5      $ )Nc              3      #    U  HR  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  UR                  v   MT     g 7frx   )rG   r   rC   rN   rI   r$   ry   s     r(   r|   :ExportGraphSignature.lifted_custom_objs.<locals>.<genexpr>?  sD      
%vv---  !((C( AHH%r~   r   rP   s    r(   lifted_custom_objs'ExportGraphSignature.lifted_custom_objs=  r   r'   Nc           	         / nU R                    H  nUR                  [        R                  :w  a  M#  [	        UR
                  [        [        [        [        [        45      (       a'  UR                  UR
                  R                  5        M~  [	        UR
                  [        5      (       a'  UR                  UR
                  R                  5        M  [        UR
                   S35      e   [!        U5      $ )Nz is not a valid user inputs)rs   rG   r   r?   rN   rH   r   r   r   r   r   appendr   r   r9   RuntimeErrorr   )rQ   user_inputsr{   s      r(   r    ExportGraphSignature.user_inputsG  s    =?!!Avv---""$#%	 	 ""155::.AEE#344""155;;/"aeeW,G#HII% "& [!!r'   c                    / nU R                    GH,  nUR                  [        R                  [        R                  4;  a  M4  [        UR                  [        [        [        [        45      (       a'  UR                  UR                  R                  5        M  [        UR                  [        5      (       a'  UR                  UR                  R                  5        M  [        UR                  [        5      (       a(  UR                  UR                  R                  5        GM  [!        UR                   S35      e   [#        U5      $ )Nz is not a valid user output)rt   rG   r   r^   r_   rN   rH   r   r   r   r   r   r   r   r9   r   r   r   )rQ   user_outputsr{   s      r(   r   !ExportGraphSignature.user_outputsa  s    >@""Avv&&&&  1A?S  ##AEEJJ/AEE#344##AEEKK0AEE#455##AEEJJ/"aeeW,G#HII# #$ \""r'   c                 :    [        S U R                   5       5      $ )Nc              3   *  #    U  H  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  [        UR                  [        5      (       d  Me  UR                  R                  UR                  4v   M     g 7frx   )	rG   r   r@   rN   rH   r   rI   r$   r   ry   s     r(   r|   <ExportGraphSignature.inputs_to_parameters.<locals>.<genexpr>|  sf      
%vv,,, # 155.1 # 188S)	 #QUUZZ"%   "BB	B*)B_immutable_dictrs   rP   s    r(   inputs_to_parameters)ExportGraphSignature.inputs_to_parametersz  "     
%%
 
 	
r'   c                 :    [        S U R                   5       5      $ )Nc              3   *  #    U  H  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  [        UR                  [        5      (       d  Me  UR                  R                  UR                  4v   M     g 7frx   )	rG   r   rA   rN   rH   r   rI   r$   r   ry   s     r(   r|   9ExportGraphSignature.inputs_to_buffers.<locals>.<genexpr>  sf      
%vv))) # 155.1 # 188S)	 #QUUZZ"%r   r   rP   s    r(   inputs_to_buffers&ExportGraphSignature.inputs_to_buffers  r   r'   c                 :    [        S U R                   5       5      $ )Nc              3   *  #    U  H  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  [        UR                  [        5      (       d  Me  UR                  R                  UR                  4v   M     g 7frx   )	rG   r   r`   rN   rH   r   rI   r$   r   ry   s     r(   r|   9ExportGraphSignature.buffers_to_mutate.<locals>.<genexpr>  sf      
&vv333 # 155.1 # 188S)	 #QUUZZ"&r   r   rt   rP   s    r(   buffers_to_mutate&ExportGraphSignature.buffers_to_mutate  "     
&&
 
 	
r'   c                 :    [        S U R                   5       5      $ )Nc              3   *  #    U  H  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  [        UR                  [        5      (       d  Me  UR                  R                  UR                  4v   M     g 7frx   )	rG   r   ra   rN   rH   r   rI   r$   r   ry   s     r(   r|   <ExportGraphSignature.parameters_to_mutate.<locals>.<genexpr>  sf      
&vv666 # 155.1 # 188S)	 #QUUZZ"&r   r   rP   s    r(   parameters_to_mutate)ExportGraphSignature.parameters_to_mutate  r   r'   c                 :    [        S U R                   5       5      $ )Nc              3   *  #    U  H  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  [        UR                  [        5      (       d  Me  UR                  R                  UR                  4v   M     g 7frx   )	rG   r   rd   rN   rH   r   rI   r$   r   ry   s     r(   r|   =ExportGraphSignature.user_inputs_to_mutate.<locals>.<genexpr>  sf      
&vv777 # 155.1 # 188S)	 #QUUZZ"&r   r   rP   s    r(   user_inputs_to_mutate*ExportGraphSignature.user_inputs_to_mutate  r   r'   c                 :    [        S U R                   5       5      $ )Nc              3   *  #    U  H  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  [        UR                  [        5      (       d  Me  UR                  R                  UR                  4v   M     g 7frx   )	rG   r   rB   rN   rH   r   rI   r$   r   ry   s     r(   r|   IExportGraphSignature.inputs_to_lifted_tensor_constants.<locals>.<genexpr>  sf      
%vv222 # 155.1 # 188S)	 #QUUZZ"%r   r   rP   s    r(   !inputs_to_lifted_tensor_constants6ExportGraphSignature.inputs_to_lifted_tensor_constants  r   r'   c                 :    [        S U R                   5       5      $ )Nc              3   *  #    U  H  nUR                   [        R                  :X  d  M#  [        UR                  [
        5      (       d  MD  [        UR                  [        5      (       d  Me  UR                  R                  UR                  4v   M     g 7frx   )	rG   r   rC   rN   rH   r   rI   r$   r   ry   s     r(   r|   DExportGraphSignature.inputs_to_lifted_custom_objs.<locals>.<genexpr>  sg      
%vv--- # 155"34 # 188S)	 #QUUZZ"%r   r   rP   s    r(   inputs_to_lifted_custom_objs1ExportGraphSignature.inputs_to_lifted_custom_objs  r   r'   c                 j   S n0 n0 nU R                    GH  nUR                  [        R                  :X  af  Ub  [	        S5      e[        UR                  [        5      (       d!  [	        S[        UR                  5       35      eUR                  R                  nM  UR                  [        R                  :X  a  [        UR                  [        5      (       d!  [	        S[        UR                  5       35      e[        UR                  [        5      (       d!  [	        S[        UR                  5       35      eUR                  X$R                  R                  '   GMK  UR                  [        R                  :X  d  GMl  [        UR                  [        5      (       d!  [	        S[        UR                  5       35      e[        UR                  [        5      (       d!  [	        S[        UR                  5       35      eUR                  X4R                  R                  '   GM     Uc  g [        UUUS9$ )Nz multiple LOSS_OUTPUT specs foundz-expected TensorArgument for LOSS_OUTPUT, got z3expected str target for GRADIENT_TO_PARAMETER, got z7expected TensorArgument for GRADIENT_TO_PARAMETER, got z4expected str target for GRADIENT_TO_USER_INPUT, got z8expected TensorArgument for GRADIENT_TO_USER_INPUT, got )ro   rm   rn   )rt   rG   r   r_   rM   rN   rH   r   rO   r   rb   rI   r$   rc   r   )rQ   ro   rm   rn   specs        r(   backward_signature'ExportGraphSignature.backward_signature  s   2435 %%DyyJ222*()KLL!$((N;;(GTXXGWX  #hhmmj>>>!$++s33(MdSWS^S^N_M`a  "$((N;;(QRVW[W_W_R`Qab  :>'6j???!$++s33(NtTXT_T_O`Nab  "$((N;;(RSWX\X`X`SaRbc  ;?++(79 &< &#$;%=
 	
r'   c                     g rx   r   rP   s    r(   assertion_dep_token(ExportGraphSignature.assertion_dep_token  s    r'   c                 L   / nU R                    H  nUR                  [        R                  :X  d  M#  [	        UR
                  [        5      (       d!  [        S[        UR
                  5       35      eUR                  UR
                  R                  5        M     [        U5      $ Nz+expected TokenArgument for TOKEN kind, got )rs   rG   r   rD   rN   rH   r+   rM   rO   r   r   r   )rQ   input_tokensr{   s      r(   r   !ExportGraphSignature.input_tokens  s|    !!Avv(!!%%77(Ed155k]S  ##AEEJJ/ " \""r'   c                 L   / nU R                    H  nUR                  [        R                  :X  d  M#  [	        UR
                  [        5      (       d!  [        S[        UR
                  5       35      eUR                  UR
                  R                  5        M     [        U5      $ r   )rt   rG   r   rD   rN   rH   r+   rM   rO   r   r   r   )rQ   output_tokensr{   s      r(   r   "ExportGraphSignature.output_tokens  s~    ""Avv)))!!%%77(Ed155k]S  $$QUUZZ0 # ]##r'   c                 6   U R                   nUc  g [        U5      S:w  a  [        S[        U5       35      e[        [	        UR                  5       5      5      n[        U R                  5      [        U R                  5      -   nX2:w  a  [        SU SU 35      eg )N   z,expected exactly 1 assertion_dep_token, got z)expected assertion_dep_token_index to be z, got )r   lenrM   nextiterkeysr   r   )rQ   r   assertion_dep_token_indexexpected_indexs       r(   rR   "ExportGraphSignature.__post_init__  s    "66&"#q( >sCV?W>XY  %).A.F.F.H)I$J!T../#d6L6L2MM6 ;N;K6RkQlm  7r'   oldnewc                 d   [        U[        5      (       d  [        S[        U5       35      e[        U[        5      (       d  [        S[        U5       35      e[        [
        [        [        [        [        4nU R                   HL  n[        UR                  U5      (       d  M   UR                  R                  U:X  d  M<  X$R                  l        MN     U R                   HL  n[        UR                  U5      (       d  M   UR                  R                  U:X  d  M<  X%R                  l        MN     g)zB
Replace all uses of the old name with new name in the signature.
zexpected old to be str, got zexpected new to be str, got N)rN   r$   rM   rO   r   r   r   r   r   r+   rt   rH   r   rs   )rQ   r   r   	arg_typesois         r(   replace_all_uses%ExportGraphSignature.replace_all_uses  s     #s## #?S	{!KLL#s## #?S	{!KLL
	 ""A!%%++55::$!$EEJ # !!A!%%++55::$!$EEJ "r'   c                    ^ ^ UU 4S jnU$ )Nc                    > UR                   S:X  a  TR                  U R                  U5        T(       a.  U R                   S:X  a  TR                  U R                  U5        g g g )Noutputplaceholder)opr   r   )r   r   userreplace_inputsrQ   s      r(   _0ExportGraphSignature.get_replace_hook.<locals>._9  sL    ww("%%chh4#&&M"9%%chh4 #:~r'   r   )rQ   r   r   s   `` r(   get_replace_hook%ExportGraphSignature.get_replace_hook8  s    	5 r'   c                     SR                  S U R                   5       5      nSR                  S U R                   5       5      nSU SU S3$ )N
c              3   8   #    U  H  n[        U5      v   M     g 7frx   r$   ry   s     r(   r|   /ExportGraphSignature.__str__.<locals>.<genexpr>B  s     A0@1A0@   c              3   8   #    U  H  n[        U5      v   M     g 7frx   r   ry   s     r(   r|   r   C  s      C1BAQ1Br   z

# inputs
z

# outputs
)joinrs   rt   )rQ   rs   rt   s      r(   rY   ExportGraphSignature.__str__A  sK    iiA0@0@AAyy C1B1B CCk]/,rJJr'   r   )ru   N)F)(r    r!   r"   r#   __doc__listr   r%   r   propertyr   r$   r   r   r   r   r   r:   r;   r<   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   r   r   rY   r&   r   r'   r(   r   r      s   iV i z"" 
JsO 
 
 
C 
 
 

3 
 
 
C 
 
 
JsO 
 
 "Zed(:S(@4(GH " "2 #jut);c)AD)HI # #0 
gc3h&7 
 
 
738#4 
 
 
738#4 
 
 
gc3h&7 
 
 
wsCx'8 
 
 
7383D 
 
 
gc3h.? 
 
 )
$;d$B )
 )
\ WS#X%6%=   	#jo 	# 	# 	$z# 	$ 	$%C %c %2Kr'   r   c                 0    SSK Jn  U" [        U 5      5      $ )z
Creates a mapping where items cannot be added, deleted, or updated.
NOTE: The immutability is shallow (like tuple is an immutable collection).
r   )MappingProxyType)typesr   rp   )itemsr   s     r(   r   r   G  s    
 'DK((r'   ru   c           
      d   SSK JnJnJnJn  SSKJn  [        U [        [        [        [        S 5      [        45      (       a
  [        SU S9$ SU R                  ;  a  [        U  S35      eU R                  S   nU R                   U;   a  [#        U R                   S9$ [%        U5      (       a  ['        U R                   S9$ [        Xu5      (       a  [)        U R                   S9$ [        Xt5      (       a  [+        U R                   S9$ [        Xs5      (       a  [-        U R                   S9$ [        Xr5      (       a0  [/        U R                   UR1                  5       R3                  5       S	9$ [        Xv5      (       a  [/        U R                   UR4                  US
9$ [7        [        U5      5      (       a'  [/        U R                   [9        [        U5      5      US
9$ [        U[        [        [        [        [        S 5      45      (       a  [        U R                   US9$ [        S[        U5       S35      e)Nr   )ScriptObjectSymBoolSymFloatSymIntr	   rU   )r   r9   valz8 is not a constant or a node with a 'val' metadata field)r   )r   r5   )r   r5   r6   z*Encountered an unsupported object of type z0 while writing the metadata for exported program)torchr  r  r  r  "torch._library.fake_class_registryr
   rN   r:   r<   r;   rO   r$   r   metarM   r   r+   r   r   r   r   r   r   _typequalified_namescript_class_namer   r   )nodetoken_namesr  r  r  r  r
   r  s           r(   _make_argument_specr  Q  s   ==C$dE4:s;<<Rt44DIIfLM
 	
 ))E
CyyK$)),,	499--	C	 	 499--	C	"	"TYY//	C	!	!DII..	C	&	& dii399;;U;U;WXX	C	*	* c&;&;c
 	
 
S		"	" &:49&EPS
 	
 
C#tS%d<	=	=TYYc::8c D> ?
 	
r'   graph_signaturer   gmztorch.fx.GraphModuler   c           	      f  ^^^^^^^^^^^^ SSK Jn  U R                  S Ln[        U R                  5      mU R
                  mU R                  m[        U R                  5      mU R                  mU R                  mU R                  mU(       a  U R                  R                  O0 mU(       a  U R                  R                  O0 mU(       a  U R                  R                  OS mU R                  nU R                  mUR                   R"                   Vs/ s H   nUR$                  S:X  d  M  ['        Xe5      PM"     nnUR)                  [+        [-        [/        UR                   R"                  5      5      5      R0                  5       Vs/ s H  n['        UT5      PM     nnS[2        S[4        4UUUU4S jjn	S[6        S[2        S[8        4UUUUUUUU4S	 jjn
U Vs/ s H
  o" U5      PM     nn[;        U5       VVs/ s H  u  pU
" X5      PM     nnn[=        XS
9$ s  snf s  snf s  snf s  snnf )Nr   )_pytreer   inpru   c                   > [        U [        5      (       a  [        [        R                  U S S9$ [        U [
        5      (       d  [        [        R                  U S S9$ U R                  nUT;   a  [        [        R                  U S S9$ UT;   a  [        [        R                  U TU   S9$ UT;   a#  [        [        R                  U TU   TU   T;  S9$ [        SU 35      e)NrG   rH   rI   )rG   rH   rI   rJ   zUnknown tensor input kind: )rN   r+   r   r   rD   r   r?   r   r@   rA   rM   )r  r   r   r   r   r   s     r(   to_input_spec9_convert_to_export_graph_signature.<locals>.to_input_spec  s    c=)))//s4HH#~..)"6"6CMMxx;)"6"6CMM))((+D1 
 &&%%(.-d3;QQ	  !#>tf!EFFr'   idxr   c                 B  > [        U[        5      (       a  [        [        R                  US S9$ [        U[
        5      (       d  [        [        R                  US S9$ UR                  nU [        T5      [        T5      -   [        T	5      -   [        T5      -   :  at  UT;   a  [        [        R                  UTU   S9$ UT;   a  [        [        R                  UTU   S9$ UT	;   a  [        [        R                  UT	U   S9$ [        SU 35      eUT
;   a  [        [        R                  US S9$ UT;   a  [        [        R                  UTU   S9$ UT;   a  [        [        R                  UTU   S9$ UT:X  a  [        [        R                  US S9$ [        SU 35      e)Nr  zUnknown tensor mutation kind: zUnknown tensor output kind: )rN   r+   r   r   rD   r   r^   r   r   r`   ra   rd   rM   rb   rc   r_   )r  r   r   buffer_mutationsgrad_paramsgrad_user_inputsro   r   parameter_mutationsuser_input_mutationsr   s      r(   to_output_spec:_convert_to_export_graph_signature.<locals>.to_output_spec  s   a'':#3#34HH!^,,:#9#9qNNvv%&-@)AAC E
 
  ''!#33+D1 
 ,,!#66.t4 
 --!#77/5  %'EdV%LMM|#!z'='=1TRR$!#99&t, 
 ))!#::+D1 
 $!z'='=1TRR %'CD6%JKKr'   )rs   rt   )torch.utilsr  r   setr   r   r   r   r   r   r   gradients_to_parameterrn   ro   r   r   graphnodesr   r  tree_leavesr   r   reversedargsr[   r   r:   r   	enumerater   )r  r  r   pytreeis_jointr   r  inputsoutputsr  r"  r  rs   r  r   rt   r  r  r  r   r   ro   r   r   r!  r   r   s     `             @@@@@@@@@@@r(   "_convert_to_export_graph_signaturer1  {  s   
 .11=H o112K*??'99334L&88)>>*@@  	**AA   	**CC   	**66 
 #//L#11M HHNN"D77m# 	0D/"   &&tD"((..1I,J'K'P'PQQD 	D-0Q  
G< GI G G22LC 2LL 2LZ 2L 2Lh 288#=%K89B79KL9KvsN3*9KLLKSSs
d 9Ls   H,H	H#H(>H-))dataclassescollections.abcr   r   enumr   r   typingr   r   r
  r
   torch._library.opaque_objectr   r   torch._subclasses.fake_tensorr   r	  &torch._functorch._aot_autograd.schemasr   __all__	dataclassr   r+   r   r   r   r   r   r[   r   r   r   r   r   r   r   r  r%  r$   r1  r   r'   r(   <module>r;     s    /  ' ? M 1 E                 - - - + + +
   R R R<  F F F2    ^K ^K ^KB)'
l '
T|T%|T|T  H|T 	|Tr'   