§
    �Štj¦V  ã                  óH  — U d dl mZ d dlZd dlmZ d dlmZmZmZ d dlm	Z	m
Z
mZ d dlZd dlmZ erd dlmZ dd	lmZ g d
¢Z ed¦  «        Z e	d¦  «        Z eej        d¦  «        sH ed¦  «        ej        j        d<    ed¦  «        ej        j        d<    ed¦  «        ej        j        d<   d dlmZmZmZ d/d„Zd0d„Z G d„ de¦  «        Z G d„ d¦  «        Zej         j!        ede"f         z  Z#de$d<   e	 	 	 d1d2d(„¦   «         Z%e	 	 	 d1d3d+„¦   «         Z%	 	 	 d1d4d.„Z%dS )5é    )ÚannotationsN)ÚCallable)ÚoverloadÚTYPE_CHECKINGÚ	TypeAlias)Ú	ParamSpecÚSelfÚTypeVar)ÚTensor)Ú_POOL_HANDLEé   )Ú_dummy_type)Úis_current_stream_capturingÚgraph_pool_handleÚXPUGraphÚgraphÚmake_graphed_callablesÚ_RÚ_PÚ_XpuStreamBaseÚ	_XPUGraphÚ_xpu_graph_pool_handleÚ_xpu_isCurrentStreamCapturing)r   r   r   ÚreturnÚboolc                 ó   — t          ¦   «         S )zÉReturn True if XPU graph capture is underway on the current XPU stream, False otherwise.

    If a XPU context does not exist on the current device, returns False without initializing the context.
    )r   © ó    úN/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/xpu/graphs.pyr   r   (   s   € õ
 )Ñ*Ô*Ð*r   r   c                 óX   — t           j                             t          ¦   «         ¦  «        S )zBReturn an opaque token representing the id of a graph memory pool.)ÚtorchÚxpur   r   r   r   r   r   r   0   s   € åŒ9×!Ò!Õ"8Ñ":Ô":Ñ;Ô;Ð;r   c                  ó    ‡ — e Zd ZdZddˆ fd„Zddˆ fd„Zdˆ fd„Zdˆ fd„Zdˆ fd„Zdˆ fd„Z	dˆ fd„Z
dˆ fd„Zd ˆ fd„Zd!ˆ fd„Zd!ˆ fd„Zˆ xZS )"r   a  Wrapper around a XPU graph.

    Arguments:
        keep_graph (bool, optional): If ``keep_graph=False``, the
            executable command graph will be instantiated on GPU at the end of
            ``capture_end`` and the underlying modifiable command graph will be
            destroyed. Note that the executable command graph will not be
            instantiated at the end of ``capture_end`` in this
            case. Instead, it will be instantiated via an explicit called
            to ``instantiate`` or automatically on the first call to
            ``replay`` if ``instantiate`` was not already called. Calling
            ``instantiate`` manually before ``replay`` is recommended to
            prevent increased latency on the first call to ``replay``.

    FÚ
keep_graphr   r   r	   c                óH   •— t          ¦   «                              | |¦  «        S ©N)ÚsuperÚ__new__)Úclsr$   Ú	__class__s     €r   r(   zXPUGraph.__new__F   s   ø€ Ý‰wŒw�Š˜s JÑ/Ô/Ð/r   NÚpoolú_POOL_HANDLE | NoneÚNonec                óL   •— t          ¦   «                              |¬¦  «         dS )aÙ  Begin capturing XPU work on the current xpu stream.

        Typically, you shouldn't call ``capture_begin`` yourself.
        Use :class:`~torch.xpu.graph`, which call ``capture_begin`` internally.

        Arguments:
            pool (optional): Token (returned by :func:`~torch.xpu.graph_pool_handle` or
                :meth:`other_Graph_instance.pool()<torch.xpu.XPUGraph.pool>`) that hints this graph may share memory
                with the indicated pool.
        ©r+   N)r'   Úcapture_begin)Úselfr+   r*   s     €r   r0   zXPUGraph.capture_beginI   s&   ø€ õ 	‰Œ×Ò 4ÐÑ(Ô(Ð(Ð(Ð(r   c                óH   •— t          ¦   «                              ¦   «          dS )a  End XPU graph capture on the current stream.

        After ``capture_end``, ``replay`` may be called on this instance.

        Typically, you shouldn't call ``capture_end`` yourself.
        Use :class:`~torch.xpu.graph`, which call ``capture_end`` internally.
        N)r'   Úcapture_end©r1   r*   s    €r   r3   zXPUGraph.capture_endV   s!   ø€ õ 	‰Œ×ÒÑÔÐÐÐr   c                óH   •— t          ¦   «                              ¦   «          dS )a/  Instantiate the XPU graph. Will be called by
        ``capture_end`` if ``keep_graph=False``, or by ``replay`` if
        ``keep_graph=True`` and ``instantiate`` has not already been
        explicitly called. Does not destroy the xpu modify command graph returned
        by ``raw_xpu_graph``.
        N)r'   Úinstantiater4   s    €r   r6   zXPUGraph.instantiate`   s!   ø€ õ 	‰Œ×ÒÑÔÐÐÐr   c                óH   •— t          ¦   «                              ¦   «          dS )z+Replay the XPU work captured by this graph.N)r'   Úreplayr4   s    €r   r8   zXPUGraph.replayi   s   ø€ å‰Œ�ŠÑÔÐÐÐr   c                óH   •— t          ¦   «                              ¦   «          dS )z1Delete the graph currently held by this instance.N)r'   Úresetr4   s    €r   r:   zXPUGraph.resetm   s   ø€ å‰Œ�Š‰Œˆˆˆr   r   c                óD   •— t          ¦   «                              ¦   «         S )zäReturn an opaque token representing the id of this graph's memory pool.

        This id can optionally be passed to another graph's ``capture_begin``,
        which hints the other graph may share the same memory pool.
        )r'   r+   r4   s    €r   r+   zXPUGraph.poolq   s   ø€ õ ‰wŒw�|Š|‰~Œ~Ðr   c                óD   •— t          ¦   «                              ¦   «         S )z.Enable debugging mode for XPUGraph.debug_dump.)r'   Úenable_debug_moder4   s    €r   r=   zXPUGraph.enable_debug_modey   s   ø€ å‰wŒw×(Ò(Ñ*Ô*Ð*r   Ú
debug_pathÚstrc                óF   •— t          ¦   «                              |¦  «        S )zÕ
        Arguments:
            debug_path (required): Path to dump the graph to.

        Calls a debugging function to dump the graph if the debugging is
        enabled via XPUGraph.enable_debug_mode()
        )r'   Ú
