
    O j/
                       % S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
JrJrJr  SSKJrJrJr  SSKJrJr  SSKrSSKJr  SSKJr  SSKJrJr  SSKJr  SS	KJr  SS
K J!r!J"r"  SSK#J$r$J%r%J&r&  SSK'J(r(J)r)J*r*J+r+  SSK,J-r-J.r.J/r/J0r0J1r1  SSK2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9J:r:J;r;  SSK<J=r=J>r>  SSK?J@r@  SSKAJBrB  \" S5      rC\%" 5       qD\"\R                  R                  lG        \!\R                  R                  lG        \R                  R                  rHS\Hl         S\HlI        S\HlJ        \@" \HS5        S rK\K\HlL        \-(       a  \R                  " SSS/5      rNOS rNS\Nl         S  rOS! rPS" rQ " S# S$5      rR " S% S&\R5      rS " S' S(\T5      rU " S) S*5      rV " S+ S,\W5      rXS- rY " S. S/5      rZS0\>S1\[S2\R                  Rn                  4S3 jr]\-(       Ga=  / S4Qr^ " S5 S65      r_\^ H  r`S7 ra\b" \_\`\a5        M      " S8 S9\7\US:9rc " S; S<\c5      rd\dR                  R                  5        HS  u  rgrh\i" \h5      (       d  \j" \h\k5      (       d  M#  \gR                  S=5      (       d  \m" \c\g5      (       a  MI  \b" \c\g\h5        MU     S> rn1 S?kroS@ rp\n" \R                  Rn                  5       Hh  u  rgrq\gR                  S=5      (       d  \gR                  SA5      (       a  M4  \g\dR                  ;  d  MF  \g\o;  d  MN  \b" \d\qR                  \p" \g5      5        Mj     O4 " SB S65      r_ " SC S9\R                  Rn                  5      rc " SD S<\c5      rdSE rsSF rtSG ruSgSH jrvSIqw\x\ySJ'       ShSK\\z\{   \|\
\z\{   4   S4   4SL jjr}    ShSM\SNSSO\~SP\
\[/\4   S-  SK\\z\{   \|\
\z\{   4   S4   S2\4SQ jjrSR rSS rST rSU rSM\CS2\C4SV jrSW r\R                  GR                  r\@" \S5        SiSX\[SY\~SZ\~S[\[4S\ jjr " S] S^5      r " S_ S`5      r " Sa Sb5      rSc r\" \Sd5        \" \GR                  Se5        \" \9Sf5        \" \:Sf5        \" \;Sf5        g)jzTorchScript.

This module contains functionality to support the JIT's scripting frontend, notably:
    - torch.jit.script

This is not intended to be imported directly; please use the exposed
functionalities in `torch.jit`.
    N)CallableIteratorMappingSequence)AnyTypeVarUnion)
deprecatedSelf)classes)_get_model_id_qualified_name)log_torchscript_usage)_register_builtin)
_graph_for_script_method_graph_for)JitTypeTraceConfigJitTypeTraceStoremonkeytype_trace)_compile_and_register_classinfer_methods_to_compileScriptMethodStubwrap_cpp_module)_enabled_set_jit_function_cache_set_jit_overload_cache_try_get_jit_cached_function_try_get_jit_cached_overloads)get_default_argsget_jit_class_defget_jit_def)Module)has_torch_functionhas_torch_function_unaryhas_torch_function_variadic)PackageExporterPackageImporter)
set_module   )validate_map_location_Tz
Functionally equivalent to a :class:`ScriptModule`, but represents a single
function and does not have any attributes or Parameters.
ScriptFunctiontorch.jit.ScriptFunctionz	torch.jitc                 .    [         R                  " S5      e)Nz ScriptFunction cannot be pickledpicklePickleErrorclss    b/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/jit/_script.py_reducer5   O   s    


?
@@    	Attributevaluetypec                     U $ N )r8   r9   s     r4   r7   r7   Z   s    r6   a  
    This method is a pass-through function that returns `value`, mostly
    used to indicate to the TorchScript compiler that the left-hand side
    expression is a class instance attribute with type of `type`. Note that
    `torch.jit.Attribute` should only be used in `__init__` method of `jit.ScriptModule`
    subclasses.

    Though TorchScript can infer correct type for most Python expressions, there are some cases where
    type inference can be wrong, including:

    - Empty containers like `[]` and `{}`, which TorchScript assumes to be container of `Tensor`
    - Optional types like `Optional[T]` but assigned a valid value of type `T`, TorchScript would assume
      it is type `T` rather than `Optional[T]`

    In eager mode, it is simply a pass-through function that returns `value`
    without other implications.

    Example:

    .. testcode::

        import torch
        from typing import Dict

        class AttributeModule(torch.jit.ScriptModule):
            def __init__(self) -> None:
                super().__init__()
                self.foo = torch.jit.Attribute(0.1, float)

                # we should be able to use self.foo as a float here
                assert 0.0 < self.foo

                self.names_ages = torch.jit.Attribute({}, Dict[str, int])
                self.names_ages["someone"] = 20
                assert isinstance(self.names_ages["someone"], int)

        m = AttributeModule()
        # m will contain two attributes
        # 1. foo of type float
        # 2. names_ages of type Dict[str, int]

    .. testcleanup::

        del AttributeModule
        del m

    Note: it's now preferred to instead use type annotations instead of `torch.jit.Attribute`:

    .. testcode::

        import torch
        from typing import Dict

        class AttributeModule(torch.nn.Module):
            names: Dict[str, int]

            def __init__(self) -> None:
                super().__init__()
                self.names = {}

        m = AttributeModule()

    .. testcleanup::

        del AttributeModule
        del m

    Args:
        value: An initial value to be assigned to attribute.
        type: A Python type

    Returns:
        Returns `value`
