
    ֧g}                      |   d dl Z d dlmZ d dlmZmZ d dlZd dlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ d dlmZmZ d dlmZmZmZ d dlmZ d dlmZm Z m!Z! d d	l"m#Z#m$Z$m%Z%m&Z& d d
l'm(Z( d dl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG d dlHmIZI g dZJeZKeZLe&ZMd ZNejO        jP        ZQ eIeQd           deQ_R        deQ_S        d ZTd ZUd ZV G d d          ZWeded         fd            ZXdeYfdZZd Z[[ejO        \                                s e]d          dS )    N)contextmanager)AnyIterator)_Await_drop_IgnoreContextManager_isinstance	_overload_overload_methodexportFinalFutureignoreis_scriptingunused)forkwait)
_awaitable_awaitable_nowait_awaitable_wait)_register_decomposition)freezeoptimize_for_inferencerun_frozen_optimizations)fuserlast_executed_optimized_graphoptimized_executionset_fusion_strategy)_InsertPoint)_ScriptProfile_unwrap_optional	AttributeCompilationUnit	interfaceRecursiveScriptClassRecursiveScriptModulescriptscript_methodScriptFunctionScriptModuleScriptWarning)jit_module_from_flatbufferloadsavesave_jit_module_to_flatbuffer)_flatten_get_trace_graph_script_if_tracing_unique_state_dict
is_tracingONNXTracedModuleTopLevelTracedModuletracetrace_moduleTracedModuleTracerWarningTracingCheckError)
set_module)r"   r#   Errorr   r)   r*   annotateenable_onednn_fusionr   export_opnamesr   r   r$   r   
isinstancer-   onednn_fusion_enabledr   r.   r'   script_if_tracingr   strict_fusionr7   r8   r   r   c                 J    t           j                            | j                  S )a  
    Generate new bytecode for a Script module.

    Returns what the op list would be for a Script Module based off the current code base.

    If you have a LiteScriptModule and want to get the currently present
    list of ops call _export_operator_list instead.
    )torch_C_export_opnames_c)ms    N/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/jit/__init__.pyr@   r@   k   s     8##AD)))    z	torch.jitr=   c                     |S )ap  Use to give type of `the_value` in TorchScript compiler.

    This method is a pass-through function that returns `the_value`, used to hint TorchScript
    compiler the type of `the_value`. It is a no-op when running outside of TorchScript.

    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]`

    Note that `annotate()` does not help in `__init__` method of `torch.nn.Module` subclasses because it
    is executed in eager mode. To annotate types of `torch.nn.Module` attributes,
    use :meth:`~torch.jit.Attribute` instead.

    Example:

    .. testcode::

        import torch
        from typing import Dict

        @torch.jit.script
        def fn():
            # Telling TorchScript that this empty dictionary is a (str -> int) dictionary
            # instead of default dictionary type of (str -> Tensor).
            d = torch.jit.annotate(Dict[str, int], {})

            # Without `torch.jit.annotate` above, following statement would fail because of
            # type mismatch.
            d["name"] = 20

    .. testcleanup::

        del fn

    Args:
        the_type: Python type that should be passed to TorchScript compiler as type hint for `the_value`
        the_value: Value or expression to hint type for.

    Returns:
        `the_value` is passed back as return value.
     )the_type	the_values     rK   r>   r>      s    Z rL   c                      t          |           S )a  
    Compiles ``fn`` when it is first called during tracing.

    ``torch.jit.script`` has a non-negligible start up time when it is first called due to
    lazy-initializations of many compiler builtins. Therefore you should not use
    it in library code. However, you may want to have parts of your library work
    in tracing even if they use control flow. In these cases, you should use
    ``@torch.jit.script_if_tracing`` to substitute for
    ``torch.jit.script``.

    Args:
        fn: A function to compile.

    Returns:
        If called during tracing, a :class:`ScriptFunction` created by `torch.jit.script` is returned.
        Otherwise, the original function `fn` is returned.
    )r2   )fns    rK   rC   rC      s    $ b!!!rL   c                 "    t          | |          S )a_  
    Provide container type refinement in TorchScript.

    It can refine parameterized containers of the List, Dict, Tuple, and Optional types. E.g. ``List[str]``,
    ``Dict[str, List[torch.Tensor]]``, ``Optional[Tuple[int,str,int]]``. It can also
    refine basic types such as bools and ints that are available in TorchScript.

    Args:
        obj: object to refine the type of
        target_type: type to try to refine obj to
    Returns:
        ``bool``: True if obj was successfully refined to the type of target_type,
            False otherwise with no new type refinement


    Example (using ``torch.jit.isinstance`` for type refinement):
    .. testcode::

        import torch
        from typing import Any, Dict, List

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

            def forward(self, input: Any): # note the Any type
                if torch.jit.isinstance(input, List[torch.Tensor]):
                    for t in input:
                        y = t.clamp(0, 0.5)
                elif torch.jit.isinstance(input, Dict[str, str]):
                    for val in input.values():
                        print(val)

        m = torch.jit.script(MyModule())
        x = [torch.rand(3,3), torch.rand(4,3)]
        m(x)
        y = {"key1":"val1","key2":"val2"}
        m(y)
    )r	   )objtarget_types     rK   rA   rA      s    P sK(((rL   c                   8    e Zd ZdZd
dZd Zdedededdfd	ZdS )rD   a8  
    Give errors if not all nodes have been fused in inference, or symbolically differentiated in training.

    Example:
    Forcing fusion of additions.

    .. code-block:: python

        @torch.jit.script
        def foo(x):
            with torch.jit.strict_fusion():
                return x + x + x

    returnNc                 n    t           j                                        st          j        d           d S d S )NzOnly works in script mode)rF   _jit_internalr   warningswarnselfs    rK   __init__zstrict_fusion.__init__  s:    "//11 	7M566666	7 	7rL   c                     d S NrN   r\   s    rK   	__enter__zstrict_fusion.__enter__      rL   typevaluetbc                     d S r`   rN   )r]   rc   rd   re   s       rK   __exit__zstrict_fusion.__exit__  rb   rL   )rW   N)__name__