debug_dump)r1   r>   r*   s     €r   rA   zXPUGraph.debug_dump}   s   ø€ õ ‰wŒw×!Ò! *Ñ-Ô-Ð-r   Úintc                óD   •— t          ¦   «                              ¦   «         S )z…Returns the underlying xpuGraph_t. ``keep_graph`` must be True.

        XPU doesn't provide APIs to manipulate this object.
        )r'   Úraw_xpu_graphr4   s    €r   rD   zXPUGraph.raw_xpu_graph‡   s   ø€ õ
 ‰wŒw×$Ò$Ñ&Ô&Ð&r   c                óD   •— t          ¦   «                              ¦   «         S )a®  Returns the underlying xpuGraphExec_t. ``instantiate`` must have been called if ``keep_graph`` is True, or ``capture_end`` must have been called if ``keep_graph`` is False. If you call ``instantiate()`` after ``raw_xpu_graph_exec()``, the previously returned xpuGraphExec_t will be destroyed. It is your responsibility not to use this object after destruction.

        XPU doesn't provide APIs to manipulate this object.
        )r'   Úraw_xpu_graph_execr4   s    €r   rF   zXPUGraph.raw_xpu_graph_execŽ   s   ø€ õ
 ‰wŒw×)Ò)Ñ+Ô+Ð+r   )F)r$   r   r   r	   r&   )r+   r,   r   r-   ©r   r-   ©r   r   )r>   r?   r   r-   )r   rB   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r0   r3   r6   r8   r:   r+   r=   rA   rD   rF   Ú__classcell__)r*   s   @r   r   r   5   s}  ø€ € € € € ðð ð 0ð 0ð 0ð 0ð 0ð 0ð 0ð)ð )ð )ð )ð )ð )ð )ðð ð ð ð ð ðð ð ð ð ð ðð ð ð ð ð ðð ð ð ð ð ðð ð ð ð ð ð+ð +ð +ð +ð +ð +ð.ð .ð .ð .ð .ð .ð'ð 'ð 'ð 'ð 'ð 'ð,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,r   r   c                  ó@   — e Zd ZU dZdZded<   	 	 ddd
„Zdd„Zdd„ZdS )r   aŠ  Context-manager that captures XPU work into a :class:`torch.xpu.XPUGraph` object for later replay.

    Arguments:
        xpu_graph (torch.xpu.XPUGraph): Graph object used for capture.
        pool (optional): Opaque token (returned by a call to :func:`~torch.xpu.graph_pool_handle()` or
            :meth:`other_Graph_instance.pool()<torch.xpu.XPUGraph.pool>`) hinting this graph's capture
            may share memory from the specified pool.
        stream (torch.xpu.Stream, optional): If supplied, will be set as the current stream in the context.
            If not supplied, ``graph`` sets its own internal side stream as the current stream in the context.

    .. note::
        For effective memory sharing, if you pass a ``pool`` used by a previous capture and the previous capture
        used an explicit ``stream`` argument, you should pass the same ``stream`` argument to this capture.

    Nútorch.xpu.Stream | NoneÚdefault_capture_streamÚ	xpu_graphr   r+   r,   Ústreamc                ó  — | j         j        €(t          j                             ¦   «         | j         _        |€dn|f| _        |�|n| j         j        | _        | j        €t          d¦  «        ‚| j        | _        || _	        d S )Nr   zcapture_stream must not be None)