c                      [         $ r;   )type_trace_dbr<   r6   r4   _get_type_trace_dbr?      s    r6   c                     [        XS 5      $ r;   )getattr)r3   names     r4   _get_function_from_typerC      s    3d##r6   c                 h    [        U S5      (       a!  S[        U 5      ;   =(       d    [        U S5      $ g )N	__class____dict__	__slots__)hasattrdirr2   s    r4   _is_new_style_classrJ      s/    sK  SX%Bk)BB !r6   c                   J    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSrg)OrderedDictWrapper   c                     Xl         g r;   _c)selfrP   s     r4   __init__OrderedDictWrapper.__init__   s    r6   c                 X    U R                  5        VVs/ s H  u  pUPM	     snn$ s  snnf r;   itemsrQ   kvs      r4   keysOrderedDictWrapper.keys   "    "jjl+ldal+++   &c                 X    U R                  5        VVs/ s H  u  pUPM	     snn$ s  snnf r;   rU   rW   s      r4   valuesOrderedDictWrapper.values   r\   r]   c                 4    [        U R                  5       5      $ r;   )lenr_   rQ   s    r4   __len__OrderedDictWrapper.__len__   s    4;;=!!r6   c                     [        S5      e)Nz6cannot delete methods or parameters of a script moduleRuntimeErrorrQ   rX   s     r4   __delitem__OrderedDictWrapper.__delitem__   s    STTr6   c                 6    U R                   R                  5       $ r;   )rP   rV   rc   s    r4   rV   OrderedDictWrapper.items   s    ww}}r6   c                 `    X;  a  [        SU 35      eU R                  R                  X5        g )NzICan't add a new parameter after ScriptModule construction. Tried to add ')rh   rP   setattrrW   s      r4   __setitem__OrderedDictWrapper.__setitem__   s2    =[\][^_  	r6   c                 8    U R                   R                  U5      $ r;   )rP   containsri   s     r4   __contains__OrderedDictWrapper.__contains__   s    ww""r6   c                 X    X;  a  [        U5      eU R                  R                  U5      $ r;   )KeyErrorrP   rA   ri   s     r4   __getitem__OrderedDictWrapper.__getitem__   s$    =1+wwq!!r6   rO   N)__name__
__module____qualname____firstlineno__rR   rZ   r_   rd   rj   rV   rp   rt   rx   __static_attributes__r<   r6   r4   rL   rL      s0    ,,"U#"r6   rL   c                   @   ^  \ rS rSrU 4S jrS rS rS rS rSr	U =r
$ )OrderedModuleDict   c                 j   > [         TU ]  [        R                  R	                  U5      5        X l        g r;   )superrR   torch_C
ModuleDict_python_modules)rQ   modulepython_dictrE   s      r4   rR   OrderedModuleDict.__init__   s'    ,,V45  +r6   c                 :    U R                   R                  5       nU$ r;   )r   rV   rQ   rs     r4   rV   OrderedModuleDict.items   s      &&(r6   c                     XR                   ;   $ r;   r   ri   s     r4   rt   OrderedModuleDict.__contains__   s    ((((r6   c                     [        U[        5      (       a*  U R                  R                  X5        X R                  U'   g [        SU SU 35      e)NzgCannot re-assign modules in a ScriptModule with non-scripted module, tried to replace existing module 'z': )
isinstanceScriptModulerP   ro   r   rh   rW   s      r4   rp   OrderedModuleDict.__setitem__   sR     a&&GGOOA!&'  #==>Cs1#G r6   c                      U R                   U   $ r;   r   ri   s     r4   rx   OrderedModuleDict.__getitem__  s    ##A&&r6   r   )rz   r{   r|   r}   rR   rV   rt   rp   rx   r~   __classcell__rE   s   @r4   r   r      s!    +)&' 'r6   r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )
ScriptMetai  c                   >^ ^	 0 T l         [        [        T SS5      5      T l        [	        U5       Hk  n[        US0 5      R                  5        H  u  pVUT R                   U'   M     [        US[        5       5      nT R                  R                  U5      T l        Mm     [        UR                  5       5       HK  u  pV[        U[        5      (       d  M  [        T U5        UT R                   UR                  R                  '   MM     [        T SS5      (       a  [        T
T ]9  XU5        g [        T SS 5      m	[        R                   " T	5      U U	4S	 j5       nUT l        [        T
T ]9  XU5        g )
N__constants__r<   _methods_constants_set_disable_script_metaFrR   c                     g r;   r<   rc   s    r4   <lambda>%ScriptMeta.__init__.<locals>.<lambda>6  s    dr6   c                   > [        T	R                  5      nT
" U /UQ70 UD6  [        T	R                  5      U:  n[        U 5      T	L a  S n[        R                  R
                  R                  XU(       + S9U R                  S'   U R                  R                  nUR                  5        H  n[        X5        M     UR                  5        H  u  px[        X5        M     S H  n[        X5        M     g g )Nc                     [        U 5      n[        US5      (       a8  [        UR                  R	                  5       5       VVs/ s H  u  p#UPM	     snn$ [        U 5      $ s  snnf )Nr   )r9   rH   sortedr   rV   r   )r   r3   rX   rY   s       r4   
make_stubsAScriptMeta.__init__.<locals>.init_then_script.<locals>.make_stubs@  sT    v,CsJ//.4S\\5G5G5I.JK.Jda.JKK7??  Ls   A )share_types_actual_script_module)_parameters_buffers_modules)rb   r   r9   r   jit
_recursivecreate_script_modulerF   r   _concrete_typeget_attributesdelattrget_modules)rQ   argskwargsnum_methodsadded_methods_in_initr   concrete_typerB   _r3   original_inits            r4   init_then_script-ScriptMeta.__init__.<locals>.init_then_script8  s    cll+K$000$'$5$C!DzS @ II((==:O6O >  56 !% : : I I)88:DD' ;,88:GDD'  ;CDD' D/ !r6   )r   setrA   r   reversedrV   unionr   r   r   r   original_methodrz   r   rR   	functoolswraps)r3   rB   basesattrsbaserX   rY   base_constantsr   r   rE   s   `        @r4   rR   ScriptMeta.__init__  s5   ') or!BCUODj"5;;="#Q >")$0@#%"HN!$!3!3!9!9.!IC	 $ 5;;=)DA!-..Q;<Q..778 *
 3.66 GT%0Z1BC		'	( 
(	(> (e,r6   r<   rz   r{   r|   r}   rR   r~   r   r   s   @r4   r   r     s    :- :-r6   r   c                       \ rS rSrS rSrg)_CachedForwardi\  c                 $    U R                  S5      $ )Nforward)__getattr__)rQ   objr3   s      r4   __get___CachedForward.__get__]  s    	**r6   r<   N)rz   r{   r|   r}   r   r~   r<   r6   r4   r   r   \  s    +r6   r   c                       \ rS rSrSrg)ScriptWarningia  r<   Nrz   r{   r|   r}   r~   r<   r6   r4   r   r   a  s    r6   r   c                    [         R                  S:  a  [        R                  " S[        5        O[        R                  " S[        5        [
        (       d  U $ [        R                  " SS9n[        X R                  SS9n[        XU 5      $ )N      z}`torch.jit.script_method` is not supported in Python 3.14+ and may break. Please switch to `torch.compile` or `torch.export`.z\`torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.   	frames_upr   )	self_name)sysversion_infowarningswarnDeprecationWarningr   _jit_internal!createResolutionCallbackFromFramer!   rz   r   )fn_rcbasts      r4   script_methodr   e  st    
7"B	
 	j	
 8	 ::QGD
b++
@CDr**r6   c                   B    \ rS rSrS\\\4   SS4S jrS\S\4S jrSr	g)	ConstMapi  const_mappingreturnNc                     Xl         g r;   r   )rQ   r   s     r4   rR   ConstMap.__init__  s    *r6   attrc                      U R                   U   $ r;   r   )rQ   r   s     r4   r   ConstMap.__getattr__  s    !!$''r6   r   )
rz   r{   r|   r}   r   strr   rR   r   r~   r<   r6   r4   r   r     s1    +gc3h&7 +D +( ( (r6   r   importerscript_module_idr   c                 d   [        U R                  [        R                  R                  5      (       d  [        S5      e[        R                  R                  5       n[        R                  R                  UU R                  U R                  [        U R                  5      U5      n[        U5      $ )z
Call by ``torch.package.PackageImporter``'s Pickler's ``persistent_load`` function.

Performs work of loading and returning a ScriptModule from a ``torch.package`` archive.
z{Loading ScriptObjects from a PackageImporter created from a directory is not supported. Use a package archive file instead.)r   
zip_readerr   r   PyTorchFileReaderrh   CompilationUnit_import_ir_module_from_packagestorage_contextr*   last_map_locationr   )r   r   cu
cpp_modules       r4   unpackage_script_moduler     s     h))588+E+EFFN
 	
 
	!	!	#B88
  h889J :&&r6   )__iter__rd   __neg____mul__rt   __add____sub____pow____truediv____mod____ne____eq____lt____gt____le____ge____and____or____xor__rx   rp   __call____int__	__float____bool____str__	__enter____exit__c                      ^  \ rS rSrSrU 4S jrS\S\4U 4S jjrS\S\SS4U 4S	 jjr	S
\S\S\S\4S jr
S rS\S\4S jrSrU =r$ )RecursiveScriptClassi  a  Wrapper for a TorchScript class instance for use in Python.

An analogue of RecursiveScriptModule for regular objects that are not modules.
This class is a wrapper around a torch._C.ScriptObject that represents an instance
of a TorchScript class and allows it to be used in Python.

Attributes:
    _c [torch._C.ScriptObject]: The C++ object to which attribute lookups and method
        calls are forwarded.
    _props [Dict[str, property]]: A dictionary of properties fetched from self._c and
        exposed on this wrppaer.
c                 &  > [         TU ]  5         SU R                  S'   Xl        U R                  R	                  5        Vs0 s H.  nUR
                  [        UR                  UR                  5      _M0     snU l	        SU R                  S'   g s  snf )NT_initializingF)
r   rR   rF   rP   _propertiesrB   propertygettersetter_props)rQ   	cpp_classproprE   s      r4   rR   RecursiveScriptClass.__init__  s|    G-1DMM/*G
 !GG//11D 		8DKK==1DK
 .3DMM/*s   5Br   r   c                    > U R                   R                  S5      (       a  [        TU ]  U5      $ XR                  ;   a  U R                  U   R                  5       $ [        U R                  U5      $ Nr  )rF   getr   r   r  fgetrA   rP   rQ   r   rE   s     r4   r    RecursiveScriptClass.__getattr__  s[    }}  11w*400{{"{{4(--//477D))r6   r8   Nc                    > U R                   R                  S5      (       a  [        TU ]  X5      $ XR                  ;   a  U R                  U   R                  U5      $ [        U R                  X5        g r$  )rF   r%  r   __setattr__r  fsetro   rP   rQ   r   r8   rE   s      r4   r*   RecursiveScriptClass.__setattr__  sZ    }}  11w*477{{"{{4(--e44DGGT)r6   method_namer   r   c                     U R                   R                  U5      (       d  [        eU R                  U5      nU" U0 UD6$ r;   )rP   _has_method	TypeErrorr   rQ   r.  r   r   self_methods        r4   forward_magic_method)RecursiveScriptClass.forward_magic_method  s>     77&&{33**;7K///r6   c                 .    [         R                  " S5      e)NzScriptClasses cannot be pickledr/   rc   s    r4   __getstate__!RecursiveScriptClass.__getstate__  s    $$%FGGr6   otherc                     U R                   R                  S5      (       a  U R                  SU5      $ U R                  SU5      $ )N__iadd__r  )rP   r0  r4  )rQ   r9  s     r4   r;  RecursiveScriptClass.__iadd__  s=    ww"":..00UCC00EBBr6   )rP   r  )rz   r{   r|   r}   __doc__rR   r   r   r   r*  r4  r7  r   r;  r~   r   r   s   @r4   r  r    s    		3	*C 	*C 	*	*C 	* 	* 	*	0"	0+.	0:=	0	0	H	C$ 	C4 	C 	Cr6   r  c                 6    U R                   " [        /UQ70 UD6$ r;   )r4  r.  rQ   r   r   s      r4   method_templater@    s    ,,[J4J6JJr6   c                      ^  \ rS rSr% Sr/ SQrSU 4S jjr\" 5       r\	S\
4   \S'   S	\S\
4U 4S
 jjrS	\S\
SS4U 4S jjrS rS rS\4S jrSrU =r$ )r   i  a  Wrapper for C++ torch::jit::Module with methods, attributes, and parameters.

A wrapper around C++ ``torch::jit::Module``. ``ScriptModule``\s
contain methods, attributes, parameters, and
constants. These can be accessed the same way as on a normal ``nn.Module``.
)codecode_with_constantsgraphinlined_graphoriginal_namer   Nc                 "   > [         TU ]  5         g r;   r   rR   )rQ   rE   s    r4   rR   ScriptModule.__init__$      Gr6   .r   r   c                 n   > SU R                   ;  a  [        TU ]	  U5      $ [        U R                  U5      $ )Nr   )rF   r   r   rA   r   r'  s     r4   r   ScriptModule.__getattr__)  s2    &dmm;w*400455t<<r6   r8   c                 :  > SU R                   ;  at  [        U[        5      (       aP  SU R                  R                   ;  a  0 U R                  l        UR
                  U R                  U'   UR                  n[        TU ]!  X5      $ [        U R                  X5        g )Nr   __annotations__)rF   r   r7   rE   rN  r9   r8   r   r*  ro   r   r,  s      r4   r*  ScriptModule.__setattr__.  s{    &dmm; eY//
 )0G0GG9;616D((.!KKEw*477D..<r6   c                 "   SU R                   ;   a  U R                  R                  U5      $ [        R                  " SS9n[
        R                  R                  U5      n[        X#S 5      U R                  UR                  5       R                  '   g )Nr   r)   r   )rF   r   definer   r   r   r   _parse_source_defr   r   rB   )rQ   srcrcbr   s       r4   rQ  ScriptModule.defineC  sl    &$--7 1188==  AAANC((,,S1C-=c-MDMM#((*//*r6   c                 6    U R                   R                  5       $ r;   )r   _replicate_for_data_parallelrc   s    r4   rW  )ScriptModule._replicate_for_data_parallelY  s    --JJLLr6   exporterc                     UR                  5       nUR                  R                  U R                  [	        U5      5        [
        U44$ )ap  Save a ScriptModule inside of a ``torch.package`` archive.

Called by ``torch.package.PackageExporter``'s Pickler's ``persistent_id`` when
saving TorchScript objects. Performs act of saving a ScriptModule inside of
a ``torch.package`` archive.

Returns method to load the ScriptModule from a ``torch.package.PackageImporter``'s
Pickler's ``persistent_load`` function.
)get_unique_idscript_module_serializer	serializerP   intr   )rQ   rY  r   s      r4   __reduce_package__ScriptModule.__reduce_package__\  sB      (557--77EUAVW+.>-@AAr6   r<   r   N)rz   r{   r|   r}   r=  __jit_unused_properties__rR   r   r   r   r   rN  r   r   r*  rQ  rW  r&   r_  r~   r   r   s   @r4   r   r     sz    	%
!	 '5&6#s(#6	=C 	=C 	=
	=C 	= 	= 	=*	N,	M	B 	B 	Br6   r   )	metaclassc                     ^  \ rS rSrSrSrU 4S jr\S 5       r\S 5       r	S r
\S 5       r\S	 5       r\S
 5       r\S 5       rS r\" S5      S 5       r\" S5      S 5       rS\S\S\4S jrS\S\S\4S jrS\4S jrS\S\S\4S jr\S 5       rS rS\S\4U 4S jjrS\S\SS4U 4S jjrS\4S jrS\ \!\4   S-  S\4S  jr"S!\S\S\S\4S" jr#S\$\   4S# jr%S$\!S\4S% jr&S& r'S' r(S\)\   4U 4S( jjr*S) r+S* r,S+r-U =r.$ ),RecursiveScriptModuleij  a  Retain the existing isinstance(ScriptModule) behavior.

The core data structure in TorchScript is the ``ScriptModule``. It is an
analogue of torch's ``nn.Module`` and represents an entire model as a tree of
submodules. Like normal modules, each individual module in a ``ScriptModule`` can
have submodules, parameters, and methods. In ``nn.Module``\s methods are implemented
as Python functions, but in ``ScriptModule``\s methods are implemented as
TorchScript functions, a statically-typed subset of Python that contains all
of PyTorch's built-in Tensor operations. This difference allows your
``ScriptModule``\s code to run without the need for a Python interpreter.

``ScriptModule``\s should not be created manually, instead use
either :func:`tracing <torch.jit.trace>` or :func:`scripting <torch.jit.script>`.
Tracing and scripting can be applied incrementally and :ref:`composed as necessary <Types>`.

* Tracing records the tensor operations as executed with a set of example inputs and uses these
  operations to construct a computation graph. You can use the full dynamic behavior of Python with tracing,
  but values other than Tensors and control flow aren't captured in the graph.

* Scripting inspects the Python code of the model
  and compiles it to TorchScript. Scripting allows the use of many `types`_ of values and supports dynamic control flow.
  Many, but not all features of Python are supported by the compiler, so changes to the source code may be necessary.
Tc                 d   > SU R                   S'   Xl        [        TU ]  5         [	        U S5        g )NTr  training)rF   rP   r   rR   r   )rQ   r   rE   s     r4   rR   RecursiveScriptModule.__init__  s-    -1DMM/* GG D*%r6   c                 V    [        U 5      nU" U5        [         R                  U5        U$ )a  
Construct a RecursiveScriptModule that's ready for use.

PyTorch code should use this to construct a RecursiveScriptModule instead
of instead of calling `__init__` directly, as it makes sure the
object is properly finalized (and in the future, we may take
control of how the RecursiveScriptModule instance is created).

Args:
    cpp_module:  The C++ Module that will hold the actual state of
                 this RecursiveScriptModule instance.
    init_fn:  Lambda that initializes the RecursiveScriptModule passed to it.
)re  _finalize_scriptmodule)r   init_fnscript_modules      r4   
_construct RecursiveScriptModule._construct  s,     2*=MM"
 "88G  r6   c                 8   [        [        R                  R                  U R                  5      5      U l        [        [        R                  R                  U R                  5      5      U l        [        U R                  U R                  5      U l	        SU l
        g )NF)rL   r   r   ParameterDictrP   r   
BufferDictr   r   r   r  rl  s    r4   rj  ,RecursiveScriptModule._finalize_scriptmodule  sx    (:&&}'7'78)M% &8##M$4$45&M" &7  -"8"8&M" +0M'r6   c                 J   U R                  U5        [        R                  R                  R	                  U R
                  R                  5       5      U l        0 n[        R                  R                  U R
                  5      R                  5        H  u  p1[        U5      X#'   M     [        U R
                  U5      U l        [        [        R                  R                  U R
                  5      5      U l        [        [        R                  R!                  U R
                  5      5      U l        U R$                  R                  5        VVs0 s H2  u  pE['        U[        R                  R(                  5      (       a  M0  XE_M4     snnU l        SU R$                  S'   gs  snnf )z
Re-construct an instance of RecursiveScriptModule using an instance of a C++ module.

Args:
    cpp_module: The C++ module that this RecursiveScriptModule will be rebuilt around.
Fr  N)rR   r   r   ConcreteModuleTypefrom_jit_typerP   _typer   r   rV   r   r   r   rL   rp  r   rq  r   rF   r   ScriptMethod)rQ   r   modulesrB   rX   rY   s         r4   _reconstruct"RecursiveScriptModule._reconstruct  s)    MM*% #((("="="K"K#D
 G$)HH$7$7$@$F$F$H  /
 ; %I-dggw?DM  2%((2H2H2QRD.uxx/B/B477/KLDM
 !MM//11DA!!UXX%:%:; 1DM
 .3DMM/*s   /F Fc                 L    U R                   R                  S5      R                  $ )zPReturn a string representation of the internal graph for the ``forward`` method.r   )rP   _get_methodrD  rc   s    r4   rD  RecursiveScriptModule.graph  s     77&&y1777r6   c                 .    U R                   R                  $ )z
Return a string representation of the internal graph for the ``forward`` method.

This graph will be preprocessed to inline all function and method calls.
)r   rE  rc   s    r4   rE  #RecursiveScriptModule.inlined_graph  s     <<---r6   c                 .    U R                   R                  $ )zt
Return a pretty-printed representation (as valid Python syntax) of the internal graph for the ``forward`` method.

)r   rB  rc   s    r4   rB  RecursiveScriptModule.code  s     <<$$$r6   c                 T    U R                   R                  nUS   [        US   5      4$ )a4  Return a tuple.

Returns a tuple of:

[0] a pretty-printed representation (as valid Python syntax) of
the internal graph for the ``forward`` method. See `code`.
[1] a ConstMap following the CONSTANT.cN format of the output in [0].
The indices in the [0] output are keys to the underlying constant's values.

r   r)   )r   rC  r   r   s     r4   rC  )RecursiveScriptModule.code_with_constants  s*     00AaD(1Q4.))r6   c                 N    U R                   R                  " [        U5      40 UD6$ )a1  Save with a file-like object.

save(f, _extra_files={})

See :func:`torch.jit.save <torch.jit.save>` which accepts a file-like object.
This function, torch.save(), converts the object to a string, treating it as a path.
DO NOT confuse these two functions when it comes to the 'f' parameter functionality.
)rP   saver   )rQ   fr   s      r4   r  RecursiveScriptModule.save  s      77<<A1&11r6   zLite Interpreter is deprecated. Please consider switching to ExecuTorch.             https://docs.pytorch.org/executorch/stable/getting-started.htmlc                 n    [         R                  " S[        SS9  U R                  R                  " U0 UD6$ )a&  Add (or update) the bytecode session to the script model.

_save_for_lite_interpreter(f)

The updated model is used
in lite interpreter for mobile applications.

Args:
    f: a string containing a file name.
    _extra_files: Map from filename to contents which will be stored as part of 'f'.

Lite Interpreter is deprecated. Please consider switching to ExecuTorch.                 https://docs.pytorch.org/executorch/stable/getting-started.htmlr   
stacklevel)r   r   r   rP   _save_for_mobiler?  s      r4   _save_for_lite_interpreter0RecursiveScriptModule._save_for_lite_interpreter  s8    " MMQ"	 77++T<V<<r6   c                 n    [         R                  " S[        SS9  U R                  R                  " U0 UD6$ )Nr  r   r  )r   r   r   rP   _save_to_buffer_for_mobiler?  s      r4   $_save_to_buffer_for_lite_interpreter:RecursiveScriptModule._save_to_buffer_for_lite_interpreter  s8    
 MMQ"	 7755tFvFFr6   r   r   r   c                 :    U R                   R                  " U0 UD6$ r;   )rP   save_to_bufferr?  s      r4   r  $RecursiveScriptModule.save_to_buffer,  s    77))4:6::r6   c                 6    U R                   R                  5       $ r;   )rP   get_debug_stater?  s      r4   r  %RecursiveScriptModule.get_debug_state/  s    77**,,r6   c                      SU R                    3$ )Nzoriginal_name=)rF  rc   s    r4   
extra_repr RecursiveScriptModule.extra_repr2  s    #D$6$6#788r6   c                 B    U R                   R                  " U /UQ70 UD6$ r;   )r   	graph_forr?  s      r4   r  RecursiveScriptModule.graph_for5  s!    <<))$@@@@r6   c                     [        U 5      [        U R                  R                  5       R	                  5       5      L a  g[        U R                  R                  5       R	                  5       5      $ N )r9   r   rP   rw  rB   rc   s    r4   rF  #RecursiveScriptModule.original_name8  sI     DzS!5!5!788tww}}++-..r6   c                 x    [         R                  " SS9nU R                  R                  U R                  X5        g )Nr)   r   )r   r   rP   _definer   )rQ   rS  rT  s      r4   rQ  RecursiveScriptModule.define?  s,      AAANCGGOOD//:r6   r   c                   > SU R                   ;  a  [        S5      eU R                  (       a  [        TU ]  U5      $ XR
                  ;   a  U R
                  U   $ U R                  R                  U5      (       a  U R                  R                  U5      $ U R                  R                  U5      (       a+  U R                  R                  U5      nX R                   U'   U$ [        TU ]  U5      $ )Nr  zKScriptModule has not been initialized, did you forget to call super's init?)rF   rh   r  r   r   r   rP   rH   rA   r0  r}  )rQ   r   r   rE   s      r4   r   !RecursiveScriptModule.__getattr__K  s    dmm3"a  !!w*400 }}$}}T**&&wwt,,$$T** $ 3 3D 9 '4d#$$7&t,,r6   r8   Nc                   > U R                   (       a  [        TU ]	  X5      $ XR                  ;   a  X R                  U'   g U R                  R                  U5      (       a  U R                  R                  X5        g [        U S5      (       a/  XR                  R                  5       ;   a  [        SU SU S35      e[        TU ]	  X5      $ )Nr   z+Cannot mutate TorchScript constant value: 'z'. Value: '')
r  r   r*  r   rP   rH   ro   r   get_constantsAttributeErrorr,  s      r4   r*  !RecursiveScriptModule.__setattr__c  s    !!w*477}}$&+d#&&,.////==?? %A${SXRYYZ[  w*477r6   c                     [         R                  R                  R                  [        R                  " U R
                  5      5      $ r;   )r   r   r   r   copyrP   rc   s    r4   __copy__RecursiveScriptModule.__copy__~  s*    99''77		$''8JKKr6   memoc                     [         R                  R                  R                  [        R
                  " U R                  U5      5      $ r;   )r   r   r   r   r  deepcopyrP   )rQ   r  s     r4   __deepcopy__"RecursiveScriptModule.__deepcopy__  s,    99''77dggt8TUUr6   r.  c                 r    [        X5      n[        USS 5      [        [        U5      :X  a  [        eU" U0 UD6$ )N__func__)rA   re  NotImplementedErrorr2  s        r4   r4  *RecursiveScriptModule.forward_magic_method  sC     "$4K{J5%{:  *)///r6   c                 $    U R                  S5      $ )Nr   r4  rc   s    r4   r   RecursiveScriptModule.__iter__  s    ,,Z88r6   idxc                 &    U R                  SU5      $ )Nrx   r  )rQ   r  s     r4   rx   !RecursiveScriptModule.__getitem__  s    ,,]C@@r6   c                 $    U R                  S5      $ )Nrd   r  rc   s    r4   rd   RecursiveScriptModule.__len__  s    ,,Y77r6   c                 &    U R                  SU5      $ )Nrt   r  )rQ   keys     r4   rt   "RecursiveScriptModule.__contains__  s    ,,^SAAr6   c                    > U R                   nUR                  [        [        S5      L a  [        TU ]  5       $ U" 5       $ )N__dir__)r  r  rC   re  r   )rQ   r3  rE   s     r4   r  RecursiveScriptModule.__dir__  s=    ,,K$$*+@)LM w((= r6   c                 d    U R                   nUR                  [        [        S5      L a  gU" 5       $ )Nr  T)r  r  rC   re  )rQ   r3  s     r4   r  RecursiveScriptModule.__bool__  s2    --K$$*+@*MN = r6   c                 d    S n[         R                  U R                  R                  5       U5      $ )Nc                     g r;   r<   rr  s    r4   rk  CRecursiveScriptModule._replicate_for_data_parallel.<locals>.init_fn  s    r6   )re  rm  rP   rW  )rQ   rk  s     r4   rW  2RecursiveScriptModule._replicate_for_data_parallel  s.    
 )33446 r6   )rF   r   rP   r   r   r   )/rz   r{   r|   r}   r=  r   rR   staticmethodrm  rj  rz  r  rD  rE  rB  rC  r  r
   r  r  r   r  r  r   r  r  rF  rQ  r   r*  r   r  dictr^  r  r4  r   r   rx   rd   rt   r   r  r  rW  r~   r   r   s   @r4   re  re  j  s"   	0  $	& 
	! 
	!. 

	0 

	0	3@ 
	8 
	8 
	. 
	. 
	% 
	% 
	* 
	*		2 
M

	=	

	=* 
M

	G	

	G	; 	;s 	;s 	;	- 	- 	- 	-	9 	9	A3 	A# 	A# 	A 
	/ 
	/
	;	-C 	-C 	-0	8C 	8 	8 	86	Ld 	L	VT#s(^d%: 	Vt 	V	0"	0+.	0:=	0	0	9hsm 	9	A3 	A3 	A	8	B
	!Xc] 	!	!
	 
	r6   re  __c                 6   ^ SS K mTR                  " U U4S jS9$ )Nr   c                 Z   > TR                   " U 5      =(       d    TR                  " U 5      $ r;   )
isfunctionismethod)xinspects    r4   r   _get_methods.<locals>.<lambda>  s#    W%7%7%:%Qg>N>Nq>Q%Qr6   )	predicate)r  
getmembers)r3   r  s    @r4   _get_methodsr    s!     !!Q
 	
r6   >%   tocpucudaevalhalfr9   applyfloattrain_applydoublebuffersr   ry  children	_get_name	zero_grad
add_moduler  
parameters
state_dictshare_memory_slow_forward_tracing_namenamed_buffersnamed_modules_named_membersnamed_childrenget_extra_stateload_state_dictregister_bufferregister_moduleset_extra_statenamed_parametersregister_parameter_save_to_state_dict_load_from_state_dictc                    ^  U 4S jnU$ )Nc                     > [        TS-   5      e)Nz" is not supported on ScriptModulesrg   )rQ   r   r   rB   s      r4   fail_make_fail.<locals>.fail  s    t&JJKKr6   r<   )rB   r  s   ` r4   
_make_failr    s    	L r6   
_call_implc                       \ rS rSrSrg)r  i  r<   Nr   r<   r6   r4   r  r    s    r6   c                   ,   ^  \ rS rSrSU 4S jjrSrU =r$ )r   i  c                 "   > [         TU ]  5         g r;   rH  rQ   argrE   s     r4   rR   rI    rJ  r6   r<   r;   r   r   s   @r4   r   r         	 	r6   c                   ,   ^  \ rS rSrSU 4S jjrSrU =r$ )re  i  c                 "   > [         TU ]  5         g r;   rH  r  s     r4   rR   rh    rJ  r6   r<   r;   r   r   s   @r4   re  re    r  r6   c                    [        U [        R                  R                  5      (       d  U $ [	        U 5      nX!;   a  U[	        U 5         $ [        U S5      (       a  U R                  5       OU n XU'   0 nU R                  R                  5        H  u  pEUS:X  a,  UR                  5        H  u  pg[        Xq5      XV'   M     XSU'   M7  [        U[        R                  R                  5      (       a$  [        U[        5      (       d  [        XQ5      X4'   M  XSU'   M     UR                  5        H  nXpR                  W'   M     U $ )N__prepare_scriptable__r   )r   r   nnr"   idrH   r  rF   rV   !call_prepare_scriptable_func_implr   r_   )r   r  obj_idnew_obj_dictrB   
sub_modulerX   rY   s           r4   r  r     s   c588??++
WF ~BsG} )05M(N(N""$TW  LLLL..0:"((* A! J
 +!+
EHHOO44Z>
 >
 "C:!TL!+ 1   "T # Jr6   c                     0 n[        X5      $ r;   )r  )r   r  s     r4   call_prepare_scriptable_funcr  G  s    ')D,S77r6   c                 @    [         R                  R                  U 5      $ )a  
Create a ``torch._C.ScriptDict`` instance with the data from ``obj``.

Args:
    obj (dict): The Python dictionary that is used to initialize the ``ScriptDict``
                returned by this function.

Returns:
    An instance of ``torch._C.ScriptDict`` that has the same data as ``obj``
    and can be passed between Python and TorchScript with reference semantics and
    zero copy overhead.
)r   r   
ScriptDict)r   s    r4   create_script_dictr  L  s     88s##r6   c                 @    [         R                  R                  U 5      $ )a  
Create a ``torch._C.ScriptList`` instance with the data from ``obj``.

Args:
    obj (dict): The Python list that is used to initialize the ``ScriptList``
                returned by this function.
Returns:
    An instance of ``torch._C.ScriptList`` that has the same data as ``obj``
    and can be passed between Python and TorchScript with reference semantics and
    zero copy overhead.
)r   r   
ScriptList)r   	type_hints     r4   create_script_listr  \  s     88s##r6   T	_TOPLEVELexample_inputsc                    Ub  [         R                  " S[        SS9  [        U [        5      (       a  U $ [        U [
        5      (       a  U $ [        U [        5      (       a  U $ U(       a  [        5       q[        (       a  [        [        5      n[        U5         [        U[        5      (       a(  UR                  5        H  u  pgU H  nU" U6   M
     M     O/[        U[        5      (       a  U H  n	U " U	6   M
     O[        S5      eS S S 5        O[         R                  " SSS9  [        U [        R                   R"                  5      (       aW  [%        U 5      n [        R&                  R(                  R+                  U [        R&                  R(                  R,                  5      $ [/        U S5      (       a  U R1                  5       OU n [        U [        5      (       a  [3        U 5      $ [        U [        5      (       a  [5        U 5      $ [6        R8                  " U 5      (       a  [;        U 5      n
[=        U [        R                   R"                  5      (       a  [?        SU  S	35      e[=        U [@        RB                  5      (       a  U $ [E        U 5      (       d  [?        S
5      e[G        U RI                  5       5      S:  a  [?        S5      eUc  [J        RL                  " US-   5      n[O        XU
5        U $ [6        RP                  " U 5      (       d  [6        RR                  " U 5      (       Ga  [;        U 5      n
[/        U S5      (       a"  U RT                  n [J        RV                  " U 5      n[/        U S5      (       a  [?        SU RX                  -   5      e[[        U 5        []        U 5      nU(       a  Xl/        U$ [a        X Rb                  5      nUc  [J        RV                  " U 5      n[        Rd                  Rg                  XU[i        U 5      5      nU Rj                  Ul5        SUl1        SUl6        Xl/        [o        X5        U$ [        R&                  R(                  Rq                  U 5      $ ! , (       d  f       GNT= f)Nz^`optimize` is deprecated and has no effect. Use `with torch.jit.optimized_execution()` insteadr   r  zError: Unable to infer types. Please format the inputs to type `List[Tuple]` or `Dict[Callable, List[Tuple]]` to be run with MonkeyType.zWarning: monkeytype is not installed. Please install https://github.com/Instagram/MonkeyType to enable Profile-Directed Typing in TorchScript. Refer to https://github.com/Instagram/MonkeyType/blob/master/README.rst to install MonkeyType. r   r  zType 'zO' cannot be compiled since it inherits from nn.Module, pass an instance insteadzLTorchScript classes must be new-style classes. Please inherit from 'object'.z\TorchScript classes does not support inheritance yet. Please directly inherit from 'object'.r)   __script_if_tracing_wrapper__script_unsupportedzTorchScript error: r,   r-   )9r   r   FutureWarningr   r  r   r,   r   r>   r   r   r  rV   list
ValueErrorr   r  r"   r  r   r   r   r   rH   r  r  r  r  isclassr   
issubclassrh   enumEnumrJ   rb   mror   r   r   r  r  __original_fn#createResolutionCallbackFromClosurer   "_check_directly_compile_overloadedr   _torchdynamo_inliner!   rz   r   _jit_script_compiler   r=  r|   r   create_script_class)r   optimize
_frames_upr   r  monkeytype_configr   example_inputexampleexamplesqualified_namemaybe_already_compiled_fnr   r   s                 r4   _script_implr7  n  s    A		
 #+,,
#|$$
#~&&

 *+ 2= A!"34nd33 2@1E1E1G-'4G"G, (5 2H  55$2X %3 %W  54& MMi 	 #uxx''*3/yy##88%%>>
 	
 s455 &&( 	 #t!#&&#t!#&&s(- c588??++lm  c499%%J"3''0  swwy>A9  < BB:PQ>RD#C~>
			C	 	 G$4$4S$9$9(-3566##C DDSID 3.//4s7O7OOPP*3/$@$E!$<?9,,#||,< DDSIDXX))'7'<
 [[
&4!$(	yy##77<<M 54s   A-Q))
Q8r   r/  r0  r   c                 .   [         R                  S:  a  [        R                  " S[        5        O[        R                  " S[        5        [
        (       d  U $  [        nSq[        U UUS-   UUS9nU(       a  [        S[        U5      S9  UUq$ ! Wqf = f)	ay  Script the function.

Scripting a function or ``nn.Module`` will inspect the source code, compile
it as TorchScript code using the TorchScript compiler, and return a :class:`ScriptModule` or
:class:`ScriptFunction`. TorchScript itself is a subset of the Python language, so not all
features in Python work, but we provide enough functionality to compute on
tensors and do control-dependent operations. For a complete guide, see the
:ref:`language-reference`.

Scripting a dictionary or list copies the data inside it into a TorchScript instance than can be
subsequently passed by reference between Python and TorchScript with zero copy overhead.

``torch.jit.script`` can be used as a function for modules, functions, dictionaries and lists
 and as a decorator ``@torch.jit.script`` for torchscript-classes and functions.

Args:
    obj (Callable, class, or nn.Module):  The ``nn.Module``, function, class type,
                                              dictionary, or list to compile.
    example_inputs (Union[List[Tuple], Dict[Callable, List[Tuple]], None]): Provide example inputs
        to annotate the arguments for a function or ``nn.Module``.

Returns:
    If ``obj`` is ``nn.Module``, ``script`` returns
    a :class:`ScriptModule` object. The returned :class:`ScriptModule` will
    have the same set of sub-modules and parameters as the
    original ``nn.Module``. If ``obj`` is a standalone function,
    a :class:`ScriptFunction` will be returned. If ``obj`` is a ``dict``, then
    ``script`` returns an instance of `torch._C.ScriptDict`. If ``obj`` is a ``list``,
    then ``script`` returns an instance of `torch._C.ScriptList`.

**Scripting a function**
    The ``@torch.jit.script`` decorator will construct a :class:`ScriptFunction`
    by compiling the body of the function.

    Example (scripting a function):

    .. testcode::

        import torch

        @torch.jit.script
        def foo(x, y):
            if x.max() > y.max():
                r = x
            else:
                r = y
            return r

        print(type(foo))  # torch.jit.ScriptFunction

        # See the compiled graph as Python code
        print(foo.code)

        # Call the function using the TorchScript interpreter
        foo(torch.ones(2, 2), torch.ones(2, 2))

    .. testoutput::
        :hide:

        ...

****Scripting a function using example_inputs**
    Example inputs can be used to annotate a function arguments.

    Example (annotating a function before scripting):

    .. testcode::

        import torch

        def test_sum(a, b):
            return a + b

        # Annotate the arguments to be int
        scripted_fn = torch.jit.script(test_sum, example_inputs=[(3, 4)])

        print(type(scripted_fn))  # torch.jit.ScriptFunction

        # See the compiled graph as Python code
        print(scripted_fn.code)

        # Call the function using the TorchScript interpreter
        scripted_fn(20, 100)

    .. testoutput::
        :hide:

        ...

**Scripting an nn.Module**
    Scripting an ``nn.Module`` by default will compile the ``forward`` method and recursively
    compile any methods, submodules, and functions called by ``forward``. If a ``nn.Module`` only uses
    features supported in TorchScript, no changes to the original module code should be necessary. ``script``
    will construct :class:`ScriptModule` that has copies of the attributes, parameters, and methods of
    the original module.

    Example (scripting a simple module with a Parameter):

    .. testcode::

        import torch

        class MyModule(torch.nn.Module):
            def __init__(self, N, M):
                super().__init__()
                # This parameter will be copied to the new ScriptModule
                self.weight = torch.nn.Parameter(torch.rand(N, M))

                # When this submodule is used, it will be compiled
                self.linear = torch.nn.Linear(N, M)

            def forward(self, input):
                output = self.weight.mv(input)

                # This calls the `forward` method of the `nn.Linear` module, which will
                # cause the `self.linear` submodule to be compiled to a `ScriptModule` here
                output = self.linear(output)
                return output

        scripted_module = torch.jit.script(MyModule(2, 3))

    Example (scripting a module with traced submodules):

    .. testcode::

        import torch
        import torch.nn as nn
        import torch.nn.functional as F

        class MyModule(nn.Module):
            def __init__(self) -> None:
                super().__init__()
                # torch.jit.trace produces a ScriptModule's conv1 and conv2
                self.conv1 = torch.jit.trace(nn.Conv2d(1, 20, 5), torch.rand(1, 1, 16, 16))
                self.conv2 = torch.jit.trace(nn.Conv2d(20, 20, 5), torch.rand(1, 20, 16, 16))

            def forward(self, input):
                input = F.relu(self.conv1(input))
                input = F.relu(self.conv2(input))
                return input

        scripted_module = torch.jit.script(MyModule())

    To compile a method other than ``forward`` (and recursively compile anything it calls), add
    the :func:`@torch.jit.export <torch.jit.export>` decorator to the method. To opt out of compilation
    use :func:`@torch.jit.ignore <torch.jit.ignore>` or :func:`@torch.jit.unused <torch.jit.unused>`.

    Example (an exported and ignored method in a module)::

        import torch
        import torch.nn as nn


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

            @torch.jit.export
            def some_entry_point(self, input):
                return input + 10

            @torch.jit.ignore
            def python_only_fn(self, input):
                # This function won't be compiled, so any
                # Python APIs can be used
                import pdb

                pdb.set_trace()

            def forward(self, input):
                if self.training:
                    self.python_only_fn(input)
                return input * 99


        scripted_module = torch.jit.script(MyModule())
        print(scripted_module.some_entry_point(torch.randn(2, 2)))
        print(scripted_module(torch.randn(2, 2)))

    Example ( Annotating forward of nn.Module using example_inputs)::

        import torch
        import torch.nn as nn
        from typing import NamedTuple

        class MyModule(NamedTuple):
        result: List[int]

        class TestNNModule(torch.nn.Module):
            def forward(self, a) -> MyModule:
                result = MyModule(result=a)
                return result

        pdt_model = TestNNModule()

        # Runs the pdt_model in eager model with the inputs provided and annotates the arguments of forward
        scripted_model = torch.jit.script(pdt_model, example_inputs={pdt_model: [([10, 20, ], ), ], })

        # Run the scripted_model with actual inputs
        print(scripted_model([20]))
r   zv`torch.jit.script` is not supported in Python 3.14+ and may break. Please switch to `torch.compile` or `torch.export`.zU`torch.jit.script` is deprecated. Please switch to `torch.compile` or `torch.export`.Fr)   )r   r/  r0  r   r  script)model_id)
r   r   r   r   r   r   r  r7  r   r   )r   r/  r0  r   r  prevrets          r4   r9  r9    s    ` 7"B	
 	c	
 8
	!A~)
 !(]35GH	D	s   3B Bc                     UR                  5        H?  u  p4X0;  d
  X   U:w  d  M  [        R                  R                  R	                  USU 35      e   g )NzDefault parameters on overloads do not affect the runtime so they must equal to the default parameter on the implementation function. Found on parameter )rV   r   r   frontendFrontendError)impl_defaultsoverload_defaultslocrB   overload_values        r4   _check_overload_defaultsrD    sW     1 7 7 9$(;~(M))$$22!F$  !:r6   c                    [        X R                  5      R                  5       n[        R                  R
                  R                  U S S [        R                  " U 5      5      n[        X"R                  5      n[        U 5      n[        U5      n[        R                  " U5      n[        XvUR                  5       5        [        R                  R                  UUUUUU5      n	U	$ r;   )r!   rz   declr   r   annotationsget_signaturer  r  r   r   r*  rD  ranger   _jit_script_compile_overload)
overload_fn	qual_nameimpl_fnoverload_decloverload_signatureimpl_astrA  implementation_defaultsr   r   s
             r4   _compile_function_with_overloadrR    s    -A-ABGGIM..<<T4!1!1+!> 7$4$45H(5.w7<<WEDM4G4G4I 
	.	.
B Ir6   c                 L   [        U 5      n[        U 5      n[        R                  " U5      nUc  U$ X;   a   [	        [        R
                  " SU 5      5      eU Vs/ s H  n[        XBU 5      PM     nnU(       a  X-   n[        X5        [        R                  " U5        U$ s  snf )Nfunction)	r   r   r   _get_fn_overloadsrh   ,get_overload_no_implementation_error_messagerR  r   _clear_fn_overloads)r   existing_compiled_fnsrL  uncompiled_overloadsrK  compiled_fnss         r4   _get_overloadsr[    s    9#>$I(::9E#$$
"FFzSVW
 	
 0/K 	(D/  
 ,; C.%%i0s   B!c                     [        U 5      n[        R                  " U5      (       d  [        U 5      (       a  [	        SU S35      eg )Nz	Function z cannot be directly compiled because it is overloaded. It must be used in a context of a function where its inputs can determine which overload to call.)r   r   rU  r   rh   )r   rL  s     r4   r+  r+  +  sO    $I&&y115RSV5W5W	{ #F F
 	
 6Xr6   c                 b   [         R                  " S[        5        [        R                  " U 5      (       d  [        S5      e[        U 5      (       d  [        S5      e[        U [        R                  R                  5      =(       a    [        U R                  5       5      S:H  nU(       d(  [        U R                  5       5      S:  a  [        S5      e[        U 5      n[        R                  " S5      n[!        X R"                  5      n[        R$                  R'                  X$X15      nXPl        U $ )a$  Decorate to annotate classes or modules of different types.

.. deprecated:: 2.5
    TorchScript is deprecated, please use ``torch.compile`` instead.

This decorator can be used to define an interface that can be used to annotate
classes or modules of different types. This can be used for to annotate a submodule
or attribute class that could have different types that implement the same
interface, or which could be swapped at runtime; or to store a list of modules or
classes of varying types.

It is sometimes used to implement "Callables" - functions or modules that implement
an interface but whose implementations differ and which can be swapped out.

Example:
.. testcode::

    import torch
    from typing import List

    @torch.jit.interface
    class InterfaceType:
        def run(self, x: torch.Tensor) -> torch.Tensor:
            pass

    # implements InterfaceType
    @torch.jit.script
    class Impl1:
        def run(self, x: torch.Tensor) -> torch.Tensor:
            return x.relu()

    class Impl2(torch.nn.Module):
        def __init__(self) -> None:
            super().__init__()
            self.val = torch.rand(())

        @torch.jit.export
        def run(self, x: torch.Tensor) -> torch.Tensor:
            return x + self.val

    def user_fn(impls: List[InterfaceType], idx: int, val: torch.Tensor) -> torch.Tensor:
        return impls[idx].run(val)

    user_fn_jit = torch.jit.script(user_fn)

    impls = [Impl1(), torch.jit.script(Impl2())]
    val = torch.rand(4, 4)
    user_fn_jit(impls, 0, val)
    user_fn_jit(impls, 1, val)
zH`torch.jit.interface` is deprecated. Please use `torch.compile` instead.z$interface must be applied to a classz1TorchScript interfaces must inherit from 'object'r   r   zmTorchScript interface does not support inheritance yet. Please directly inherit from 'object' or 'nn.Module'.r)   )r   r   r   r  r$  rh   rJ   r%  r   r  r"   rb   r(  r   r   r   r    rz   r   _jit_script_interface_compile__torch_script_interface__)r   is_module_interfacer5  rT  r   mangled_classnames         r4   	interfacerb  5  s    f MMR ??3ABBs##NOO %S%((//:Rs3779~QR?R3swwy>A#5D
 	

 %S)N

9
9!
<C C
.C>>S &7"Jr6   c                     [        U 5      n[        R                  R                  X!5      n[        R
                  " U 5      n[        XU5      $ r;   )r   r   r   	CallStackr   'createResolutionCallbackForClassMethodsr   )r   rB  
_qual_nameerror_stackrT  s        r4   _recursive_compile_classrh    s?     %J (($$Z5K

?
?
DC&s<<r6   spaddingoffsetcharc                     U[        U 5      :  a  U[        U 5      -  nSR                  [        X-   5       Vs/ s H  oCPM     sn5      U -   $ s  snf r  )rb   joinrI  )ri  rj  rk  rl  r   s        r4   padro    sL    #a&3q677%(8"9:"9QD"9:;a??:s   Ac                   F    \ rS rSrSS\S\S\4S jjrS\S\4S jrS	 r	S
r
g)_ScriptProfileColumni  header	alignmentrk  c                 6    Xl         X l        X0l        0 U l        g r;   )rr  rs  rk  rows)rQ   rr  rs  rk  s       r4   rR   _ScriptProfileColumn.__init__  s    "$&	r6   linenor8   c                      X R                   U'   g r;   )ru  )rQ   rw  r8   s      r4   add_row_ScriptProfileColumn.add_row  s    !		&r6   c           
         [        U R                  5      n/ nU R                  R                  5        H7  u  p4[	        U5      nUR                  X545        [        [        U5      U5      nM9     U R                  S:  a   XR                  -   nXfU R                  -  -  nOSnU VVs/ s H  u  p5U[        XVU R                  5      4PM     nnn[        U R                  X`R                  5      U4$ s  snnf )Nr   )
rb   rr  ru  rV   r   appendmaxrs  ro  rk  )rQ   
max_lengthru  r  r8   cellrj  s          r4   materialize _ScriptProfileColumn.materialize  s    %
&())//+JCu:DKK$SY
3J ,
 >>A >>1G//GGHLM93c$56M4;;5t;; Ns   $$C-)rs  rr  rk  ru  N)   r   )rz   r{   r|   r}   r   r^  rR   r   ry  r  r~   r<   r6   r4   rq  rq    s4    's 's ' '"c "# "<r6   rq  c                   8    \ rS rSrS\\   S\\   4S jrS rSr	g)_ScriptProfileTablei  colssource_rangec                     Xl         X l        g r;   r  r  )rQ   r  r  s      r4   rR   _ScriptProfileTable.__init__  s    	(r6   c           	         / n/ nSnU R                    H5  nUR                  5       u  pVX5-  nUR                  U[        U5      45        M7     UR                  U5        UR                  [	        S[        U5      SS5      5        U R                   HS  nSnU H7  u  pVUR                  U5      n	U	c  U[	        S[        U5      5      -  nM3  X-  nM9     UR                  U5        MU     SR                  U5      $ )Nr  r   =
)	r  r  r|  r  ro  rb   r  r%  rn  )
rQ   outputscellsheader_buffercolrr  ru  line
row_bufferr  s
             r4   dump_string_ScriptProfileTable.dump_string  s    2499C??,LF#MLL&$t*-. 
 	}%s2s=11c:;%%DJ %xx~<#b#f+"66J&J !& NN:& & yy!!r6   r  N)
rz   r{   r|   r}   r"  rq  r^  rR   r  r~   r<   r6   r4   r  r    s$    )T"67 )tCy )"r6   r  c                   >    \ rS rSrS
S jrS rS rS\4S jrS r	S	r
g)_ScriptProfilei  r   Nc                 J    [         R                  R                  5       U l        g r;   )r   	profilingr  profilerc   s    r4   rR   _ScriptProfile.__init__  s    ((779r6   c                 8    U R                   R                  5         g r;   )r  enablerc   s    r4   r  _ScriptProfile.enable  s    r6   c                 8    U R                   R                  5         g r;   )r  disablerc   s    r4   r  _ScriptProfile.disable  s    r6   c                 b   / nU R                   R                  5        GHy  nUR                  5       nUR                  5       R	                  5       n[        S U 5       5      nU Vs/ s H  ofUS  PM	     nnUR                  5       nU[        U5      -   n[        Xx5      n	[        S5      n
[        S5      n[        S5      n[        SSS5      nUR                  5       nU	 H~  nU
R                  Xf5        UR                  XdXg-
     5        UR                  U5      nUc  M@  UR                  XoR                  5       5        UR                  XoR                  5       5        M     [        XX/[!        U	5      5      nUR#                  UR%                  5       5        GM|     SR'                  U5      $ s  snf )	Nc              3   n   #    U  H+  n[        U5      [        UR                  S 5      5      -
  v   M-     g7f) N)rb   lstrip).0r  s     r4   	<genexpr>-_ScriptProfile.dump_string.<locals>.<genexpr>  s'     T|tTSS)9%::|s   35zLine #Hitsz	Time (ns)zLine Contentsr   r)   z

)r  _dump_statssourcetext
splitlinesminstarting_linenorb   rI  rq  line_mapry  r%  countduration_nsr  r"  r|  r  rn  )rQ   r  source_stats
source_refsource_linesdedentr  
start_lineend_liner  rw  hitstime_nsline_contentsstatsstattables                    r4   r  _ScriptProfile.dump_string  sy    LL446L%,,.J%??,779LT|TTF6BCldMlLC#335J!C$55H 6L)(3F'/D*;7G0!QGM ))+E$t*%%d9J,KLyy#LLzz|4OOD*:*:*<= % (w6\8JE NN5,,./3 74 {{7##- Ds   %F,c                 6    [        U R                  5       5        g r;   )printr  rc   s    r4   dump_ScriptProfile.dump  s    d !r6   )r  ra  )rz   r{   r|   r}   rR   r  r  r   r  r  r~   r<   r6   r4   r  r    s"    :$S $<"r6   r  c                 "    U c  [        S5      eU $ )NzUnwrapping null optional)AssertionError)r  s    r4   _unwrap_optionalr    s    y788Hr6   zaten::_unwrap_optionalzaten::is_scriptingzaten::has_torch_functionr;   )Nr   NN)r   r  )r=  collectionsr  r&  r   r  r0   r   r   collections.abcr   r   r   r   typingr   r   r	   typing_extensionsr
   r   r   torch._jit_internalr   torch._classesr   r   r   torch._utils_internalr   torch.jit._builtinsr   torch.jit._fuserr   r   torch.jit._monkeytype_configr   r   r   torch.jit._recursiver   r   r   r   torch.jit._stater   r   r   r   r   torch.jit.frontendr   r    r!   torch.nnr"   torch.overridesr#   r$   r%   torch.packager&   r'   torch.utilsr(   _serializationr*   r+   r>   r   rx  r  r,   rz   r|   r5   
__reduce__
namedtupler7   r?   rC   rJ   rL   r   r9   r   r   Warningr   r   r   r   r  r   _magic_methodsr  r.  r@  ro   r   re  rF   rV   rB   itemcallabler   r  
startswithrH   r  _compiled_methods_allowlistr  methodendswithr  r  r  r  r  boolrN  r"  tupler  r7  r^  r9  rD  rR  r[  r+  rb  rh  r   ro  rq  r  r  r  is_scriptingr<   r6   r4   <module>r     s         
  A A & & .  + " > 7 1 A 
   P O  
 ; " 1 T] "#":   $.   !((  + 8  
>; '
A $  &&{Wf4EFII	 X$C( "  "F&'* &'b;- ;-|+ +
	G 	+>( (''14'
XX__'0 N>?C ?CB &	K 	$k?C &TBv TBlU Uz
 ,44::<
d~~jx&@&@??4  GL$$?$? 	dD) =
&#P %UXX__5f??4  DMM,$?$? -66677)6??Jt<LM 6 uxx  
$N8
$ $ 	4 
 	LPH=
 $u+tHd5k,A'BDHIH=Z (,LPn	nn n C5#:

%	n
 $u+tHd5k,A'BDHIn 	nj.6
R2 R" Rj= ((** 
?K (@3 @ @c @S @< <8" "8)" )"X "$< = -,,.B C $&@ A *,F G -/I Jr6   