+
    &j
                      a  R t0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
HtHtHtHt ^ RIHtHt ^ RIHtHt ^ RIt^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ R	I H!t!H"t" ^ R
I#H$t$H%t%H&t& ^ RI'H(t(H)t)H*t*H+t+ ^ RI,H-t-H.t.H/t/H0t0H1t1 ^ RI2H3t3H4t4H5t5 ^ RI6H7t7 ^ RI8H9t9H:t:H;t; ^ RI<H=t=H>t> ^ RI?H@t@ ^RIAHBtB ]! R4      tC]%! 4       sD]"]P                  P                  nG        ]!]P                  P                  nG        ]P                  P                  tHR]Hn        R]HnI        R]HnJ        ]@! ]HR4       R tK]K]HnL        ]-'       d   ]P                  ! RRR.4      tNMR tNR]Nn        R tOR tPR  tQ ! R! R"4      tR ! R# R$]R4      tS ! R% R&]T4      tU ! R' R(4      tV ! R) R*]W4      tXR+ tY ! R, R-4      tZR. R/ lt[]-'       Ed   . ROt\ ! R0 R14      t]]\ F  t^R2 t_]`! ]]]^]_4       K  	   ! R3 R4]7]UR57      ta ! R6 R7]a4      tb]bP                  P                  4        FW  w  tetf]g! ]f4      '       g   ]h! ]f]i4      '       g   K%  ]eP                  R84      '       g   ]k! ]a]e4      '       d   KM  ]`! ]a]e]f4       KY  	  R9 tl0 R:kR;kR<kR=kR>kR?kR@kRAkRBkRCkRkRDkREkRFkRGkRHkRIkRJkRKkRLkRMkRNkROkRPkRQkRRkRSkRTkRUkRVkRWkRXkRYkRZkR[kR\kR]ktmR^ tn]l! ]P                  Pn                  4       Fl  w  tetp]eP                  R84      '       g   ]eP                  R_4      '       d   K6  ]e]bP                  9  g   KI  ]e]m9  g   KR  ]`! ]b]pP                  ]n! ]e4      4       Kn  	  M4 ! R` R14      t] ! Ra R4]P                  Pn                  4      ta ! Rb R7]a4      tbRc trRd tsRe ttRRf ltuRgsv] ^ k RRh Ri lltwRRj Rk lltxRl tyRm tzRn t{Ro t|Rp Rq lt}Rr t~]P                  P                  t]@! ]R4       RRs Rt llt ! Ru Rv4      t ! Rw Rx4      t ! Ry Rz4      tR{ t]! ]R|4       ]! ]EP
                  R}4       ]! ]9R~4       ]! ]:R~4       ]! ];R~4       R# )zTorchScript.

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)
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                 .    \         P                  ! R 4      h)z ScriptFunction cannot be pickledpicklePickleErrorclss   &i/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/jit/_script.py_reducer2   O   s    