r*   rP   r!   r"   ÚStreamr+   Úcapture_streamÚAssertionErrorÚ
stream_ctxrQ   )r1   rQ   r+   rR   s       r   Ú__init__zgraph.__init__©   s€   € ð Œ>Ô0Ð8Ý49´I×4DÒ4DÑ4FÔ4FˆDŒNÔ1à;?¸<°R°RÈdÈWˆŒ	àÐ(ˆFˆF¨d¬nÔ.Sð 	Ôð ÔÐ&Ý Ð!BÑCÔCÐCØÔ-ˆŒØ"ˆŒˆˆr   r   r-   c                óØ   — t           j                             ¦   «          t           j                             ¦   «          | j                             ¦   «           | j        j        | j        Ž  d S r&   )	r!   r"   ÚsynchronizeÚempty_cacherW   Ú	__enter__rQ   r0   r+   )r1   s    r   r\   zgraph.__enter__¾   sX   € åŒ	×ÒÑÔÐåŒ	×ÒÑÔÐØŒ×!Ò!Ñ#Ô#Ð#à$ˆŒÔ$ d¤iÐ0Ð0Ð0Ð0r   ÚargsÚobjectc                óV   — | j                              ¦   «           | j        j        |Ž  d S r&   )rQ   r3   rW   Ú__exit__)r1   r]   s     r   r`   zgraph.__exit__Ç   s.   € ØŒ×"Ò"Ñ$Ô$Ð$Ø ˆŒÔ  $Ð'Ð'Ð'Ð'r   )NN)rQ   r   r+   r,   rR   rO   rG   )r]   r^   r   r-   )	rI   rJ   rK   rL   rP   Ú__annotations__rX   r\   r`   r   r   r   r   r   –   s}   € € € € € € ðð ð  7;ÐÐ:Ð:Ð:Ñ:ð
 %)Ø*.ð	#ð #ð #ð #ð #ð*1ð 1ð 1ð 1ð(ð (ð (ð (ð (ð (r   r   .r   Ú_ModuleOrCallableé   FÚ	callablesÚsample_argsútuple[Tensor, ...]Únum_warmup_itersrB   Úallow_unused_inputr+   r,   c                ó   — d S r&   r   ©rd   re   rg   rh   r+   s        r   r   r   Ï   s	   € ð ˜r   útuple[_ModuleOrCallable, ...]útuple[tuple[Tensor, ...], ...]c                ó   — d S r&   r   rj   s        r   r   r   Ù   s	   € ð %( Cr   ú1_ModuleOrCallable | tuple[_ModuleOrCallable, ...]ú3tuple[Tensor, ...] | tuple[tuple[Tensor, ...], ...]c                ó”  ‡)‡*— t          j        ¦   «         r"t          j        ¦   «         rt          d¦  «        ‚d}t	          | t
          ¦  «        s.d}| f} t          j        t
          t          df         |¦  «        f}n4t          j        t
          t
          t          df         df         |¦  «        }g Š)t          | |¦  «        D �]\  }}t	          |t           j
        j        ¦  «        r‘t          |j        ¦  «        dk    r0t          |j        ¦  «        dk    rt          |j        ¦  «        dk    st          d¦  «        ‚t!          d„ |                     ¦   «         D ¦   «         ¦  «        st          d¦  «        ‚t          j        j        j        |Ž }	‰)                     t          |	¦  «        ¦  «         t!          d	„ |	D ¦   «         ¦  «        st-          d
