
    &Vji^U                     t   U d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
mZ d dlZd dlmZ d dlmZmZ ddlmZ erddlmZ g dZ ed	
           G d de	                      Zi Zeeeej                 f         ed<   d Z e            eej        <    G d d          Zej         ej!        ej"        ej#        ej$        j%        e j&        ej'         e             e(d          ej)         ej*        d          dZ+ e,e          D ]Z- e.ee-          e+e-<   dddefdZ/dej0        j1        dej        fdZ2i Z3ee4e5e5f         ej        f         ed<   dej0        j1        dej        fdZ6 ed	
          dede4d         dee5df         fd             Z7 ed	
          d1d!ed"e8fd#            Z9 ed	
          d$             Z: ed	
          d%ed&efd'            Z; ed	
          	 	 	 	 d2dede4ed(f         de
ee5ef                  d)e
e4e                  d*e
ee5ef                  d+e8de
e         fd,            Z< ed	
          	 	 d3d-ej=        j>        de5de4e         de
ee5ef                  d+e8de
e         fd.            Z?d/ej        de4ed(f         dee5ef         d+e8de
e         f
d0Z@dS )4    N)AnyCallablecast
NamedTupleOptionalTYPE_CHECKING)boolean_dispatched)
OpOverloadOpOverloadPacket   )compatibility)Argument)ArgsKwargsPaircheck_for_mutable_operationget_signature_for_torch_opcreate_type_hinttype_matchesnormalize_functionnormalize_moduleF)is_backward_compatiblec                   H    e Zd ZU dZeedf         ed<   eeef         ed<   dS )r   z<
    Simple named tuple for wrapping args/kwargs pairs.
    .argskwargsN)	__name__
__module____qualname____doc__tupler   __annotations__dictstr     S/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/fx/operator_schemas.pyr   r      sF           S/cNr#   r   _manual_overridesc                      g } d }|                      t          j        |                     dt          fd}|                      t          j        |                     | S )Nc                     d S Nr"   )selfs    r$   nonzeroz!_nonzero_schemas.<locals>.nonzero/       r#   as_tuplec                    d S r(   r"   )r)   r,   s     r$   r*   z!_nonzero_schemas.<locals>.nonzero4   r+   r#   )appendinspect	signaturebool)
signaturesr*   s     r$   _nonzero_schemasr3   ,   sy    J   g'001114     g'00111r#   c                       e Zd Zd ZdS )_FakeGlobalNamespacec                 :    |dk    rt           S t          d          )Ntorchz!Expected a torch namespace lookup)r7   RuntimeError)r)   names     r$   __getattr__z _FakeGlobalNamespace.__getattr__@   s    7??L>???r#   N)r   r   r   r:   r"   r#   r$   r5   r5   ?   s(        @ @ @ @ @r#   r5   t)TensorDeviceLayoutnumberFutureAnyEnumTypeQScheme	__torch__NoneTypeStorager;   ts_typeztorch._C.JitTypereturnc                 6    t          | j        t                    S )z
    Convert a TorchScript type to a Python type (including subtypes) via
    eval'ing the annotation_str. _type_eval_globals sets up expressions
    like "List" and "Future" to map to actual types (typing.List and jit.Future)
    )evalannotation_str_type_eval_globals)rF   s    r$    _torchscript_type_to_python_typerL   W   s     &(:;;;r#   	ts_schemac           	         ddl m} g }| j        D ]}t          |j                  }|                                r|j        n|j        }|j        dk    r|j        nd}|j	        r|j
        n|j        }|dk    ra||j        k    sJ |j        }t          |          D ]=\  }}	|	j        |j        k    sJ  ||	j        |j        |	j        |	j                  ||<   >|                     |||||                     d | j        D             }
t'          |
          dk    rd }n+t'          |
          dk    r	|
d         }nt)          |
          }t          j        ||	          S )