?
@@    	Attributevaluetypec                     V # N )r5   r6   s   &&r1   r4   r4   Z   s    r3   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                      \         # r8   )type_trace_dbr9   r3   r1   _get_type_trace_dbr<      s    r3   c                     \        WR 4      # r8   )getattr)r0   names   &&r1   _get_function_from_typer@      s    3d##r3   c                 n    \        V R 4      '       d#   R\        V 4      9   ;'       g    \        V R4      # R# )	__class____dict__	__slots__N)hasattrdirr/   s   &r1   _is_new_style_classrG      s2    sK  SX%BBk)BB !r3   c                   V   a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	 tR
tV tR# )OrderedDictWrapperc                    Wn         R # r8   _c)selfrL   s   &&r1   __init__OrderedDictWrapper.__init__   s    r3   c                V    V P                  4        UUu. uF  w  rVNK	  	  upp# u uppi r8   itemsrM   kvs   &  r1   keysOrderedDictWrapper.keys   "    "jjl+ldal+++   %c                V    V P                  4        UUu. uF  w  rVNK	  	  upp# u uppi r8   rQ   rS   s   &  r1   valuesOrderedDictWrapper.values   rX   rY   c                4    \        V P                  4       4      # r8   )lenr[   rM   s   &r1   __len__OrderedDictWrapper.__len__   s    4;;=!!r3   c                    \        R 4      h)z6cannot delete methods or parameters of a script moduleRuntimeErrorrM   rT   s   &&r1   __delitem__OrderedDictWrapper.__delitem__   s    STTr3   c                6    V P                   P                  4       # r8   )rL   rR   r_   s   &r1   rR   OrderedDictWrapper.items   s    ww}}r3   c                d    W9  d   \        R V 24      hV P                  P                  W4       R# )zICan't add a new parameter after ScriptModule construction. Tried to add 'N)rd   rL   setattrrS   s   &&&r1   __setitem__OrderedDictWrapper.__setitem__   s2    =[\][^_  	r3   c                8    V P                   P                  V4      # r8   )rL   containsre   s   &&r1   __contains__OrderedDictWrapper.__contains__   s    ww""r3   c                Z    W9  d   \        V4      hV P                  P                  V4      # r8   )KeyErrorrL   r>   re   s   &&r1   __getitem__OrderedDictWrapper.__getitem__   s$    =1+wwq!!r3   rK   N)__name__
__module____qualname____firstlineno__rN   rV   r[   r`   rf   rR   rl   rp   rt   __static_attributes____classdictcell____classdict__s   @r1   rI   rI      s8     ,,"U#" "r3   rI   c                   J   a a ] tR t^t oV 3R ltR tR tR tR tRt	Vt
V ;t# )OrderedModuleDictc                l   < \         SV `  \        P                  P	                  V4      4       W n        R # r8   )superrN   torch_C
ModuleDict_python_modules)rM   modulepython_dictrB   s   &&&r1   rN   OrderedModuleDict.__init__   s'    ,,V45  +r3   c                :    V P                   P                  4       pV# r8   )r   rR   rM   rs   & r1   rR   OrderedModuleDict.items   s      &&(r3   c                    WP                   9   # r8   r   re   s   &&r1   rp   OrderedModuleDict.__contains__   s    ((((r3   c                    \        V\        4      '       d,   V P                  P                  W4       W P                  V&   R# \        R V RV 24      h)zgCannot re-assign modules in a ScriptModule with non-scripted module, tried to replace existing module 'z': N)
isinstanceScriptModulerL   rk   r   rd   rS   s   &&&r1   rl   OrderedModuleDict.__setitem__   sR     a&&GGOOA!&'  #==>Cs1#G r3   c                (    V P                   V,          # r8   r   re   s   &&r1   rt   OrderedModuleDict.__getitem__  s    ##A&&r3   r   )rv   rw   rx   ry   rN   rR   rp   rl   rt   rz   r{   __classcell__rB   r}   s   @@r1   r   r      s#     +)&' 'r3   r   c                   2   a a ] tR tRt oV 3R ltRtVtV ;t# )
ScriptMetai  c                  <a a	 / S n         \        \        S R R	4      4      S n        \	        V4       Fk  p\        VR/ 4      P                  4        F  w  rVVS P                   V&   K  	  \        VR\        4       4      pS P                  P                  V4      S n        Km  	  \        VP                  4       4       FL  w  rV\        V\        4      '       g   K  \        S V4       VS P                   VP                  P                  &   KN  	  \        S RR4      '       d   \        S
S `9  WV4       R# \        S RR 4      o	\        P                   ! S	4      V V	3R l4       pVS n        \        S
S `9  WV4       R# )
__constants___methods_constants_set_disable_script_metaFNrN   c                     R # r8   r9   r_   s   &r1   <lambda>%ScriptMeta.__init__.<locals>.<lambda>6  s    dr3   c                   < \        S	P                  4      pS
! V .VO5/ VB  \        S	P                  4      V8  p\        V 4      S	J d   R  p\        P                  P
                  P                  WV'       * R7      V P                  R&   V P                  P                  pVP                  4        F  p\        W4       K  	  VP                  4        F  w  rx\        W4       K  	  R F  p\        W4       K  	  R# R# )c                     \        V 4      p\        VR 4      '       d8   \        VP                  P	                  4       4       UUu. uF  w  r#VNK	  	  upp# \        V 4      # u uppi )r   )r6   rE   sortedr   rR   r   )r   r0   rT   rU   s   &   r1   
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_moduleN)_parameters_buffers_modules)r^   r   r6   r   jit
_recursivecreate_script_modulerC   r   _concrete_typeget_attributesdelattrget_modules)rM   argskwargsnum_methodsadded_methods_in_initr   concrete_typer?   _r0   original_inits   &*,      r1   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/ !r3   r9   )r   setr>   r   reversedrR   unionr   r   r   r   original_methodrv   r   rN   	functoolswraps)r0   r?   basesattrsbaserT   rU   base_constantsr   r   rB   s   f&&&     @r1   rN   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,r3   r9   rv   rw   rx   ry   rN   rz   r{   r   r   s   @@r1   r   r     s     :- :-r3   r   c                   &   a  ] tR tRt o R tRtV tR# )_CachedForwardi\  c                $    V P                  R 4      # )forward)__getattr__)rM   objr0   s   &&&r1   __get___CachedForward.__get__]  s    	**r3   r9   N)rv   rw   rx   ry   r   rz   r{   r|   s   @r1   r   r   \  s     + +r3   r   c                       ] tR tRtRtR# )ScriptWarningia  r9   Nrv   rw   rx   ry   rz   r9   r3   r1   r   r   a  s    r3   r   c                 *   \         P                  R8  d   \        P                  ! R\        4       M\        P                  ! R\        4       \
        '       g   V # \        P                  ! ^R7      p\        W P                  RR7      p\        WV 4      # )   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r      )sysversion_infowarningswarnDeprecationWarningr   _jit_internal!createResolutionCallbackFromFramer   rv   r   )fn_rcbasts   &  r1   script_methodr   e  st    
7"B	
 	j	
 8	 ::QGD
b++
@CDr**r3   c                   D   a  ] tR tRt o V 3R lR ltV 3R lR ltRtV tR# )ConstMapi  c                :   < V ^8  d   QhRS[ S[S[3,          RR/# )   const_mappingreturnN)r   strr   )formatr}   s   "r1   __annotate__ConstMap.__annotate__  s$     + +gc3h&7 +D +r3   c                    Wn         R # r8   r   )rM   r   s   &&r1   rN   ConstMap.__init__  s    *r3   c                &   < V ^8  d   QhRS[ RS[/# r   attrr   r   r   )r   r}   s   "r1   r   r     s     ( ( ( (r3   c                (    V P                   V,          # r8   r   )rM   r   s   &&r1   r   ConstMap.__getattr__  s    !!$''r3   r   N)rv   rw   rx   ry   rN   r   rz   r{   r|   s   @r1   r   r     s     + +( (r3   r   c                d    V ^8  d   QhR\         R\        R\        P                  P                  /# )r   importerscript_module_idr   )r%   r   r   nnr    )r   s   "r1   r   r     s,     ' ''14'
XX__'r3   c                f   \        V P                  \        P                  P                  4      '       g   \        R4      h\        P                  P                  4       p\        P                  P                  VV P                  V P                  \        V P                  4      V4      p\        V4      # )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   PyTorchFileReaderrd   CompilationUnit_import_ir_module_from_packagestorage_contextr'   last_map_locationr   )r   r   cu
cpp_modules   &&  r1   unpackage_script_moduler    s     h))588+E+EFFN
 	
 
	!	!	#B88
  h889J :&&r3   c                      a a ] tR tRt oRtV 3R ltV3R lV 3R lltV3R lV 3R lltV3R lR	 ltR
 t	V3R lR lt
RtVtV ;t# )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                &  < \         SV `  4        R V P                  R&   Wn        V P                  P	                  4        Uu/ uF.  pVP
                  \        VP                  VP                  4      bK0  	  upV n	        RV P                  R&   R# u upi )T_initializingFN)