¦  «        ‚�Œd„ ‰)D ¦   «         }
d„ | D ¦   «         Š*ˆ)ˆ*fd„t/          t          | ¦  «        ¦  «        D ¦   «         }d„ t/          t          | ¦  «        ¦  «        D ¦   «         }d„ t/          t          | ¦  «        ¦  «        D ¦   «         }|€t1          ¦   «         n|}t           j                             ¦   «          t           j                             t           j                             ¦   «         ¦  «        5  t          | ||¦  «        D ]Ì\  }}}d\  }}}t/          |¦  «        D ]§}t           j        j                              ||Ž ¦  «        }t          d„ |D ¦   «         ¦  «        }t          |¦  «        dk    rRt           j                             |t          d„ |D ¦   «         ¦  «        t          d„ |D ¦   «         ¦  «        d|¬¦  «        }Œ¨|||fD ]}~ŒŒÍ	 ddd¦  «         n# 1 swxY w Y   t           j                             ¦   «          g }g }t          | ||¦  «        D ]¢\  }}}t           j                              ||¬¦  «        5   ||Ž }ddd¦  «         n# 1 swxY w Y   t           j        j         !                    |¦  «        \  }}|                     t          |¦  «        ¦  «         |                     |¦  «         Œ£g }g }t          tE          |¦  «        tE          |¦  «        tE          |¦  «        ¦  «        D �]Z\  }}}t          d„ |D ¦   «         ¦  «        } t          d„ |D ¦   «         ¦  «        }d}t          |¦  «        dk    r‹t           j                              ||¬¦  «        5  t           j                             |t          d„ |D ¦   «         ¦  «        t          d„ | D ¦   «         ¦  «        d|¬¦  «        }ddd¦  «         n# 1 swxY w Y   g }!d}"|D ]A}#|#j#        r#|�!|!                     ||"         ¦  «         |"dz  }"Œ,|!                     d¦  «         ŒBt          |!¦  «        }!|                     | ¦  «         |                     |!¦  «         �Œ\| $                    ¦   «          | $                    ¦   «          d6d-„}$g }%tK          | ¦  «        D ]¹\  }&} |$||&         ||&         ‰*|&         |
|&         ||&         ||&         ||&         ||&         ||&         ¦	  «	        }'t	          |t           j
        j        ¦  «        r7d7d5„}( |(||j&        |'|j'        ¦  «        |_'        |%                     |¦  «         Œ¤|%                     |'¦  «         Œº|r|%d         S t          |%¦  «        S )8a¯  Accept callables (functions or :class:`nn.Module<torch.nn.Module>`\ s) and returns graphed versions.

    Each graphed callable's forward pass runs its source callable's
    forward XPU work as a XPU graph inside a single autograd node.

    The graphed callable's forward pass also appends
    a backward node to the autograd graph. During backward, this node runs the
    callable's backward work as a XPU graph.

    Therefore, each graphed callable should be a drop-in replacement for its source callable
    in an autograd-enabled training loop.

    See :ref:`Partial-network capture<partial-network-capture>` for detailed use and constraints.

    If you pass a tuple of several callables, their captures will use the same memory pool.

    Arguments:
        callables (torch.nn.Module or Python function, or tuple of these): Callable or callables to graph.
            If you pass a tuple of callables, their order in the tuple must be the same order they'll run
            in the live workload.
        sample_args (tuple of Tensors, or tuple of tuples of Tensors): Samples args for each callable.
            If a single callable was passed, ``sample_args`` must be a single tuple of argument Tensors.
            If a tuple of callables was passed, ``sample_args`` must be tuple of tuples of argument Tensors.
        num_warmup_iters (int): The number of warmup iterations. Currently, ``DataDistributedParallel`` needs
            11 iterations for warm up. Default: ``3``.
        allow_unused_input (bool): If False, specifying inputs that were not used when computing outputs
            (and therefore their grad is always zero) is an error. Defaults to False.
        pool (optional): Token (returned by :func:`~torch.xpu.graph_pool_handle` or
            :meth:`other_Graph_instance.pool()<torch.xpu.XPUGraph.pool>`) that hints this graph may share memory
            with the indicated pool.
    .. note::
        The ``requires_grad`` state of each Tensor in ``sample_args`` must match the state
        that's expected for the corresponding real input in the training loop.

    .. warning::
        This API is in beta and may change in future releases.

    .. warning::
        ``sample_args`` for each callable must contain only Tensors. Other types are not allowed.

    .. warning::
        Returned callables do not support higher order differentiation (e.g., double backward).

    .. warning::
        In any :class:`~torch.nn.Module` passed to :func:`~make_graphed_callables`, only parameters
        may be trainable. Buffers must have ``requires_grad=False``.

    .. warning::
        After you pass a :class:`torch.nn.Module` through :func:`~make_graphed_callables`,
        you may not add or remove any of that Module's parameters or buffers.

    .. warning::
        :class:`torch.nn.Module`\s passed to :func:`~torch.xpu.make_graphed_callables` must not have module hooks
        registered on them at the time they are passed. However, registering hooks on modules *after* passing them
        through :func:`~torch.xpu.make_graphed_callables` is allowed.

    .. warning::
        When running a graphed callable, you must pass its arguments in the same order and format
        they appeared in that callable's ``sample_args``.

    .. warning::
        The automatic mixed precision is supported in :func:`~torch.xpu.make_graphed_callables` only with disabled
        caching. The context manager `torch.amp.autocast()` must have `cache_enabled=False`.
    z_make_graphed_callables does not support the autocast caching. Please set `cache_enabled=False`.FT.r   z§Modules must not have hooks registered at the time they are passed. However, registering hooks on modules after passing them through make_graphed_callables is allowed.c              3  ó(   K  — | ]}|j         d u V — ŒdS )FN©Úrequires_grad©Ú.0Úbs     r   ú	<genexpr>z)make_graphed_callables.<locals>.<genexpr>F  s)   è è € ÐEÐE°A�q”¨%Ð/ÐEÐEÐEÐEÐEÐEr   zœIn any :class:`~torch.nn.Module` passed to :func:`~make_graphed_callables`, only parameters may be trainable. All buffers must have ``requires_grad=False``.c              3  óJ   K  — | ]}t          |t          j        ¦  «        V — Œd S r&   )Ú