Nr   )	Parameterr)   inputfrom)r9   kinddefault
annotationc                 6    g | ]}t          |j                  S r"   )rL   type).0rets     r$   
<listcomp>z9_torchscript_schema_to_signature_impl.<locals>.<listcomp>   s0       7:(22  r#   r   )return_annotation)r/   rO   	argumentsrL   rV   has_default_valuedefault_valueemptyr9   
kwarg_onlyKEYWORD_ONLYPOSITIONAL_OR_KEYWORDPOSITIONAL_ONLY	enumeraterR   rS   rT   r.   returnslenr   	Signature)rM   rO   
parametersargarg_typerS   r9   rR   idxpreturn_typesreturn_types               r$   %_torchscript_schema_to_signature_implrn   `   s    "!!!!!"$J" 
 
3CH=='*'<'<'>'>S###IO 8v--sxx7 ~1I""0 	 6>>9::::: ,D#J//  Qv!@@@@@"+)"2I |	# # #
3 	I4dGQQQ	
 	
 	
 	
 >G>O  L <A	\		a		"1oL))Z;GGGGr#   _SCHEMA_TO_SIGNATURE_CACHEc                     | j         | j        f}t                              |          }||S t	          |           }|t          |<   |S r(   )r9   overload_namero   getrn   )rM   	cache_key	cache_valress       r$    _torchscript_schema_to_signaturerv      sO     	 77I*..y99I
/	
:
:C,/y)Jr#   targetr   )r   .r   r   c                 ^   t          | d          \  }}|r|rg }t          ||          D ]:\  }}	  |j        |i | |                    ||f           +# t          $ r Y 7w xY wd }t          |          dk    rd S t          |          dk    r|d         \  }	}
 ||
           d S d S d S d S )NT)return_schemasc                 :    | j         rt          d|  d          d S )Nz!Tried to trace mutable operation z|. FX only supports functional code, so operations that mutate operands in-place (e.g. via `out` arguments) are not supported)
is_mutabler8   )schemas    r$   throw_if_mutablez5check_for_mutable_operation.<locals>.throw_if_mutable   s?      ") ) ) )   r#   r   r   )r   zipbindr.   	TypeErrorre   )rw   r   r   r2   schemasmatched_schemascandidate_signaturer|   r}   _schema_to_checks              r$   r   r      s(    5VDQQQJ g 
 ,/z7+C+C 	 	'(#($9&999&&(;V'DEEEE   	 	 	 1$$D!!Q&&!0!3A_----- D?   s   $A
A#"A#opry   c                     t           t                    r	 j        g}nt           t                    r! fd                                 D             }not
                                         }|r|r|dfndS t          j        j	        
                               }||rdndS t          j                            |          }d |D             }|r||fn|S )a  
    Given an operator on the `torch` namespace, return a list of `inspect.Signature`
    objects corresponding to the overloads of that op.. May return `None` if a signature
    could not be retrieved.

    Args:
        op (Callable): An operator on the `torch` namespace to look up a signature for

    Returns:
        Optional[List[inspect.Signature]]: A list of signatures for the overloads of this
            operator, or None if the operator signatures could not be retrieved. If
            return_schemas=True, returns a tuple containing the optional Python signatures
            and the optional TorchScript Function signature
    c                 :    g | ]}t          |          j        S r"   )getattr_schema)rW   overloadr   s     r$   rY   z.get_signature_for_torch_op.<locals>.<listcomp>   s&    PPPX72x((0PPPr#   N)NNc                 ,    g | ]}t          |          S r"   )rv   rW   r|   s     r$   rY   z.get_signature_for_torch_op.<locals>.<listcomp>   s!    QQQv26::QQQr#   )
isinstancer
   r   r   	overloadsr%   rr   r7   jit	_builtins_find_builtin_C_jit_get_schemas_for_operator)r   ry   r   overrideaten_fnr2   s   `     r$   r   r      s      "j!! B:,	B(	)	) BPPPPPPP$((,, 	@'5?Hd##4?)%33B77?#1;<<t;(88AAQQQQQJ$2BJ  
Br#   c                    	 t          | t          t          f          rt          | t                    rd }nd }t          |           dk    r |t                    S | d         }| D ]7}t          ||          rt          ||          r|}& |t                    c S  ||          S n'# t          $ r t          j        d|             Y nw xY w| S )a  
    Produces a type hint for the given argument.

    The :func:`create_type_hint` looks for a type hint compatible with the input argument `x`.

    If `x` is a `list` or `tuple`, it looks for an object in the list whose type is a superclass
    of the rest, and uses that as `base_type` for the `List` or `Tuple` to be returned.
    If no such object is found, it defaults to `List[Any]`.

    If `x` is neither a `list` nor a `tuple`, it returns `x`.
    c                     t           |          S r(   )listxs    r$   ret_typez"create_type_hint.<locals>.ret_type  s    7Nr#   c                      t           | df         S )N.)r   r   s    r$   r   z"create_type_hint.<locals>.ret_type  s     C=(r#   r   z@We were not able to successfully create type hint from the type )	r   r   r   re   r   
issubclass	Exceptionwarningswarn)r   r   	base_typer;   s       r$   r   r      s-   
a$'' 	'!T"" )# # # #
) ) ) 1vv{{x}}$!I ) )a++ )	1-- ) !II#8C==(((8I&&&-	'.  
 
 
RqRR	
 	
 	
 	
 	


 Hs   AB+ AB+ 
B+ +!CCsignature_typeargument_typec                    t          | d|           }| u rdS |t          j        u r(| k    r"| j        }t	          fd|D                       S t          | dd           t
          u r| j        d         t          u rt          u rdS t          j                  st          j
        d|  d           dS t          dd           t
          u rt          j        d                   S fd} |          S | t          u rt          j        u rdS | t          j        u rt          t           hv rdS t          j                  r$t          j        |           rt          |           S dS )	N