r   rN   rC   rL   _propertiesr?   propertygettersetter_props)rM   	cpp_classproprB   s   && r1   rN   RecursiveScriptClass.__init__  s|    G-1DMM/*G
 !GG//11D 		8DKK==1DK
 .3DMM/*s   4Bc                &   < V ^8  d   QhRS[ RS[/# r   r   )r   r}   s   "r1   r   !RecursiveScriptClass.__annotate__  s     	* 	*C 	*C 	*r3   c                   < V P                   P                  R 4      '       d   \        SV `  V4      # WP                  9   d"   V P                  V,          P                  4       # \        V P                  V4      # )r	  )rC   getr   r   r  fgetr>   rL   rM   r   rB   s   &&r1   r    RecursiveScriptClass.__getattr__  s[    }}  11w*400{{"{{4(--//477D))r3   c                *   < V ^8  d   QhRS[ RS[RR/# r   r   r5   r   Nr   )r   r}   s   "r1   r   r    s"     	* 	*C 	* 	* 	*r3   c                   < V P                   P                  R 4      '       d   \        SV `  W4      # WP                  9   d#   V P                  V,          P                  V4      # \        V P                  W4       R# )r	  N)rC   r  r   __setattr__r  fsetrk   rL   rM   r   r5   rB   s   &&&r1   r   RecursiveScriptClass.__setattr__  sZ    }}  11w*477{{"{{4(--e44DGGT)r3   c                2   < V ^8  d   QhRS[ RS[RS[RS[/# r   method_namer   r   r   r   )r   r}   s   "r1   r   r    s-     	0 	0"	0+.	0:=	0	0r3   c                    V P                   P                  V4      '       g   \        hV P                  V4      pV! V/ VB # r8   )rL   _has_method	TypeErrorr   rM   r"  r   r   self_methods   &&*, r1   forward_magic_method)RecursiveScriptClass.forward_magic_method  s>     77&&{33**;7K///r3   c                .    \         P                  ! R 4      h)zScriptClasses cannot be pickledr,   r_   s   &r1   __getstate__!RecursiveScriptClass.__getstate__  s    $$%FGGr3   c                &   < V ^8  d   QhRS[ RS[ /# )r   otherr   r	   )r   r}   s   "r1   r   r    s     	C 	C$ 	C4 	Cr3   c                    V P                   P                  R 4      '       d   V P                  R V4      # V P                  RV4      # )__iadd____add__)rL   r$  r(  )rM   r.  s   &&r1   r1  RecursiveScriptClass.__iadd__  s=    ww"":..00UCC00EBBr3   )rL   r  )rv   rw   rx   ry   __doc__rN   r   r  r(  r+  r1  rz   r{   r   r   s   @@r1   r  r    sE     		3	* 	*	* 	*	0 	0	H	C 	C 	Cr3   r  c                 6    V P                   ! \        .VO5/ VB # r8   )r(  r"  rM   r   r   s   &*,r1   method_templater7    s    ,,[J4J6JJr3   c                      a a ] tR tRt oRt. ROtV3R lV 3R llt]! 4       tV3R lV 3R llt	V3R lV 3R llt
R	 tR
 tV3R lR ltV3R ltRtVtV ;t# )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``.
c                   < V ^8  d   QhRR/# r   r   Nr9   )r   r}   s   "r1   r   ScriptModule.__annotate__$  s     	 	d 	r3   c                $   < \         SV `  4        R # r8   r   rN   )rM   rB   s   &r1   rN   ScriptModule.__init__$      Gr3   c                &   < V ^8  d   QhRS[ RS[/# r   r   )r   r}   s   "r1   r   r;  )  s     	= 	=C 	=C 	=r3   c                p   < R V P                   9  d   \        SV `	  V4      # \        V P                  V4      # )r   )rC   r   r   r>   r   r  s   &&r1   r   ScriptModule.__getattr__)  s2    &dmm;w*400455t<<r3   c                *   < V ^8  d   QhRS[ RS[RR/# r  r   )r   r}   s   "r1   r   r;  .  s"     	= 	=C 	= 	= 	=r3   c                B  < R V P                   9  dw   \        V\        4      '       dR   RV P                  P                   9  d   / V P                  n        VP
                  V P                  V&   VP                  p\        SV `!  W4      # \        V P                  W4       R# )r   __annotations__N)rC   r   r4   rB   rE  r6   r5   r   r  rk   r   r  s   &&&r1   r  ScriptModule.__setattr__.  s{    &dmm; eY//
 )0G0GG9;616D((.!KKEw*477D..<r3   c                ,   R V P                   9   d   V P                  P                  V4      # \        P                  ! ^R7      p\
        P                  P                  V4      p\        W#R4      V P                  VP                  4       P                  &   R# )r   r   N)rC   r   definer   r   r   r   _parse_source_defr   r   r?   )rM   srcrcbr   s   &&  r1   rH  ScriptModule.defineC  sl    &$--7 1188==  AAANC((,,S1C-=c-MDMM#((*//*r3   c                6    V P                   P                  4       # r8   )r   _replicate_for_data_parallelr_   s   &r1   rN  )ScriptModule._replicate_for_data_parallelY  s    --JJLLr3   c                    < V ^8  d   QhRS[ /# )r   exporter)r$   )r   r}   s   "r1   r   r;  \  s     	B 	B 	Br3   c                    VP                  4       pVP                  P                  V P                  \	        V4      4       \
        V33# )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	serializerL   intr  )rM   rQ  r   s   && r1   __reduce_package__ScriptModule.__reduce_package__\  sB      (557--77EUAVW+.>-@AAr3   c                :   < V ^8  d   Qh/ S[ RS[3,          ;R&   # )r   .r   )r   r   )r   r}   s   "r1   r   r;    s     & #s(#6' r3   r9   )codecode_with_constantsgraphinlined_graphoriginal_name)rv   rw   rx   ry   r4  __jit_unused_properties__rN   r   r   r   r  rH  rN  rW  __annotate_func__rz   r{   r   r   s   @@r1   r   r     sZ     	%
!	 	 '5&6	= 	=
	= 	=*	N,	M	B 	BQ  r3   r   )	metaclassc                     a a ] tR tRt oRtRtV 3R lt]R 4       t]R 4       t	R t
]R 4       t]R	 4       t]R
 4       t]R 4       tR t]! R4      R 4       t]! R4      R 4       tV3R lR ltV3R lR ltV3R lR ltV3R lR lt]R 4       tR tV3R lV 3R lltV3R lV 3R lltV3R lR ltV3R  lR! ltV3R" lR# ltV3R$ lR% ltV3R& lR' lt R( t!R) t"V3R* lV 3R+ llt#R, t$R- t%R.t&Vt'V ;t(# )/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                f   < R V P                   R&   Wn        \        SV `  4        \	        V R4       R# )Tr	  trainingN)rC   rL   r   rN   r   )rM   r  rB   s   &&r1   rN   RecursiveScriptModule.__init__  s-    -1DMM/* GG D*%r3   c                V    \        V 4      pV! V4       \         P                  V4       V# )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.
)rc  _finalize_scriptmodule)r  init_fnscript_modules   && r1   
_construct RecursiveScriptModule._construct  s,     2*=MM"
 "88G  r3   c                :   \        \        P                  P                  V P                  4      4      V n        \        \        P                  P                  V P                  4      4      V n        \        V P                  V P                  4      V n	        R V n
        R# )FN)rI   r   r   ParameterDictrL   r   
BufferDictr   r   r   r	  rj  s   &r1   rh  ,RecursiveScriptModule._finalize_scriptmodule  sx    (:&&}'7'78)M% &8##M$4$45&M" &7  -"8"8&M" +0M'r3   c                L   V P                  V4       \        P                  P                  P	                  V P
                  P                  4       4      V n        / p\        P                  P                  V P
                  4      P                  4        F  w  r1\        V4      W#&   K  	  \        V P
                  V4      V n        \        \        P                  P                  V P
                  4      4      V n        \        \        P                  P!                  V P
                  4      4      V n        V P$                  P                  4        UUu/ uF3  w  rE\'        V\        P                  P(                  4      '       d   K1  WEbK5  	  uppV n        RV P$                  R&   R# u uppi )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)rN   r   r   ConcreteModuleTypefrom_jit_typerL   _typer   r   rR   r   r   r   rI   rn  r   ro  r   rC   r   ScriptMethod)rM   r  modulesr?   rT   rU   s   &&    r1   _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    V P                   P                  R4      P                  # )zPReturn a string representation of the internal graph for the ``forward`` method.r   )rL   _get_methodr\  r_   s   &r1   r\  RecursiveScriptModule.graph  s     77&&y1777r3   c                .    V P                   P                  # )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   r]  r_   s   &r1   r]  #RecursiveScriptModule.inlined_graph  s     <<---r3   c                .    V P                   P                  # )zt
Return a pretty-printed representation (as valid Python syntax) of the internal graph for the ``forward`` method.

)r   rZ  r_   s   &r1   rZ  RecursiveScriptModule.code  s     <<$$$r3   c                d    V P                   P                  pV^ ,          \        V^,          4      3# )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   r   s   & r1   r[  )RecursiveScriptModule.code_with_constants  s*     00AaD(1Q4.))r3   c                N    V P                   P                  ! \        V4      3/ VB # )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.
)rL   saver   )rM   fr   s   &&,r1   r  RecursiveScriptModule.save  s      77<<A1&11r3   zLite Interpreter is deprecated. Please consider switching to ExecuTorch.             https://docs.pytorch.org/executorch/stable/getting-started.htmlc                t    \         P                  ! R\        ^R7       V P                  P                  ! V/ VB # )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.html
stacklevel)r   r   r   rL   _save_for_mobiler6  s   &*,r1   _save_for_lite_interpreter0RecursiveScriptModule._save_for_lite_interpreter  s8    " MMQ"	 77++T<V<<r3   c                t    \         P                  ! R \        ^R7       V P                  P                  ! V/ VB # )r  r  )r   r   r   rL   _save_to_buffer_for_mobiler6  s   &*,r1   $_save_to_buffer_for_lite_interpreter:RecursiveScriptModule._save_to_buffer_for_lite_interpreter  s8    
 MMQ"	 7755tFvFFr3   c                ,   < V ^8  d   QhRS[ RS[ RS[ /# r   r   r   r   r   )r   r}   s   "r1   r   "RecursiveScriptModule.__annotate__,  s"     	; 	; 	;s 	;s 	;r3   c                :    V P                   P                  ! V/ VB # r8   )rL   save_to_bufferr6  s   &*,r1   r  $RecursiveScriptModule.save_to_buffer,  s    77))4:6::r3   c                ,   < V ^8  d   QhRS[ RS[ RS[ /# r  r  )r   r}   s   "r1   r   r  /  s"     	- 	- 	- 	- 	-r3   c                6    V P                   P                  4       # r8   )rL   get_debug_stater6  s   &*,r1   r  %RecursiveScriptModule.get_debug_state/  s    77**,,r3   c                    < V ^8  d   QhRS[ /# r   r   r   )r   r}   s   "r1   r   r  2  s     	9 	9 	9r3   c                     R V P                    2# )zoriginal_name=)r^  r_   s   &r1   
extra_repr RecursiveScriptModule.extra_repr2  s    #D$6$6#788r3   c                ,   < V ^8  d   QhRS[ RS[ RS[ /# r  r  )r   r}   s   "r1   r   r  5  s'     	A 	A3 	A# 	A# 	Ar3   c                B    V P                   P                  ! V .VO5/ VB # r8   )r   	graph_forr6  s   &*,r1   r  RecursiveScriptModule.graph_for5  s!    <<))$@@@@r3   c                    \        V 4      \        V P                  P                  4       P	                  4       4      J d   R # \        V P                  P                  4       P	                  4       4      #  )r6   r   rL   ru  r?   r_   s   &r1   r^  #RecursiveScriptModule.original_name8  sI     DzS!5!5!788tww}}++-..r3   c                    \         P                  ! ^R7      pV P                  P                  V P                  W4       R# )   r   N)r   r   rL   _definer   )rM   rJ  rK  s   && r1   rH  RecursiveScriptModule.define?  s,      AAANCGGOOD//:r3   c                &   < V ^8  d   QhRS[ RS[/# r   r   )r   r}   s   "r1   r   r  K  s     	- 	-C 	-C 	-r3   c                  < R V P                   9  d   \        R4      hV P                  '       d   \        SV `  V4      # WP
                  9   d   V P
                  V,          # V P                  P                  V4      '       d   V P                  P                  V4      # V P                  P                  V4      '       d,   V P                  P                  V4      pW P                   V&   V# \        SV `  V4      # )r	  zKScriptModule has not been initialized, did you forget to call super's init?)rC   rd   r	  r   r   r   rL   rE   r>   r$  r{  )rM   r   r   rB   s   && r1   r   !RecursiveScriptModule.__getattr__K  s    dmm3"a  !!!w*400 }}$}}T**&&wwt,,$$T** $ 3 3D 9 '4d#$$7&t,,r3   c                *   < V ^8  d   QhRS[ RS[RR/# r  r   )r   r}   s   "r1   r   r  c  s"     	8 	8C 	8 	8 	8r3   c                  < V P                   '       d   \        SV `	  W4      # WP                  9   d   W P                  V&   R# V P                  P                  V4      '       d   V P                  P                  W4       R# \        V R 4      '       d1   WP                  P                  4       9   d   \        RV RV R24      h\        SV `	  W4      # )r   z+Cannot mutate TorchScript constant value: 'z'. Value: ''N)
r	  r   r  r   rL   rE   rk   r   get_constantsAttributeErrorr  s   &&&r1   r  !RecursiveScriptModule.__setattr__c  s    !!!w*477}}$&+d#&&,.////==?? %A${SXRYYZ[  w*477r3   c                    < V ^8  d   QhRS[ /# r  r/  )r   r}   s   "r1   r   r  ~  s     	L 	Ld 	Lr3   c                    \         P                  P                  P                  \        P                  ! V P
                  4      4      # r8   )r   r   r   r   copyrL   r_   s   &r1   __copy__RecursiveScriptModule.__copy__~  s*    99''77		$''8JKKr3   c                J   < V ^8  d   QhRS[ S[S[3,          R,          RS[/# )r   memoNr   )dictrV  r   r	   )r   r}   s   "r1   r   r    s,     	V 	VT#s(^d%: 	Vt 	Vr3   c                    \         P                  P                  P                  \        P
                  ! V P                  V4      4      # r8   )r   r   r   r   r  deepcopyrL   )rM   r  s   &&r1   __deepcopy__"RecursiveScriptModule.__deepcopy__  s,    99''77dggt8TUUr3   c                2   < V ^8  d   QhRS[ RS[RS[RS[/# r!  r   )r   r}   s   "r1   r   r    s-     	0 	0"	0+.	0:=	0	0r3   c                t    \        W4      p\        VR R4      \        \        V4      8X  d   \        hV! V/ VB # )__func__N)r>   rc  NotImplementedErrorr&  s   &&*, r1   r(  *RecursiveScriptModule.forward_magic_method  sC     "$4K{J5%{:  *)///r3   c                0   < V ^8  d   QhRS[ S[,          /# r  )r   r   )r   r}   s   "r1   r   r    s     	9 	9hsm 	9r3   c                $    V P                  R 4      # )__iter__r(  r_   s   &r1   r  RecursiveScriptModule.__iter__  s    ,,Z88r3   c                &   < V ^8  d   QhRS[ RS[/# )r   idxr   rV  r   )r   r}   s   "r1   r   r    s     	A 	A3 	A3 	Ar3   c                &    V P                  R V4      # )rt   r  )rM   r  s   &&r1   rt   !RecursiveScriptModule.__getitem__  s    ,,]C@@r3   c                $    V P                  R 4      # )r`   r  r_   s   &r1   r`   RecursiveScriptModule.__len__  s    ,,Y77r3   c                &    V P                  R V4      # )rp   r  )rM   keys   &&r1   rp   "RecursiveScriptModule.__contains__  s    ,,^SAAr3   c                0   < V ^8  d   QhRS[ S[,          /# r  )r   r   )r   r}   s   "r1   r   r    s     	! 	!Xc] 	!r3   c                   < V P                   pVP                  \        \        R 4      J d   \        SV `  4       # V! 4       # )__dir__)r  r  r@   rc  r   )rM   r'  rB   s   & r1   r  RecursiveScriptModule.__dir__  s=    ,,K$$*+@)LM w((= r3   c                h    V P                   pVP                  \        \        R 4      J d   R# V! 4       # )__bool__T)r  r  r@   rc  )rM   r'  s   & r1   r  RecursiveScriptModule.__bool__  s2    --K$$*+@*MN = r3   c                d    R  p\         P                  V P                  P                  4       V4      # )c                     R # r8   r9   rp  s   &r1   ri  CRecursiveScriptModule._replicate_for_data_parallel.<locals>.init_fn  s    r3   )rc  rk  rL   rN  )rM   ri  s   & r1   rN  2RecursiveScriptModule._replicate_for_data_parallel  s.    
 )33446 r3   )rC   r   rL   r   r   r   ))rv   rw   rx   ry   r4  r   rN   staticmethodrk  rh  rx  r  r\  r]  rZ  r[  r  r   r  r  r  r  r  r  r^  rH  r   r  r  r  r(  r  rt   r`   rp   r  r  rN  rz   r{   r   r   s   @@r1   rc  rc  j  s    	0  $	& 
	! 
	!. 

	0 

	0	3@ 
	8 
	8 
	. 
	. 
	% 
	% 
	* 
	*		2 
M

	=	

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

	G	

	G	; 	;	- 	-	9 	9	A 	A 
	/ 
	/
	;	- 	-0	8 	86	L 	L	V 	V	0 	0	9 	9	A 	A	8	B
	! 	!	!
	 
	r3   rc  __c                 <   a ^ RI oSP                  ! V V3R lR7      # )    Nc                 \   < SP                   ! V 4      ;'       g    SP                  ! V 4      # r8   )
isfunctionismethod)xinspects   &r1   r   _get_methods.<locals>.<lambda>  s&    W%7%7%:%Q%Qg>N>Nq>Q%Qr3   )	predicate)r  
getmembers)r0   r  s   &@r1   _get_methodsr    s!     !!Q
 	
r3   r   register_bufferregister_parameterregister_module
add_module_applyapplycudacputofloatdoublehalf
state_dict_save_to_state_dictload_state_dict_load_from_state_dict_named_members
parametersnamed_parametersbuffersnamed_bufferschildrennamed_childrenrw  named_modules	zero_gradshare_memory	_get_namer  _slow_forward_tracing_nameevaltrainget_extra_stateset_extra_statec                    a  V 3R  lpV# )c                 (   < \        SR ,           4      h)z" is not supported on ScriptModulesrc   )rM   r   r   r?   s   &*,r1   fail_make_fail.<locals>.fail  s    t&JJKKr3   r9   )r?   r  s   f r1   
_make_failr    s    	L r3   
_call_implc                       ] tR tRtRtR# )r  i  r9   Nr   r9   r3   r1   r  r    s    r3   c                   6   a a ] tR tRt oRV 3R lltRtVtV ;t# )r   i  c                $   < \         SV `  4        R # r8   r=  rM   argrB   s   &&r1   rN   r>    r?  r3   r9   r8   r   r   s   @@r1   r   r          	 	r3   c                   6   a a ] tR tRt oRV 3R lltRtVtV ;t# )rc  i  c                $   < \         SV `  4        R # r8   r=  r  s   &&r1   rN   rf    r?  r3   r9   r8   r   r   s   @@r1   rc  rc    r  r3   c                    \        V \        P                  P                  4      '       g   V # \	        V 4      pW!9   d   V\	        V 4      ,          # \        V R 4      '       d   V P                  4       MT p WV&   / pV P                  P                  4        F  w  rEVR8X  d-   VP                  4        F  w  rg\        Wq4      WV&   K  	  WSV&   K8  \        V\        P                  P                  4      '       d&   \        V\        4      '       g   \        WQ4      W4&   K  WSV&   K  	  VP                  4        F  pWpP                  X&   K  	  V # )__prepare_scriptable__r   )r   r   r   r    idrE   r   rC   rR   !call_prepare_scriptable_func_implr   r[   )r   r  obj_idnew_obj_dictr?   
sub_modulerT   rU   s   &&      r1   r"  r"     s   c588??++
WF ~BsG} )05M(N(N""$TW  LLLL..0:"((* A! J
 +!+
EHHOO44Z>
 >
 "C:!TL!+ 1   "T # Jr3   c                     / p\        W4      # r8   )r"  )r   r  s   & r1   call_prepare_scriptable_funcr'  G  s    ')D,S77r3   c                @    \         P                  P                  V 4      # )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   &r1   create_script_dictr*  L  s     88s##r3   c                @    \         P                  P                  V 4      # )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   &&r1   create_script_listr.  \  s     88s##r3   Tc                    V ^8  d   QhR\         \        ,          \        \        \         \        ,          3,          ,          R,          /# )r   example_inputsN)listtupler  r   )r   s   "r1   r   r   n  s5     H= H=
 K$xe'<"==DH=r3   c                 Z	   Ve   \         P                  ! R\        ^R7       \        V \        4      '       d   V # \        V \
        4      '       d   V # \        V \        4      '       d   V # V'       d   \        4       s\        '       d   \        \        4      p\        V4      ;_uu_ 4        \        V\        4      '       d*   VP                  4        F  w  rgV F	  pV! V!   K  	  K  	  M1\        V\        4      '       d   V F	  p	V ! V	!   K  	  M\        R4      hR R R 4       M\         P                  ! R^R7       \        V \        P                   P"                  4      '       dX   \%        V 4      p \        P&                  P(                  P+                  V \        P&                  P(                  P,                  4      # \/        V R4      '       d   V P1                  4       MT p \        V \        4      '       d   \3        V 4      # \        V \        4      '       d   \5        V 4      # \6        P8                  ! V 4      '       d   \;        V 4      p
\=        V \        P                   P"                  4      '       d   \?        RV  R24      h\=        V \@        PB                  4      '       d   V # \E        V 4      '       g   \?        R4      h\G        V PI                  4       4      ^8  d   \?        R	4      hVf   \J        PL                  ! V^,           4      p\O        WV
4       V # \6        PP                  ! V 4      '       g   \6        PR                  ! V 4      '       Ed   \;        V 4      p
\/        V R
4      '       d#   V PT                  p \J        PV                  ! V 4      p\/        V R4      '       d   \?        RV PX                  ,           4      h\[        V 4       \]        V 4      pV'       d	   Wn/        V# \a        W Pb                  4      pVf   \J        PV                  ! V 4      p\        Pd                  Pg                  WV\i        V 4      4      pV Pj                  Vn5        RVn1        RVn6        Wn/        \o        W4       V# \        P&                  P(                  Pq                  V 4      #   + '       g   i     ELn; i)Nz^`optimize` is deprecated and has no effect. Use `with torch.jit.optimized_execution()` insteadr  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   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'.__script_if_tracing_wrapper__script_unsupportedzTorchScript error: r)   r*   )9r   r   FutureWarningr   r  r   r)   r   r;   r   r   r  rR   r1  
ValueErrorr   r   r    r'  r   r   r   r   rE   r   r*  r.  r  isclassr   
issubclassrd   enumEnumrG   r^   mror   r   r   r  r  __original_fn#createResolutionCallbackFromClosurer5  "_check_directly_compile_overloadedr   _torchdynamo_inliner   rv   r   _jit_script_compiler   r4  rx   r   create_script_class)r   optimize
_frames_upr   r0  monkeytype_configr   example_inputexampleexamplesqualified_namemaybe_already_compiled_fnr   r   s   &&&&&         r1   _script_implrK  n  s    A		
 #+,,
#|$$
#~&&

 *+ 2= A!"34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44s   *A1RR*	c                    V ^8  d   QhR\         RRR\        R\        \        .\         3,          R,          R\        \
        ,          \        \        \        \
        ,          3,          ,          R,          R\         /# )r   r   rC  NrD  r   r0  r   )r   rV  r   r   r1  r2  r  )r   s   "r1   r   r     sx     n n	nn n C5#:

%	n
 K$xe'<"==Dn 	nr3   c                H   \         P                  R8  d   \        P                  ! R\        4       M\        P                  ! R\        4       \
        '       g   V #  \        pRs\        V VV^,           VVR7      pV'       d   \        R\        V4      R7       VVs#   Xsi ; i)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]))
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`.F)r   rC  rD  r   r0  script)model_idr   )
r   r   r   r   r   r   	_TOPLEVELrK  r   r   )r   rC  rD  r   r0  prevrets   &&&&&  r1   rN  rN    s    ` 7"B	
 	c	
 8
	!A~)
 !(]35GH	D	s   >B B!c                     VP                  4        FE  w  r4W09  g   W,          V8w  g   K  \        P                  P                  P	                  VR V 24      h	  R# )zDefault parameters on overloads do not affect the runtime so they must equal to the default parameter on the implementation function. Found on parameter N)rR   r   r   frontendFrontendError)impl_defaultsoverload_defaultslocr?   overload_values   &&&  r1   _check_overload_defaultsrZ    sW     1 7 7 9$(;~(M))$$22!F$  !:r3   c                    \        W P                  4      P                  4       p\        P                  P
                  P                  V R R \        P                  ! V 4      4      p\        W"P                  4      p\        V 4      p\        V4      p\        P                  ! V4      p\        WvVP                  4       4       \        P                  P                  VVVVVV4      p	V	# r8   )r   rv   declr   r   annotationsget_signaturer  r  r   r   r>  rZ  ranger   _jit_script_compile_overload)
overload_fn	qual_nameimpl_fnoverload_decloverload_signatureimpl_astrW  implementation_defaultsr   r   s
   &&&       r1   _compile_function_with_overloadrh    s    -A-ABGGIM..<<T4!1!1+!> 7$4$45H(5.w7<<WEDM4G4G4I 
	.	.
B Ir3   c                 X   \        V 4      p\        V 4      p\        P                  ! V4      pVf   V# W9   d!   \	        \        P
                  ! RV 4      4      hV Uu. uF  p\        WBV 4      NK  	  ppV'       d	   W,           p\        W4       \        P                  ! V4       V# u upi )Nfunction)	r   r   r   _get_fn_overloadsrd   ,get_overload_no_implementation_error_messagerh  r   _clear_fn_overloads)r   existing_compiled_fnsrb  uncompiled_overloadsra  compiled_fnss   &     r1   _get_overloadsrq    s    9#>$I(::9E#$$
"FFzSVW
 	
 0/K 	(D/  
 ,; C.%%i0s   B'c                     \        V 4      p\        P                  ! V4      '       g   \        V 4      '       d   \	        R V R24      hR# )z	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.N)r   r   rk  r   rd   )r   rb  s   & r1   r?  r?  +  sO    $I&&y115RSV5W5W	{ #F F
 	
 6Xr3   c                0    V ^8  d   QhR\         R\         /# )r   r   r   )r(   )r   s   "r1   r   r   5  s     R R2 R" Rr3   c                l   \         P                  ! R\        4       \        P                  ! V 4      '       g   \        R4      h\        V 4      '       g   \        R4      h\        V \        P                  P                  4      ;'       d    \        V P                  4       4      ^8H  pV'       g*   \        V P                  4       4      ^8  d   \        R4      h\        V 4      p\        P                  ! ^4      p\!        W P"                  4      p\        P$                  P'                  W$W14      pWPn        V # )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'zmTorchScript interface does not support inheritance yet. Please directly inherit from 'object' or 'nn.Module'.)r   r   r   r  r8  rd   rG   r9  r   r   r    r^   r<  r   r   r   r   rv   r   _jit_script_interface_compile__torch_script_interface__)r   is_module_interfacerI  rK  r   mangled_classnames   &     r1   	interfacery  5  s    f MMR ??3ABBs##NOO %S%((//:RRs3779~QR?R3swwy>A#5D
 	

 %S)N

9
9!
<C C
.C>>S &7"Jr3   c                     \        V 4      p\        P                  P                  W!4      p\        P
                  ! V 4      p\        WV4      # r8   )r   r   r   	CallStackr   'createResolutionCallbackForClassMethodsr   )r   rX  
_qual_nameerror_stackrK  s   &&   r1   _recursive_compile_classr    s?     %J (($$Z5K

?
?
DC&s<<r3   c                H    V ^8  d   QhR\         R\        R\        R\         /# )r   spaddingoffsetcharr   rV  )r   s   "r1   r   r     s.     @ @3 @ @c @S @r3   c                     V\        V 4      8  d   V\        V 4      ,          pR P                  \        W,           4       Uu. uF  qCNK  	  up4      V ,           # u upi r  )r^   joinr_  )r  r  r  r  r   s   &&&& r1   padr    sL    #a&3q677%(8"9:"9QD"9:;a??:s   
Ac                   N   a  ] tR tRt o R	V 3R lR lltV 3R lR ltR tRtV tR# )
_ScriptProfileColumni  c                ,   < V ^8  d   QhRS[ RS[RS[/# )r   header	alignmentr  r  )r   r}   s   "r1   r   !_ScriptProfileColumn.__annotate__  s"     ' 's 's ' 'r3   c                8    Wn         W n        W0n        / V n        R # r8   )r  r  r  rows)rM   r  r  r  s   &&&&r1   rN   _ScriptProfileColumn.__init__  s    "$&	r3   c                &   < V ^8  d   QhRS[ RS[/# )r   linenor5   r  )r   r}   s   "r1   r   r    s     " "c "# "r3   c                "    W P                   V&   R # r8   )r  )rM   r  r5   s   &&&r1   add_row_ScriptProfileColumn.add_row  s    !		&r3   c           
        \        V P                  4      p. pV P                  P                  4        F7  w  r4\	        V4      pVP                  W534       \        \        V4      V4      pK9  	  V P                  ^ 8  d-   WP                  ,           pWfV P                  ,          ,          pM^ pV UUu. uF  w  r5V\        WVV P                  4      3NK  	  ppp\        V P                  W`P                  4      V3# u uppi )r  )
r^   r  r  rR   r   appendmaxr  r  r  )rM   
max_lengthr  r  r5   cellr  s   &      r1   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   1#C9)r  r  r  r  N)   r  )	rv   rw   rx   ry   rN   r  r  rz   r{   r|   s   @r1   r  r    s#     ' '" "< <r3   r  c                   8   a  ] tR tRt o V 3R lR ltR tRtV tR# )_ScriptProfileTablei  c                F   < V ^8  d   QhRS[ S[,          RS[ S[,          /# )r   colssource_range)r1  r  rV  )r   r}   s   "r1   r    _ScriptProfileTable.__annotate__  s%     ) )T"67 )tCy )r3   c                    Wn         W n        R # r8   r  r  )rM   r  r  s   &&&r1   rN   _ScriptProfileTable.__init__  s    	(r3   c           	        . p. pR pV P                    F9  pVP                  4       w  rVW5,          pVP                  V\        V4      34       K;  	  VP                  V4       VP                  \	        R \        V4      ^ R4      4       V P                   F\  pR pV F@  w  rVVP                  V4      p	V	f   V\	        R \        V4      4      ,          pK8  W,          pKB  	  VP                  V4       K^  	  RP                  V4      # )r  =
)	r  r  r  r  r  r^   r  r  r  )
rM   outputscellsheader_buffercolr  r  line
row_bufferr  s
   &         r1   dump_string_ScriptProfileTable.dump_string  s    2499C??,LF#MLL&$t*-. 
 	}%s2s=11c:;%%DJ %xx~<#b#f+"66J&J !& NN:& & yy!!r3   r  N)rv   rw   rx   ry   rN   r  rz   r{   r|   s   @r1   r  r    s     ) )" "r3   r  c                   V   a  ] tR tRt o V 3R lR ltR tR tV 3R lR ltR tR	t	V t
R
# )_ScriptProfilei  c                   < V ^8  d   QhRR/# r:  r9   )r   r}   s   "r1   r   _ScriptProfile.__annotate__  s     : :$ :r3   c                L    \         P                  P                  4       V n        R # r8   )r
   	profilingr  profiler_   s   &r1   rN   _ScriptProfile.__init__  s    ((779r3   c                :    V P                   P                  4        R # r8   )r  enabler_   s   &r1   r  _ScriptProfile.enable  s    r3   c                :    V P                   P                  4        R # r8   )r  disabler_   s   &r1   r  _ScriptProfile.disable  s    r3   c                    < V ^8  d   QhRS[ /# r  r  )r   r}   s   "r1   r   r    s     $ $S $r3   c                z   . pV P                   P                  4        EF  pVP                  4       pVP                  4       P	                  4       p\        R  V 4       4      pV Uu. uF  qfVR NK	  	  ppVP                  4       pV\        V4      ,           p\        Wx4      p	\        R4      p
\        R4      p\        R4      p\        R^ ^4      pVP                  4       pV	 F  pV
P                  Wf4       VP                  WdWg,
          ,          4       VP                  V4      pVf   KI  VP                  WoP                  4       4       VP                  WoP                  4       4       K  	  \        WW.\!        V	4      4      pVP#                  VP%                  4       4       EK  	  RP'                  V4      # u upi )c              3   v   "   T F/  p\        V4      \        VP                  R 4      4      ,
          x  K1  	  R# 5i) N)r^   lstrip).0r  s   & r1   	<genexpr>-_ScriptProfile.dump_string.<locals>.<genexpr>  s*     T|tTSS)9%:::|s   79NzLine #Hitsz	Time (ns)zLine Contentsz

)r  _dump_statssourcetext
splitlinesminstarting_linenor^   r_  r  line_mapr  r  countduration_nsr  r1  r  r  r  )rM   r  source_stats
source_refsource_linesdedentr  
start_lineend_liner  r  hitstime_nsline_contentsstatsstattables   &                r1   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   %F8c                8    \        V P                  4       4       R # r8   )printr  r_   s   &r1   dump_ScriptProfile.dump  s    d !r3   )r  N)rv   rw   rx   ry   rN   r  r  r  r  rz   r{   r|   s   @r1   r  r    s-     : :$ $<" "r3   r  c                 $    V f   \        R4      hV # )NzUnwrapping null optional)AssertionError)r  s   &r1   _unwrap_optionalr    s    y788Hr3   zaten::_unwrap_optionalzaten::is_scriptingzaten::has_torch_functionc                @    V ^8  d   Qh/ ^ \         9   d
   \        ;R&   # )r   rP  )__conditional_annotations__bool)r   s   "r1   r   r      s       T#  4 U#r3   )r  r`   __neg____mul__rp   r2  __sub____pow____truediv____mod____ne____eq____lt____gt____le____ge____and____or____xor__rt   rl   __call____int__	__float__r  __str__	__enter____exit__r8   )Nr  NN)r  r  )r  r4  collectionsr  r:  r   r  r-   r   r   collections.abcr   r   r   r   typingr   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   rv  r  r)   rv   rx   r2   
__reduce__
namedtupler4   r<   r@   rG   rI   r   r6   r   r   Warningr   r   r   r  _magic_methodsr  r"  r7  rk   r   rc  rC   rR   r?   itemcallabler   r  
startswithrE   r  _compiled_methods_allowlistr  r   methodendswithr"  r'  r*  r.  rP  rK  rN  rZ  rh  rq  r?  ry  r  r   r  r  r  r  r  is_scriptingr   )r  s   @r1   <module>r     sJ         
  A A  .  + " > 7 1 A 
   P O  
 ; " 1 T] "#":   $.   !((  + 8  
>; '
A $  &&{Wf4EFII	 X$C( "  "F&'* &'b;- ;-|+ +
	G 	+>( ('0 8N>?C ?CB &	K 	$k?C &TBv TBlU Uz
 ,44::<
d~~jx&@&@??4  GL$$?$? 	dD) =
&#&#&# 	&# 		&#
 	&# 	&# 	&# 	&# 	&# 	&# 	&# 	&# 	&# 	&# 	&#  	!&#" 	#&#$ 	 %&#& 	'&#( 	)&#* 	+&#, 	-&#. 	/&#0 	1&#2 	3&#4 	5&#6 	7&#8 	9&#: 	;&#< 	=&#> 	?&#@ 	A&#B 	C&#D 	E&#F 	G&#H 	I&#J 	K&#P %UXX__5f??4  DMM,$?$? -66677)6??Jt<LM 6 uxx  
$N8
$ $ 	 H=Vnj.6
Rj= ((** 
?K (@< <8" "8)" )"X "$< = -,,.B C $&@ A *,F G -/I Jr3   