isinstancer!   r   )ru   Úargs     r   rw   z)make_graphed_callables.<locals>.<genexpr>N  s.   è è € ÐHÐH°S•:˜c¥5¤<Ñ0Ô0ÐHÐHÐHÐHÐHÐHr   zfIn the beta API, sample_args for each callable must contain only Tensors. Other types are not allowed.c                ó,   — g | ]}t          |¦  «        ‘ŒS r   )Úlen)ru   r]   s     r   ú
<listcomp>z*make_graphed_callables.<locals>.<listcomp>V  s   € Ð!LÐ!LÐ!L°¥# d¡)¤)Ð!LÐ!LÐ!Lr   c                ó’   — g | ]D}t          |t          j        j        ¦  «        r!t	          |                     ¦   «         ¦  «        nd ‘ŒES )r   )ry   r!   ÚnnÚModuleÚtupleÚ
parameters)ru   Úcs     r   r}   z*make_graphed_callables.<locals>.<listcomp>W  sP   € ð "ð "ð "àõ ",¨A­u¬x¬Ñ!?Ô!?ÐG�ˆa�lŠl‰nŒnÑÔÐÀRð"ð "ð "r   c                ó2   •— g | ]}‰|         ‰|         z   ‘ŒS r   r   )ru   ÚiÚflatten_sample_argsÚper_callable_module_paramss     €€r   r}   z*make_graphed_callables.<locals>.<listcomp>[  s9   ø€ ð *ð *ð *àð 	˜AÔÐ!;¸AÔ!>Ñ>ð*ð *ð *r   c                óJ   — g | ] }t           j                             ¦   «         ‘Œ!S r   ©r!   r"   r   ©ru   Ú_s     r   r}   z*make_graphed_callables.<locals>.<listcomp>`  ó&   € ÐFÐFÐF¨1•%”)×$Ò$Ñ&Ô&ÐFÐFÐFr   c                óJ   — g | ] }t           j                             ¦   «         ‘Œ!S r   r‰   rŠ   s     r   r}   z*make_graphed_callables.<locals>.<listcomp>a  rŒ   r   N)NNNc              3  ó(   K  — | ]}|j         ¯	|V — Œd S r&   rr   ©ru   Úos     r   rw   z)make_graphed_callables.<locals>.<genexpr>n  s)   è è € Ð$KÐ$K¨1¸1¼?Ð$K QÐ$KÐ$KÐ$KÐ$KÐ$KÐ$Kr   c              3  ó(   K  — | ]}|j         ¯	|V — Œd S r&   rr   ©ru   r…   s     r   rw   z)make_graphed_callables.<locals>.<genexpr>r  s=   è è € ð %ð %Ø"#¸q¼ð%Øð%ð %ð %ð %ð %ð %r   c              3  óL   K  — | ]}|j         ¯	t          j        |¦  «        V — Œ d S r&   ©rs   r!   Ú
empty_liker�   s     r   rw   z)make_graphed_callables.<locals>.<genexpr>u  sH   è è € ð +ð +Ø45ÀAÄOð+Ý!Ô,¨QÑ/Ô/ð+ð +ð +ð +ð +ð +r   )ÚoutputsÚinputsÚgrad_outputsÚonly_inputsÚallow_unusedr/   c              3  óP   K  — | ]!}|j         rt          j        |¦  «        nd V — Œ"d S r&   r”   r�   s     r   rw   z)make_graphed_callables.<locals>.<genexpr>”  sJ   è è € ð $
ð $
ØAB 1¤?Ð<�EÔ˜QÑÔÐ¸ð$
ð $
ð $
ð $
ð $
ð $
r   c              3  ó(   K  — | ]}|j         ¯	|V — Œd S r&   rr   r�   s     r   rw   z)make_graphed_callables.<locals>.<genexpr>˜  s)   è è € ÐJÐJ 1¸!¼/ÐJ˜QÐJÐJÐJÐJÐJÐJr   c              3  ó(   K  — | ]}|j         ¯	|V — Œd S r&   rr   r’   s     r   rw   z)make_graphed_callables.<locals>.<genexpr>ž  s)   è è € Ð TÐ T qÀAÄOÐ T Ð TÐ TÐ TÐ TÐ TÐ Tr   c              3  ó   K  — | ]}|®|V — Œ	d S r&   r   r�   s     r   rw   z)make_graphed_callables.<locals>.<genexpr>Ÿ  s"   è è € Ð&WÐ&W¨QÈÈ qÈÈÈÈÐ&WÐ&Wr   é   Ú	fwd_graphr   Ú	bwd_graphÚmodule_paramsútuple[torch.nn.Parameter, ...]Úlen_user_argsrB   Úoutput_unflatten_specútorch.utils._pytree.TreeSpecÚstatic_input_surfacerf   Ústatic_outputsÚstatic_grad_outputsútuple[Tensor | None, ...]Ústatic_grad_inputsr   úCallable[..., object]c	           	     ót   ‡ ‡‡‡‡‡‡‡‡‡
—  G ˆˆ ˆˆˆˆˆfd„dt           j        j        ¦  «        Š
dˆ
ˆˆfd„}	|	S )Nc                  ó€   •— e Zd Zedˆˆˆˆfd„¦   «         Zeej        j        j        dˆ ˆˆfd	„¦   «         ¦   «         Z	d
S )úOmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.GraphedÚctxr^   r—   r   r   rf   c                óx  •— t          ‰¦  «        D ]Y}‰|                              ¦   «         ||                              ¦   «         k    r!‰|                              ||         ¦  «         ŒZ‰                     ¦   «          t	          ‰t
          ¦  «        st          d¦  «        ‚t          d„ ‰D ¦   «         ¦  «        S )Nzstatic_outputs must be a tuplec              3  ó>   K  — | ]}|                      ¦   «         V — Œd S r&   ©Údetachr�   s     r   rw   zjmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.forward.<locals>.<genexpr>Ë  s*   è è € Ð@Ð@¨A˜QŸXšX™ZœZÐ@Ð@Ð@Ð@Ð@Ð@r   )ÚrangeÚdata_ptrÚcopy_r8   ry   r�   ÚRuntimeError)r°   r—   r…   r    r¤   r§   r¨   s      €€€€r   ÚforwardzWmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.forwardÁ  s¹   ø€ õ ˜}Ñ-Ô-ð Að A�AØ+¨AÔ.×7Ò7Ñ9Ô9¸VÀA¼Y×=OÒ=OÑ=QÔ=QÒQÐQØ,¨QÔ/×5Ò5°f¸Q´iÑ@Ô@Ð@øØ× Ò Ñ"Ô"Ð"Ý! .µ%Ñ8Ô8ð IÝ&Ð'GÑHÔHÐHÝÐ@Ð@°Ð@Ñ@Ô@Ñ@Ô@Ð@r   Úgradsc                óò  •— t          |¦  «        t          ‰¦  «        k    r/t          dt          ‰¦  «        › dt          |¦  «        › �¦  «        ‚t          ‰|¦  «        D ]F\  }}|�?|                     ¦   «         |                     ¦   «         k    r|                     |¦  «         ŒG‰                     ¦   «          t          ‰t          ¦  «        st          d¦  «        ‚t          d„ ‰D ¦   «         ¦  «        S )Nz	Expected z gradients but got z"static_grad_inputs must be a tuplec              3  óF   K  — | ]}|�|                      ¦   «         n|V — Œd S r&   r³   rt   s     r   rw   zkmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.backward.<locals>.<genexpr>Ý  sC   è è € ð ð Ø;< ! -�A—H’H‘J”J�J°Qðð ð ð ð ð r   )r|   r¸   Úzipr¶   r·   r8   ry   r�   )r°   rº   ÚgÚgradr¡   r«   r©   s       €€€r   ÚbackwardzXmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.backwardÍ  s
  ø€ õ �u‘:”:¥Ð%8Ñ!9Ô!9Ò9Ð9Ý&Ø]¥CÐ(;Ñ$<Ô$<Ð]Ð]ÕQTÐUZÑQ[ÔQ[Ð]Ð]ñô ð õ  #Ð#6¸Ñ>Ô>ð *ð *‘G�A�tØ�}ØŸ:š:™<œ<¨4¯=ª=©?¬?Ò:Ð:ØŸGšG D™MœM˜MøØ× Ò Ñ"Ô"Ð"å!Ð"4µeÑ<Ô<ð MÝ&Ð'KÑLÔLÐLÝð ð Ø@Rðñ ô ñ ô ð r   N)r°   r^   r—   r   r   rf   )r°   r^   rº   r   r   rf   )
rI   rJ   rK   Ústaticmethodr¹   r!   ÚautogradÚfunctionÚonce_differentiablerÀ   )r¡   r    r¤   r«   r©   r§   r¨   s   €€€€€€€r   ÚGraphedr¯   À  sœ   ø€ € € € € ØðAð Að Að Að Að Að Að Añ Œ\ðAð ØŒ^Ô$Ô8ðð ð ð ð ð ð ñ 9Ô8ñ Œ\ðð ð r   rÅ   Ú	user_argsr^   r   c                 ó²   •— t          j        j        j        | Ž } ‰j        t          |¦  «        ‰z   Ž }t           j        j                             |‰¦  «        S r&   )r!   ÚutilsÚ_pytreeÚarg_tree_leavesÚapplyr�   Útree_unflatten)rÆ   Úflatten_user_argsÚoutrÅ   r¢   r¥   s      €€€r   ÚfunctionalizedzVmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.functionalizedá  sN   ø€ å %¤Ô 3Ô CÀYÐ OÐØ�'”-¥%Ð(9Ñ":Ô":¸]Ñ"JÐLˆCÝ”;Ô&×5Ò5°cÐ;PÑQÔQÐQr   )rÆ   r^   r   r^   )r!   rÂ   ÚFunction)r    r¡   r¢   r¤   r¥   r§   r¨   r©   r«   rÏ   rÅ   s   ````````` @r   Úmake_graphed_autograd_functionz>make_graphed_callables.<locals>.make_graphed_autograd_functionµ  sœ   øøøøøøøøøø€ ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	•e”nÔ-ñ 	ô 	ð 	ðB	Rð 	Rð 	Rð 	Rð 	Rð 	Rð 	Rð 	Rð Ðr   Úfuncútorch.nn.ModuleÚgraph_training_stater   ÚgraphedúCallable[_P, _R]Úorig_fwdc                ó    ‡ ‡‡‡— dˆ ˆˆˆfd„}|S )	NrÆ   ú_P.argsÚuser_kwargsú	_P.kwargsr   r   c                 ó:   •— ‰j         ‰k    r ‰| i |¤ŽS  ‰| i |¤ŽS r&   )Útraining)rÆ   rÚ   rÒ   rÔ   rÕ   r×   s     €€€€r   Únew_fwdzEmake_graphed_callables.<locals>.make_graphed_forward.<locals>.new_fwdÿ  s;   ø€ Ø”}Ð(<Ò<Ð<Ø&˜w¨	ÐA°[ÐAÐAÐAà'˜x¨ÐB°kÐBÐBÐBr   )rÆ   rÙ   rÚ   rÛ   r   r   r   )rÒ   rÔ   rÕ   r×   rÞ   s   ```` r   Úmake_graphed_forwardz4make_graphed_callables.<locals>.make_graphed_forwardù  sC   øøøø€ ðCð Cð Cð Cð Cð Cð Cð Cð Cð �r   )r    r   r¡   r   r¢   r£   r¤   rB   r¥   r¦   r§   rf   r¨   rf   r©   rª   r«   rf   r   r¬   )
rÒ   rÓ   rÔ   r   rÕ   rÖ   r×   rÖ   r   rÖ   )(r!   Úis_autocast_enabledÚis_autocast_cache_enabledr¸   ry   r�   ÚtypingÚcastr   r½   r   r€   r|   Ú_backward_hooksÚ_forward_hooksÚ_forward_pre_hooksÚallÚbuffersrÈ   rÉ   rÊ   ÚappendÚ	TypeErrorrµ   r   r"   rZ   rR   rT   Útree_leavesrÂ   r¿   r   Útree_flattenÚreversedrs   ÚreverseÚ	enumeraterÝ   r¹   )+rd   re   rg   rh   r+   Újust_one_callableÚ_sample_argsrƒ   r]   Úflatten_argÚper_callable_len_user_argsÚ"per_callable_static_input_surfacesÚ
fwd_graphsÚ
bwd_graphsÚmempoolrÒ   r§   Úgrad_inputsr–   Úoutputs_gradr‹   ÚvÚper_callable_static_outputsÚ"per_callable_output_unflatten_specr    Úfunc_outputsÚflatten_outputsÚspecÚ per_callable_static_grad_outputsÚper_callable_static_grad_inputsr¨   r¡   r©   r«   Úgrad_idxrz   rÑ   Úretr…   rÕ   rß   r†   r‡   s+                                            @@r   r   r   ã   s	  øø€ õN Ô Ñ"Ô"ð 
¥uÔ'FÑ'HÔ'Hð 
ÝØmñ
ô 
ð 	
ð Ðõ �i¥Ñ'Ô'ð PØ ÐØ�Lˆ	Ýœ¥E­&°#¨+Ô$6¸ÑDÔDÐFˆˆå”{¥5­­v°s¨{Ô);¸SÐ)@Ô#AÀ;ÑOÔOˆàÐå�y ,Ñ/Ô/ð ñ ‰ˆˆ4Ý�a�œœÑ)Ô)ð 	å�AÔ%Ñ&Ô&¨!Ò+Ð+Ý˜Ô(Ñ)Ô)¨QÒ.Ð.Ý˜Ô,Ñ-Ô-°Ò2Ð2å"ðañô ð õ ÐEÐE¸¿º¹¼ÐEÑEÔEÑEÔEð Ý"ð1ñô ð õ
 ”kÔ)Ô9¸4Ð@ˆØ×"Ò"¥5¨Ñ#5Ô#5Ñ6Ô6Ð6ÝÐHÐH¸KÐHÑHÔHÑHÔHð 	Ýð^ñô ð ñ	ð "MÐ!LÐ8KÐ!LÑ!LÔ!LÐð"ð "àð"ñ "ô "Ðð*ð *ð *ð *ð *å•s˜9‘~”~Ñ&Ô&ð*ñ *ô *Ð&ð
 GÐFµµc¸)±n´nÑ0EÔ0EÐFÑFÔF€JØFÐFµµc¸)±n´nÑ0EÔ0EÐFÑFÔF€Jà%) \ÕÑ!Ô!Ð!°t€Gõ 