__origin__Tc              3   8   K   | ]}t          |          V  d S r(   )r   )rW   cr   s     r$   	<genexpr>ztype_matches.<locals>.<genexpr>'  s-      IIa<=11IIIIIIr#   r   z.Does not support nested parametric types, got z. Please file a bug.Fc                     t          | dd           t          urdS | j        }| j        dk    rdS t          fd|D                       S )Nr   F)r"   Tc              3   J   K   | ]}|t           u pt          |          V  d S r(   )Ellipsisr   )rW   r   sig_el_types     r$   r   z=type_matches.<locals>.is_homogeneous_tuple.<locals>.<genexpr>>  s6      XXXD*Q*D*DXXXXXXr#   )r   r   __args__all)r;   	containedr   s     r$   is_homogeneous_tuplez*type_matches.<locals>.is_homogeneous_tuple8  s[    q,--U::u
IzU""tXXXXiXXXXXXr#   )r   typingUnionr   anyr   intr/   isclassr   r   r   r7   dtypenumbersNumberfloat)r   r   sig_origin_typesig_containedr   r   s    `   @r$   r   r     s   nlNKKO&&t &,&&>]+J+J&/IIII=IIIIII~|T22d::$-a0 CK3$6$64{++ 	Meeee   5=,55==m4Q7EEE	Y 	Y 	Y 	Y 	Y $#M222 %+!=!=t''Mc5\,I,It}%% 9'/.*I*I 9-8885r#   .	arg_typeskwarg_typesnormalize_to_only_use_kwargsc                    |i }d}t          | t          j                  s3t          | t          t          f          st          | d          r| j        } t          | t          j                  st          | t          t          f          s| }| t          v rlt          | t                    rJ t          |          }|d         |d         }
}	t          j
        |	          j        t          j
        |
          j        k    rdS |	}t          |          sJ t          j
        t          j        |                    }t          ||||          }nt          |           sJ t          |           }g }|ro|D ]5}	  |j        |i | |                    |           &# t$          $ r Y 2w xY wt'          |          dk    rn"t'          |          dk    rt          |d         |||          }n|||r|nt)          t*          t,                   d          }|r|ni }|D ]~}d}	  |j        |i |}|j                                        D ])\  }}|j        |         }|ot3          |j        |          }*n# t$          $ r d	}Y nw xY w|rt          ||||          } nnFd
                    d |D                       }t9          dt;          j        |            d|           |S )a  
    Returns normalized arguments to PyTorch functions. This means that
    `args/kwargs` will be matched up to the functional's
    signature and return exclusively kwargs in positional order if
    `normalize_to_only_use_kwargs` is True.
    Also populates default values. Does not support positional-only
    parameters or varargs parameters (*args, **kwargs). Does not support modules.

    May require `arg_types` and `kwarg_types` in order to disambiguate overloads.

    Args:
        target (Callable): Function that we are normalizing
        args (Tuple[Any]): Tuple of args to the function
        kwargs (Optional[Dict[str, Any]]): Dict of kwargs to the function
        arg_types (Optional[Tuple[Any]]): Tuple of arg types for the args
        kwarg_types (Optional[Dict[str, Any]]): Dict of arg types for the kwargs
        normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs.

    Returns:

        Returns normalized_args_and_kwargs, or `None` if not successful.
    N_opif_trueif_falser   r   r"   TF
c              3   4   K   | ]}t          |          V  d S r(   )r!   r   s     r$   r   z%normalize_function.<locals>.<genexpr>  s9       1 1(.F1 1 1 1 1 1r#   z Tried to normalize arguments to zy but the schema match was ambiguous! Please provide argument types to the normalize_arguments() call. Available schemas:
)r   typesBuiltinFunctionTyper   r
   hasattrr   r	   r!   r/   r0   rg   callableunwrap&_args_kwargs_to_normalized_args_kwargsr   r   r.   r   re   r   r   r   r[   itemsr   rT   joinr8   r7   typename)rw   r   r   r   r   r   new_args_and_kwargstarget_for_analysis