__module____qualname____doc__r^   ra   r   rg   rN   rL   rK   rD   rD      sq         7 7 7 7  S  # $      rL   rD   rW   c               #   "  K   t           j        j        j        } 	 t           j        j                            d           d V  t           j        j                            |            d S # t           j        j                            |            w xY w)NF)rF   rG   Graphglobal_print_source_rangesset_global_print_source_ranges)old_enable_source_rangess    rK   _hide_source_rangesrq     sx      $x~HP55e<<<556NOOOOO556NOOOOs   (A( (&Benabledc                 D    t           j                            |            dS )zFEnable or disables onednn JIT fusion based on the parameter `enabled`.N)rF   rG   _jit_set_llga_enabled)rr   s    rK   r?   r?     s    	H""7+++++rL   c                  >    t           j                                        S )z,Return whether onednn JIT fusion is enabled.)rF   rG   _jit_llga_enabledrN   rL   rK   rB   rB     s    8%%'''rL   zJIT initialization failed)^rZ   
contextlibr   typingr   r   torch._CrF   torch._jit_internalr   r   r   r	   r
   r   r   r   r   r   r   r   torch.jit._asyncr   r   torch.jit._awaitr   r   r   torch.jit._decomposition_utilsr   torch.jit._freezer   r   r   torch.jit._fuserr   r   r   r   torch.jit._ir_utilsr   torch.jit._scriptr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   torch.jit._serializationr,   r-   r.   r/   torch.jit._tracer0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   torch.utilsr<   __all___fork_wait_set_fusion_strategyr@   rG   JITExceptionr=   rh   rj   r>   rC   rA   rD   rq   boolr?   rB   	_jit_initRuntimeErrorrN   rL   rK   <module>r      s3    % % % % % %                                             ( ' ' ' ' ' ' ' K K K K K K K K K K B B B B B B V V V V V V V V V V            - , , , , ,                                                                  # " " " " "  > 	* 	* 	* 	* 	 

5+    - - -`" " ",() () ()V       < PXd^ P P P P,$ , , , ,
( ( (
 x 4
,2
3
334 4rL   