„I×ÒÑÔÐÝ	Œ×	Ò	�%œ)×*Ò*Ñ,Ô,Ñ	-Ô	-ð ð Ý03Ø�|Ð%Gñ1
ô 1
ð 	ð 	Ñ,ˆD�$Ð,ð 2BÑ.ˆK˜ ,ÝÐ+Ñ,Ô,ð ð �Ýœ+Ô-×9Ò9¸$¸$À¸+ÑFÔF�Ý$Ð$KÐ$K°Ð$KÑ$KÔ$KÑKÔK�Ý�|Ñ$Ô$ qÒ(Ð(Ý"'¤.×"5Ò"5Ø ,Ý$ð %ð %Ø';ð%ñ %ô %ñ  ô  õ &+ð +ð +Ø9@ð+ñ +ô +ñ &ô &ð %)Ø%7ð #6ñ 
#ô 
#�Køð ˜|¨[Ð9ð ð �Ø�Aðð'	ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð õ. 
„I×ÒÑÔÐð #%ÐØ)+Ð&Ý!$ Y°¸jÑ!IÔ!Ið 8ð 8Ñˆˆd�IåŒY�_Š_˜Y¨Wˆ_Ñ5Ô5ð 	'ð 	'Ø˜4 ˜;ˆLð	'ð 	'ð 	'ñ 	'ô 	'ð 	'ð 	'ð 	'ð 	'ð 	'ð 	'øøøð 	'ð 	'ð 	'ð 	'õ !&¤Ô 3× @Ò @ÀÑ NÔ NÑˆ˜Ø#×*Ò*­5°Ñ+AÔ+AÑBÔBÐBØ*×1Ò1°$Ñ7Ô7Ð7Ð7ð (*Ð$Ø&(Ð#Ý;>ÝÐ3Ñ4Ô4ÝÐ,Ñ-Ô-Ý�ÑÔñ<ô <ð  Cñ  CÑ7Ð˜n¨iõ
 $ð $
ð $
ØFTð$
ñ $
ô $
ñ 
ô 
Ðõ ÐJÐJ¨ÐJÑJÔJÑJÔJˆØˆÝˆ|ÑÔ˜qÒ Ð Ý”—’ °�Ñ9Ô9ð ð Ý#œn×1Ò1Ø(Ý Ð TÐ TÐ,@Ð TÑ TÔ TÑTÔTÝ!&Ð&WÐ&WÐ2EÐ&WÑ&WÔ&WÑ!WÔ!WØ $Ø!3ð 2ñ ô �ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð  ÐØˆØ'ð 	0ð 	0ˆCØÔ ð 0 [Ð%<Ø"×)Ò)¨+°hÔ*?Ñ@Ô@Ð@Ø˜A‘��à"×)Ò)¨$Ñ/Ô/Ð/Ð/Ý"Ð#5Ñ6Ô6Ðà(×/Ò/Ð0CÑDÔDÐDØ'×.Ò.Ð/AÑBÔBÐBÑBð %×,Ò,Ñ.Ô.Ð.Ø#×+Ò+Ñ-Ô-Ð-ð2ð 2ð 2ð 2ðh $&€CÝ˜YÑ'Ô'ð " ð " ‰ˆˆ4Ø0Ð0Ø�qŒMØ�qŒMØ& qÔ)Ø& qÔ)Ø.¨qÔ1Ø.¨qÔ1Ø'¨Ô*Ø,¨QÔ/Ø+¨AÔ.ñ

ô 

ˆõ �d�EœHœOÑ,Ô,ð 	 ðð ð ð ð 0Ð/Ø�d”m W¨d¬lñô ˆDŒLð �JŠJ�tÑÔÐÐà�JŠJ�wÑÔÐÐàð Ø�1Œvˆå�‰:Œ:Ðs8   ËCOÏOÏOÐ&P8Ð8P<	Ð?P<	ÕAV,Ö,V0	Ö3V0	)r   r   rH   )rc   FN)rd   rb   re   rf   rg   rB   rh   r   r+   r,   r   rb   )rd   rk   re   rl   rg   rB   rh   r   r+   r,   r   rk   )rd   rn   re   ro   rg   rB   rh   r   r+   r,   r   rn   )&Ú
__future__r   râ   Úcollections.abcr   r   r   r   Útyping_extensionsr   r	   r
   r!   r   Ú	torch.xpur   Ú_utilsr   Ú__all__r   r   ÚhasattrÚ_CÚ__dict__Útorch._Cr   r   r   r   r   r   r   r   r€   r^   rb   ra   r   r   r   r   ú<module>r     s±  ðØ "Ð "Ð "Ð "Ð "Ð "Ð "à €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6à €€€Ø Ð Ð Ð Ð Ð ð ð 'Ø&Ð&Ð&Ð&Ð&Ð&à  Ð  Ð  Ð  Ð  Ð  ðð ð €ð €WˆT�]„]€Ø€Yˆt�_„_€à€wˆuŒxÐ)Ñ*Ô*ð à%0 [°Ñ%=Ô%=€E„HÔ�kÑ"Ø2=°+Ð>VÑ2WÔ2W€E„HÔÐ.Ñ/Ø9D¸Ø'ñ:ô :€E„HÔÐ5Ñ6ð VÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ Uð+ð +ð +ð +ð<ð <ð <ð <ð
^,ð ^,ð ^,ð ^,ð ^,ˆyñ ^,ô ^,ð ^,ðB3(ð 3(ð 3(ð 3(ð 3(ñ 3(ô 3(ð 3(ðl  %œxœ°¸#¸v¸+Ô1FÑFÐ Ð FÐ FÐ FÑ Fð 
ð Ø$Ø $ðð ð ð ñ 
„ðð 
ð Ø$Ø $ð(ð (ð (ð (ñ 
„ð(ð Ø$Ø $ðnð nð nð nð nð nð nr   