dispatchedr   r   sigtorch_op_schemasr   r   sig_matchesbound_typesarg_nameri   paramschema_printoutss                        r$   r   r   O  s   > ~vu899	F%5z$BCC	 FE""	  fe788 T6,j9::T %'''
 "&#.....+F3J *9 5z*7MXG!'**5$X..9: : t")+,,,,,/B C CDDDv;
 
 5f== 8	 (8  #,',d=f===#**+>????    H ?##q((_%%**&L#A&f6R' '## (K,C-6 P		DsR<P<PI1<"D++"K/? " "+&*
0*B*=*B!*+.9+ +K 7B6K6Q6Q6S6S " " 2((;(Fx(P.9 /"l$)$4h?" ?""
  ) 0 0 0*/KKK0& 	" F$7$($*$@	!" !" 0 "E	" (,yy 1 12A1 1 1 ( ($ 'b5>&;Q;Q b bO_b b   s%   6"F
F&%F&AI00I?>I?rootc                    	 |                      |          }n&# t          $ r}t          d| d          |d}~ww xY wt          |j        d          rs|j        j        }t          t          j        |d          |j        k    rCt          j
        t          j        |j                            }|i }t          ||||          }	|	S dS )a(  
    Returns normalized arguments to PyTorch modules. This means that
    `args/kwargs` will be matched up to the functional's
    signature and return exclusively kwargs in positional order if
    `normalize_to_only_use_kwargs` is True.
    Also populates default values. Does not support positional-only
    parameters or varargs parameters (*args, **kwargs).

    Args:
        root (nn.Module): root module upon which we query modules
        target (Callable): Function that we are normalizing
        args (Tuple[Any]): Tuple of args to the function
        kwargs (Optional[Dict[str, Any]]): Dict of kwargs to the function
        normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs.

    Returns:

        Returns normalized_args_and_kwargs, or `None` if not successful.
    z$Tried to normalize node with target z# but root did not have that target!Nr   )get_submoduleAttributeErrorr8   r   	__class__r   r   r7   nnr/   r0   r   forwardr   )
r   rw   r   r   r   submode	classnamer   r   s
             r$   r   r     s    6##F++   !6 ! ! !
 
 	
 v,, 	'$-	58Y--1AAA#GN6>$B$BCCC~"HT6#?# # '&4s    
;6;r   c                 L  	 t           j        j        t           j        j        h	t	          	fd| j                                        D                       r.t          | j                                                  g dk    rdS  | j	        |i |}|
                                 i }g }t          | j                  D ]K\  }}|s4|t          |          k     r!|                    |j        |                    ;|j        |         ||<   Lt          t!          |          |          S )a  
    Given a call target, args, and kwargs, return the arguments normalized into
    an ArgsKwargsPair, or None if the type signature is not supported by
    this normalization.

    Args:

        sig (inspect.Signature): Signature object for the target
        args (Tuple): Arguments that appear at the callsite for `target`
        kwargs (Dict): Keyword arguments that appear at the callsite for `target`
        normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs.

    Returns:

        Optional[ArgsKwargsPair]: Normalized args and kwargs for `target`, or `None` if
            this target is not supported.
    c              3   *   K   | ]}|j         vV  d S r(   )rR   )rW   rk   supported_parameter_typess     r$   r   z9_args_kwargs_to_normalized_args_kwargs.<locals>.<genexpr>#  s+      
T
Tq1622
T
T
T
T
T
Tr#   )rP   rQ   to	generatorN)r/   rO   ra   r`   r   rg   valuesr   keysr   apply_defaultsrc   re   r.   r[   r   r   )
r   r   r   r   
bound_args
new_kwargsnew_argsir   r   s
            @r$   r   r     s0   6 	/&! 
T
T
T
TCN<Q<Q<S<S
T
T
TTT 
 ##%%&&*N*N*NNN44*6**J!#JHcn-- < <5+ 	<CIIOOJ078888 * 4U ;Ju%//:666r#   )F)NNNF)NF)Aenumr/   r   r   r   r   r   r   r   r   r   r   r7   torch._jit_internalr	   
torch._opsr
   r   _compatibilityr   noder   __all__r   r%   r    r   rf   r   r3   r*   r5   r<   devicelayoutr   r   r@   EnumqschemerV   UntypedStorageTypeVarrK   dirkr   rL   r   FunctionSchemarn   ro   r   r!   rv   r   r1   r   r   r   r   r   Moduler   r   r"   r#   r$   <module>r      s         K K K K K K K K K K K K K K K K  2 2 2 2 2 2 3 3 3 3 3 3 3 3 ) ) ) ) ) )     e,,,    Z   -, >@ 4$w'8"99: ? ? ?    $4#3#5#5 %-  @ @ @ @ @ @ @ @ lllni9}%%''T

#			   
V / /A#GFA..q<.@ <S < < < <0Hx&0H0H 0H 0H 0Hf HJ DsCx'2C!CD I I Ix&    e,,,$$!/2$<@j<Q$ $ $ -,$N e,,,C C8 CT C C C -,CD e,,,) ) -,)X e,,,/ /S / / / -,/d e,,, (,&*,0).C CC
S/C T#s(^$C c
#	C
 $sCx.)C #'C nC C C -,CL e,,,
 (,).+ +
(/++ *+ T#s(^$	+
 #'+ n+ + + -,+\17		17
S/17 cN17 #'	17
 n17 17 17 17 17 17r#   