Ë
    *êñi–p  ã                  óˆ  — U d dl mZ d dlZd dlZd dlmZ d dlmZ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j0                  d«      s] ed«      ej0                  j2                  d<    ed«      ej0                  j2                  d<    ed«      ej0                  j2                  d<   d dlmZmZmZ dd„Zd d„Z G d„ de«      Z  G d„ d«      Z!e	dede"f   f   Z#de$d<   e	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 d"d„«       Z%e	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 d#d„«       Z%	 	 	 d!	 	 	 	 	 	 	 	 	 	 	 d$d„Z%y)%é    )ÚannotationsN)ÚCallable)ÚoverloadÚTYPE_CHECKINGÚ	TypeAliasÚUnion)Ú	ParamSpecÚSelfÚTypeVar)ÚTensor)Ú_POOL_HANDLEé   )Ú_dummy_type)Úis_current_stream_capturingÚgraph_pool_handleÚ	CUDAGraphÚgraphÚmake_graphed_callablesÚ_RÚ_PÚ_CudaStreamBaseÚ
_CUDAGraphÚ_graph_pool_handleÚ_cuda_isCurrentStreamCapturing)r   r   r   c                 ó   — t        «       S )zÌReturn True if CUDA graph capture is underway on the current CUDA stream, False otherwise.

    If a CUDA context does not exist on the current device, returns False without initializing the context.
    )r   © ó    úS/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/torch/cuda/graphs.pyr   r   -   s   € ô
 *Ó+Ð+r   c                 óP   — t         j                  j                  t        «       «      S )zÚReturn an opaque token representing the id of a graph memory pool.

    See :ref:`Graph memory management<graph-memory-management>`.

    .. warning::
        This API is in beta and may change in future releases.
    )ÚtorchÚcudar   r   r   r   r   r   r   6   s   € ô �:‰:×"Ñ"Ô#5Ó#7Ó8Ð8r   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 CUDA graph.

    Arguments:
        keep_graph (bool, optional): If ``keep_graph=False``, the
            cudaGraphExec_t will be instantiated on GPU at the end of
            ``capture_end`` and the underlying cudaGraph_t will be
            destroyed. Users who want to query or otherwise modify the
            underlying cudaGraph_t before instantiation can set
            ``keep_graph=True`` and access it via ``raw_cuda_graph`` after
            ``capture_end``. Note that the cudaGraphExec_t 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``. It
            is allowed to modify the raw cudaGraph_t after first calling
            ``instantiate``, but the user must call ``instantiate`` again
            manually to make sure the instantiated graph has these
            changes. Pytorch has no means of tracking these changes.

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

    c                ó$   •— t         ‰| �  | |«      S ©N)ÚsuperÚ__new__)ÚclsÚ
keep_graphÚ	__class__s     €r   r&   zCUDAGraph.__new__]   s   ø€ Ü‰w‰˜s JÓ/Ð/r   c                ó(   •— t         ‰| �  ||¬«       y)að  Begin capturing CUDA work on the current stream.

        Typically, you shouldn't call ``capture_begin`` yourself.
        Use :class:`~torch.cuda.graph` or :func:`~torch.cuda.make_graphed_callables`,
        which call ``capture_begin`` internally.

        Arguments:
            pool (optional): Token (returned by :func:`~torch.cuda.graph_pool_handle` or
                :meth:`other_Graph_instance.pool()<torch.cuda.CUDAGraph.pool>`) that hints this graph may share memory
                with the indicated pool.  See :ref:`Graph memory management<graph-memory-management>`.
            capture_error_mode (str, optional): specifies the cudaStreamCaptureMode for the graph capture stream.
                Can be "global", "thread_local" or "relaxed". During cuda graph capture, some actions, such as cudaMalloc,
                may be unsafe. "global" will error on actions in other threads, "thread_local" will only error for
                actions in the current thread, and "relaxed" will not error on these actions. Do NOT change this setting
                unless you're familiar with `cudaStreamCaptureMode <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85>`_
        )ÚpoolÚcapture_error_modeN)r%   Úcapture_begin)Úselfr+   r,   r)   s      €r   r-   zCUDAGraph.capture_begin`   s   ø€ ô& 	‰Ñ 4Ð<NÐÕOr   c                ó"   •— t         ‰| �  «        y)aG  End CUDA 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.cuda.graph` or :func:`~torch.cuda.make_graphed_callables`,
        which call ``capture_end`` internally.
        N)r%   Úcapture_end©r.   r)   s    €r   r0   zCUDAGraph.capture_endu   s   ø€ ô 	‰ÑÕr   c                ó"   •— t         ‰| �  «        y)a$  Instantiate the CUDA 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 cudaGraph_t returned
        by ``raw_cuda_graph``.
        N)r%   Úinstantiater1   s    €r   r3   zCUDAGraph.instantiate€   s   ø€ ô 	‰ÑÕr   c                ó"   •— t         ‰| �  «        y)z,Replay the CUDA work captured by this graph.N)r%   Úreplayr1   s    €r   r5   zCUDAGraph.replay‰   s   ø€ ä‰‰Õr   c                ó"   •— t         ‰| �  «        y)z1Delete the graph currently held by this instance.N)r%   Úresetr1   s    €r   r7   zCUDAGraph.reset�   s   ø€ ä‰‰�r   c                ó    •— 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+   r1   s    €r   r+   zCUDAGraph.pool‘   s   ø€ ô ‰w‰|‹~Ðr   c                ó    •— t         ‰| �  «       S )z/Enable debugging mode for CUDAGraph.debug_dump.)r%   Úenable_debug_moder1   s    €r   r:   zCUDAGraph.enable_debug_mode™   s   ø€ ä‰wÑ(Ó*Ð*r   c                ó"   •— 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 CUDAGraph.enable_debug_mode()
        )r%   Ú
debug_dump)r.   Ú
debug_pathr)   s     €r   r<   zCUDAGraph.debug_dump�   s   ø€ ô ‰wÑ! *Ó-Ð-r   c                ó    •— t         ‰| �  «       S )a}  Returns the underlying cudaGraph_t. ``keep_graph`` must be True.

        See the following for APIs for how to manipulate this object: `Graph Managmement <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__GRAPH.html>`_ and `cuda-python Graph Management bindings <https://nvidia.github.io/cuda-python/cuda-bindings/latest/module/runtime.html#graph-management>`_
        )r%   Úraw_cuda_graphr1   s    €r   r?   zCUDAGraph.raw_cuda_graph§   s   ø€ ô
 ‰wÑ%Ó'Ð'r   c                ó    •— t         ‰| �  «       S )aª  Returns the underlying cudaGraphExec_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_cuda_graph_exec()``, the previously returned cudaGraphExec_t will be destroyed. It is your responsibility not to use this object after destruction.

        See the following for APIs for how to manipulate this object: `Graph Execution <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__GRAPH__EXEC.html>`_ and `cuda-python Graph Execution bindings <https://nvidia.github.io/cuda-python/cuda-bindings/latest/module/runtime.html#graph-execution>`_
        )r%   Úraw_cuda_graph_execr1   s    €r   rA   zCUDAGraph.raw_cuda_graph_exec®   s   ø€ ô
 ‰wÑ*Ó,Ð,r   )F)r(   ÚboolÚreturnr
   )NÚglobal)r+   ú_POOL_HANDLE | Noner,   ÚstrrC   ÚNone©rC   rG   ©rC   r   )r=   rF   rC   rG   )rC   Úint)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r&   r-   r0   r3   r5   r7   r+   r:   r<   r?   rA   Ú__classcell__)r)   s   @r   r   r   B   sg   ø„ ñö40ð KSðPØ'ðPØDGðPà	õPõ*	õõõõõ+õ.õ(÷-ñ -r   r   c                  óN   — e Zd ZU dZdZded<   	 	 	 d	 	 	 	 	 	 	 d	d„Zd
d„Zdd„Zy)r   aÅ  Context-manager that captures CUDA work into a :class:`torch.cuda.CUDAGraph` object for later replay.

    See :ref:`CUDA Graphs <cuda-graph-semantics>` for a general introduction,
    detailed use, and constraints.

    Arguments:
        cuda_graph (torch.cuda.CUDAGraph): Graph object used for capture.
        pool (optional): Opaque token (returned by a call to :func:`~torch.cuda.graph_pool_handle()` or
            :meth:`other_Graph_instance.pool()<torch.cuda.CUDAGraph.pool>`) hinting this graph's capture
            may share memory from the specified pool. See :ref:`Graph memory management<graph-memory-management>`.
        stream (torch.cuda.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.
        capture_error_mode (str, optional): specifies the cudaStreamCaptureMode for the graph capture stream.
            Can be "global", "thread_local" or "relaxed". During cuda graph capture, some actions, such as cudaMalloc,
            may be unsafe. "global" will error on actions in other threads, "thread_local" will only error for
            actions in the current thread, and "relaxed" will not error on actions. Do NOT change this setting
            unless you're familiar with `cudaStreamCaptureMode <https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85>`_

    .. 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.

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

    .. _cudaStreamCaptureMode:
        https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html#group__CUDART__STREAM_1g9d0535d93a214cbf126835257b16ba85
    Nútorch.cuda.Stream | NoneÚdefault_capture_streamc                óŠ  — |€C| j                   j                  €-t        j                  j	                  «       | j                   _        |€dn|f| _        |�|n| j                   j                  | _        | j                  €t        d«      ‚t        j                  j                  | j                  «      | _	        || _
        || _        y )Nr   zcapture_stream must not be None)r)   rR   r    r!   ÚStreamr+   Úcapture_streamÚAssertionErrorÚstreamÚ
stream_ctxÚ
cuda_graphr,   )r.   rY   r+   rW   r,   s        r   Ú__init__zgraph.__init__Ö   s¡   € ð ˆ>˜dŸn™n×CÑCÐKÜ49·J±J×4EÑ4EÓ4GˆD�N‰NÔ1à;?¸<±RÈdÈWˆŒ	àÐ(‰F¨d¯n©n×.SÑ.Sð 	Ôð ×ÑÐ&Ü Ð!BÓCÐCÜŸ*™*×+Ñ+¨D×,?Ñ,?Ó@ˆŒØ$ˆŒØ"4ˆÕr   c                ó¼  — t         j                  j                  «        t         j                  j                  j
                  rt        j                  «        t         j                  j                  «        t         j                  j                  «        | j                  j                  «         | j                  j                  | j                  d| j                   iŽ y )Nr,   )r    r!   ÚsynchronizeÚcompilerÚconfigÚforce_cudagraph_gcÚgcÚcollectÚempty_cacheÚ_CÚ_host_emptyCacherX   Ú	__enter__rY   r-   r+   r,   )r.   s    r   re   zgraph.__enter__í   s�   € ä�
‰
×ÑÔ ä�>‰>× Ñ ×3Ò3ô �J‰JŒLä�
‰
×ÑÔ ä�‰×!Ñ!Ô#ð 	�‰×!Ñ!Ô#à%ˆ�‰×%Ñ%à�Y‰Yð	
ð  $×6Ñ6ó		
r   c                ój   — | j                   j                  «         | j                  j                  |Ž  y r$   )rY   r0   rX   Ú__exit__)r.   Úargss     r   rg   zgraph.__exit__  s&   € Ø�‰×#Ñ#Ô%Ø ˆ�‰× Ñ  $Ò'r   )NNrD   )rY   r   r+   rE   rW   rQ   r,   rF   rH   )rh   ÚobjectrC   rG   )	rK   rL   rM   rN   rR   Ú__annotations__rZ   re   rg   r   r   r   r   r   ¶   sU   … ñð: 8<ÐÐ4Ó;ð
 %)Ø+/Ø"*ð5àð5ð "ð5ð )ð	5ð
  ó5ó.
ô6(r   r   útorch.nn.Module.r   Ú_ModuleOrCallablec                 ó   — y r$   r   ©Ú	callablesÚsample_argsÚnum_warmup_itersÚallow_unused_inputr+   s        r   r   r     s   € ð r   c                 ó   — y r$   r   rn   s        r   r   r     s   € ð %(r   c                ó|  — t        j                  «       rt        j                  «       rt        d«      ‚d}t	        | t
        «      s*d}| f} t        j                  t
        t        df   |«      f}n,t        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„ |j%                  «       D «       «      st!        d«      ‚t        j&                  j(                  j*                  |	Ž }
|j-                  t        |
«      «       t#        d	„ |
D «       «      rŒüt!        d
«      ‚ |D �	cg c]  }	t        |	«      ‘Œ }}	| D �cg c]A  }t	        |t         j                  j                  «      rt        |j/                  «       «      nd‘ŒC }}t1        t        | «      «      D �cg c]  }||   ||   z   ‘Œ }}t1        t        | «      «      D �cg c]   }t         j2                  j5                  «       ‘Œ" }}t1        t        | «      «      D �cg c]   }t         j2                  j5                  «       ‘Œ" }}|€
t7        «       n|}t         j2                  j9                  «        t         j2                  j;                  t         j2                  j=                  «       «      5  t        | ||«      D ]¸  \  }}	}d\  }}}t1        |«      D ]“  }t         j&                  j(                  j?                   ||	Ž «      }t        d„ |D «       «      }t        |«      dkD  sŒPt         j@                  jC                  |t        d„ |D «       «      t        d„ |D «       «      d|¬«      }Œ• |||fD ]  }~Œ Œº 	 ddd«       t         j2                  j9                  «        g }g }t        | ||«      D ]Œ  \  }}	}t         j2                  jE                  ||¬«      5   ||	Ž }ddd«       t         j&                  j(                  jG                  «      \  }}|j-                  t        |«      «       |j-                  |«       ŒŽ g }g } t        tI        |«      tI        |«      tI        |«      «      D �]  \  }}!}"t        d„ |!D «       «      }#t        d„ |!D «       «      }d}t        |«      dkD  rnt         j2                  jE                  |"|¬«      5  t         j@                  jC                  |t        d„ |D «       «      t        d„ |#D «       «      d|¬«      }ddd«       g }$d}%|D ];  }&|&jJ                  r|�|$j-                  ||%   «       |%dz  }%Œ+|$j-                  d«       Œ= t        |$«      }$|j-                  |#«       | j-                  |$«       �Œ |jM                  «        | jM                  «        	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„}'g }(tO        | «      D ]©  \  }} |'||   ||   ||   ||   ||   ||   ||   ||   | |   «	      })t	        |t         j                  j                  «      rD	 	 	 	 	 	 	 	 	 	 dd„}* |*||jP                  |)|jR                  «      |_)        |(j-                  |«       Œ™|(j-                  |)«       Œ« |r|(d   S t        |(«      S c c}	w c c}w c c}w c c}w c c}w # 1 sw Y   �Œ.xY w# 1 sw Y   �ŒÖxY w# 1 sw Y   �Œ´xY w)aØ  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 CUDA work as a CUDA 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 CUDA 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.
    See :ref:`Graph memory management<graph-memory-management>` for when this is appropriate.

    Arguments:
        callables (torch.nn.Module or Python function, or tuple of these): Callable or callables to graph.
            See :ref:`Graph memory management<graph-memory-management>` for when passing a tuple of callables
            is appropriate.  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.cuda.graph_pool_handle` or
            :meth:`other_Graph_instance.pool()<torch.cuda.CUDAGraph.pool>`) that hints this graph may share memory
            with the indicated pool.  See :ref:`Graph memory management<graph-memory-management>`.
    .. 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.cuda.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.cuda.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.cuda.make_graphed_callables` only with disabled
        caching. The context manager `torch.cuda.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  ó8   K  — | ]  }|j                   d u –— Œ y­w)FN©Úrequires_grad©Ú.0Úbs     r   ú	<genexpr>z)make_graphed_callables.<locals>.<genexpr>Š  s   è ø€ ÒE°A�q—‘¨%Ô/ÑEùs   ‚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  óP   K  — | ]  }t        |t        j                  «      –— Œ  y ­wr$   )Ú
isinstancer    r   )ry   Úargs     r   r{   z)make_graphed_callables.<locals>.<genexpr>’  s   è ø€ ÒH°S”:˜c¤5§<¡<×0ÑHùs   ‚$&zfIn the beta API, sample_args for each callable must contain only Tensors. Other types are not allowed.r   N)NNNc              3  ó:   K  — | ]  }|j                   sŒ|–— Œ y ­wr$   rv   ©ry   Úos     r   r{   z)make_graphed_callables.<locals>.<genexpr>´  s   è ø€ Ò$K¨1¸1¿?»?¤QÑ$Kùó   ‚”c              3  ó:   K  — | ]  }|j                   sŒ|–— Œ y ­wr$   rv   ©ry   Úis     r   r{   z)make_graphed_callables.<locals>.<genexpr>¸  s   è ø€ ò %Ø"#¸q¿»œAñ%ùr‚   c              3  ó`   K  — | ]&  }|j                   sŒt        j                  |«      –— Œ( y ­wr$   ©rw   r    Ú
empty_liker€   s     r   r{   z)make_graphed_callables.<locals>.<genexpr>»  s&   è ø€ ò +Ø45ÀAÇOÃOœE×,Ñ,¨Q×/ñ+ùs   ‚.”.)ÚoutputsÚinputsÚgrad_outputsÚonly_inputsÚallow_unused)r+   c              3  ób   K  — | ]'  }|j                   rt        j                  |«      nd –— Œ) y ­wr$   r‡   r€   s     r   r{   z)make_graphed_callables.<locals>.<genexpr>ß  s+   è ø€ ò $
ØAB 1§?¢?ŒE×Ñ˜QÔ¸Ó<ñ$
ùs   ‚-/c              3  ó:   K  — | ]  }|j                   sŒ|–— Œ y ­wr$   rv   r€   s     r   r{   z)make_graphed_callables.<locals>.<genexpr>ã  s   è ø€ ÒJ 1¸!¿/»/œQÑJùr‚   c              3  ó:   K  — | ]  }|j                   sŒ|–— Œ y ­wr$   rv   r„   s     r   r{   z)make_graphed_callables.<locals>.<genexpr>é  s   è ø€ Ò T qÀAÇOÃO¤Ñ Tùr‚   c              3  ó&   K  — | ]	  }|€Œ|–— Œ y ­wr$   r   r€   s     r   r{   z)make_graphed_callables.<locals>.<genexpr>ê  s   è ø€ Ò&W¨QÈÉ¤qÑ&Wùs   ‚Šé   c	           	     ó€   ‡ ‡‡‡‡‡‡‡‡‡
—  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	y)úOmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphedc                ó4  •— t        ‰«      D ]A  }‰|   j                  «       ||   j                  «       k7  sŒ+‰|   j                  ||   «       ŒC ‰j                  «        t	        ‰t
        «      st        dt        ‰«      › �«      ‚t        d„ ‰D «       «      S )Nz"static_outputs must be tuple, got c              3  ó<   K  — | ]  }|j                  «       –— Œ y ­wr$   ©Údetachr€   s     r   r{   zjmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.forward.<locals>.<genexpr>  s   è ø€ Ò@¨A˜QŸX™XŸZÑ@ùs   ‚)ÚrangeÚdata_ptrÚcopy_r5   r}   ÚtuplerV   Útype)ÚctxrŠ   r…   Ú	fwd_graphÚlen_user_argsÚstatic_input_surfaceÚstatic_outputss      €€€€r   ÚforwardzWmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.forward  s�   ø€ ô ˜}Ó-ò A�AØ+¨AÑ.×7Ñ7Ó9¸VÀA¹Y×=OÑ=OÓ=QÓQØ,¨QÑ/×5Ñ5°f¸Q±iÕ@ðAð × Ñ Ô"Ü! .´%Ô8Ü(Ø<¼TÀ.Ó=QÐ<RÐSóð ô Ñ@°Ô@Ó@Ð@r   c                óž  •— t        |«      t        ‰«      k7  r#t        dt        |«      › dt        ‰«      › �«      ‚t        ‰|«      D ];  \  }}|€Œ	|j                  «       |j                  «       k7  sŒ+|j	                  |«       Œ= ‰j                  «        t        ‰t        «      st        dt        ‰«      › �«      ‚t        d„ ‰D «       «      S )Nzlen(grads)=z != len(static_grad_outputs)=z&static_grad_inputs must be tuple, got c              3  óD   K  — | ]  }|�|j                  «       n|–— Œ y ­wr$   r˜   rx   s     r   r{   zkmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.backward.<locals>.<genexpr>3  s)   è ø€ ò ð ð #$ -�A—H‘H”J°QÓ6ñùs   ‚ )	ÚlenrV   Úzipr›   rœ   r5   r}   r�   rž   )rŸ   ÚgradsÚgÚgradÚ	bwd_graphÚstatic_grad_inputsÚstatic_grad_outputss       €€€r   ÚbackwardzXmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.backward  sÚ   ø€ ô �u“:¤Ð%8Ó!9Ò9Ü(Ø%¤c¨%£j \Ð1NÌsÐSfÓOgÐNhÐióð ô  #Ð#6¸Ó>ò *‘G�A�tØ‘}ð Ÿ:™:›<¨4¯=©=«?Ó:ØŸG™G D�Mð*ð × Ñ Ô"ô "Ð"4´eÔ<Ü(Ø@ÄÐFXÓAYÐ@ZÐ[óð ô ñ ð 0ôó ð r   N)rŸ   ri   rŠ   r   rC   útuple[Tensor, ...])rŸ   ri   r©   r   rC   r°   )
rK   rL   rM   Ústaticmethodr¤   r    ÚautogradÚfunctionÚonce_differentiabler¯   )r¬   r    r¡   r­   r®   r¢   r£   s   €€€€€€€r   ÚGraphedr•     sC   ø„ Ø÷
Aó ð
Að Ø�^‰^×$Ñ$×8Ñ8öó 9ó ñr   rµ   c                 óÚ   •— t        j                  j                  j                  | Ž } ‰j                  t        |«      ‰z   Ž }t         j                  j                  j                  |‰«      S r$   )r    ÚutilsÚ_pytreeÚarg_tree_leavesÚapplyr�   Útree_unflatten)Ú	user_argsÚflatten_user_argsÚoutrµ   Úmodule_paramsÚoutput_unflatten_specs      €€€r   ÚfunctionalizedzVmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.functionalized9  sY   ø€ ô !&§¡× 3Ñ 3× CÑ CÀYÐ OÐØ�'—-‘-¤%Ð(9Ó":¸]Ñ"JÐLˆCÜ—;‘;×&Ñ&×5Ñ5°cÐ;PÓQÐQr   )r¼   ri   rC   ri   )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‘n×-Ñ-ô (	÷T	Rð Ðr   c                ó    ‡ ‡‡‡— dˆ ˆˆˆfd„}|S )Nc                 óB   •— ‰j                   ‰k(  r ‰| i |¤ŽS  ‰| i |¤ŽS r$   )Útraining)r¼   Úuser_kwargsÚfuncÚgraph_training_stateÚgraphedÚorig_fwds     €€€€r   Únew_fwdzEmake_graphed_callables.<locals>.make_graphed_forward.<locals>.new_fwdZ  s2   ø€ ð —}‘}Ð(<Ò<Ù&¨	ÐA°[ÑAÐAá'¨ÐB°kÑBÐBr   )r¼   z_P.argsrÇ   z	_P.kwargsrC   r   r   )rÈ   rÉ   rÊ   rË   rÌ   s   ```` r   Úmake_graphed_forwardz4make_graphed_callables.<locals>.make_graphed_forwardT  s   û€ ÷Cð Cð �r   )r    r   r¬   r   r¿   ztuple[torch.nn.Parameter, ...]r¡   rJ   rÀ   ztorch.utils._pytree.TreeSpecr¢   r°   r£   r°   r®   ztuple[Tensor | None, ...]r­   r°   rC   zCallable[..., object])
rÈ   rk   rÉ   rB   rÊ   úCallable[_P, _R]rË   rÎ   rC   rÎ   )*r    Úis_autocast_enabledÚis_autocast_cache_enabledÚRuntimeErrorr}   r�   ÚtypingÚcastr   r¨   ÚnnÚModuler§   Ú_backward_hooksÚ_forward_hooksÚ_forward_pre_hooksrV   ÚallÚbuffersr·   r¸   r¹   ÚappendÚ
parametersrš   r!   r   r   r\   rW   rT   Útree_leavesr²   r«   r   Útree_flattenÚreversedrw   ÚreverseÚ	enumeraterÆ   r¤   )+ro   rp   rq   rr   r+   Újust_one_callableÚ_sample_argsÚflatten_sample_argsÚcrh   Úflatten_argÚper_callable_len_user_argsÚper_callable_module_paramsr…   Ú"per_callable_static_input_surfacesÚ_Ú
fwd_graphsÚ
bwd_graphsÚmempoolrÈ   r¢   Úgrad_inputsr‰   Úoutputs_gradÚ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_idxr~   rÃ   ÚretrÊ   rÍ   s+                                              r   r   r   %  sz  € ôR × Ñ Ô"¤u×'FÑ'FÔ'HÜØmó
ð 	
ð Ðô �i¤Ô'Ø ÐØ�Lˆ	ÜŸ™¤E¬&°#¨+Ñ$6¸ÓDÐF‰ä—{‘{¤5¬¬v°s¨{Ñ);¸SÐ)@Ñ#AÀ;ÓOˆàÐä�y ,Ó/ó ‰ˆˆ4Ü�aœŸ™Ÿ™Ô)ä�A×%Ñ%Ó&¨!Ò+Ü˜×(Ñ(Ó)¨QÒ.Ü˜×,Ñ,Ó-°Ò2ä$ðaóð ô ÑE¸¿¹»ÔEÔEÜ$ð1óð ô
 —k‘k×)Ñ)×9Ñ9¸4Ð@ˆØ×"Ñ"¤5¨Ó#5Ô6ÜÑH¸KÔHÕHÜ ð^óð ð)ð6 9LÖ!L°¤# d¥)Ð!LÐÐ!Lð ö"àô ",¨A¬u¯x©x¯©Ô!?Œˆa�l‰l‹nÔÀRÑGð"Ðð "ô ”s˜9“~Ó&ö*àð 	˜AÑÐ!;¸AÑ!>Ó>ð*Ð&ð *ô
 38¼¸I»Ó2GÖH¨Q”%—*‘*×&Ñ&Õ(ÐH€JÐHÜ27¼¸I»Ó2GÖH¨Q”%—*‘*×&Ñ&Õ(ÐH€JÐHà%) \ÔÔ!°t€Gô
 
‡J�J×ÑÔÜ	�‰×	Ñ	œ5Ÿ:™:×,Ñ,Ó.Ó	/ñ Ü03Ø�|Ð%Gó1
ò 	Ñ,ˆD�$Ð,ð 2BÑ.ˆK˜ ,ÜÐ+Ó,ò �ÜŸ+™+×-Ñ-×9Ñ9¹$À¸+ÓF�Ü$Ñ$K°Ô$KÓK�Ü�|Ó$ qÓ(Ü"'§.¡.×"5Ñ"5Ø ,Ü$ñ %Ø';ô%ó  ô &+ñ +Ø9@ô+ó &ð %)Ø%7ð #6ó 
#‘Kð	ð ˜|¨[Ð9ò �Ùññ'	÷ô. 
‡J�J×ÑÔð #%ÐØ)+Ð&Ü!$ Y°¸jÓ!Iò 8Ñˆˆd�IÜ�Z‰Z×Ñ˜i¨gÐÓ6ñ 	'Ù ˜;ˆL÷	'ô !&§¡× 3Ñ 3× @Ñ @ÀÓ NÑˆ˜Ø#×*Ñ*¬5°Ó+AÔBØ*×1Ñ1°$Õ7ð8ð (*Ð$Ø&(Ð#Ü;>ÜÐ3Ó4ÜÐ,Ó-Ü�Óó<ó %CÑ7Ð˜n¨iô $ñ $
ØFTô$
ó 
Ðô ÑJ¨ÔJÓJˆØˆÜˆ|Ó˜qÒ Ü—‘×!Ñ! )°'Ð!Ó:ñ Ü#Ÿn™n×1Ñ1Ø(Ü Ñ TÐ,@Ô TÓTÜ!&Ñ&WÐ2EÔ&WÓ!WØ $Ø!3ð 2ó �÷ð  ÐØˆØ'ò 	0ˆCØ× Ò  [Ð%<Ø"×)Ñ)¨+°hÑ*?Ô@Ø˜A‘‘à"×)Ñ)¨$Õ/ð	0ô #Ð#5Ó6Ðà(×/Ñ/Ð0CÔDØ'×.Ñ.Ð/AÖBðK%CðP %×,Ñ,Ô.Ø#×+Ñ+Ô-ð=Øð=àð=ð 6ð=ð ð	=ð
  <ð=ð 1ð=ð +ð=ð 7ð=ð /ð=ð 
ó=ð@ $&€CÜ˜YÓ'ò $ ‰ˆˆ4Ù0Ø�q‰MØ�q‰MØ& qÑ)Ø& qÑ)Ø.¨qÑ1Ø.¨qÑ1Ø'¨Ñ*Ø,¨QÑ/Ø+¨AÑ.ó

ˆô �dœEŸH™HŸO™OÔ,ðØ%ðà&*ðð *ðð +ð	ð
 "óñ  0Ø�d—m‘m W¨d¯l©lóˆDŒLð �J‰J�tÕà�J‰J�wÕðI$ ñL Ø�1‰vˆä�‹:Ðùòi "Mùò"ùò*ùò
 IùÚH÷ñ ú÷B	'ñ 	'ú÷0ñ úsL   Æ6[>ÇA\È,\É%\Ê%\Ì!A5\ÎA\Ñ
\$Ô:A\1Ü\!Ü$\.	Ü1\;	)rC   rB   rI   )é   FN)ro   rl   rp   r°   rq   rJ   rr   rB   r+   rE   rC   rl   )ro   útuple[_ModuleOrCallable, ...]rp   ztuple[tuple[Tensor, ...], ...]rq   rJ   rr   rB   r+   rE   rC   rû   )ro   ú1_ModuleOrCallable | tuple[_ModuleOrCallable, ...]rp   z3tuple[Tensor, ...] | tuple[tuple[Tensor, ...], ...]rq   rJ   rr   rB   r+   rE   rC   rü   )&Ú
__future__r   r`   rÒ   Úcollections.abcr   r   r   r   r   Útyping_extensionsr	   r
   r   r    r   Ú
torch.cudar   Ú_utilsr   Ú__all__r   r   Úhasattrrc   Ú__dict__Útorch._Cr   r   r   r   r   r   r   ri   rl   rj   r   r   r   r   ú<module>r     sø  ðæ "ã 	Û Ý $ß <Ó <ß 6Ñ 6ã Ý ñ å'å  ò€ñ ˆTƒ]€Ùˆtƒ_€ñ ˆu�x‰xÐ*Ô+á&1°,Ó&?€E‡H�H×Ñ�lÑ#Ù.9Ð:NÓ.O€E‡H�H×ÑÐ*Ñ+Ù:EØ(ó;€E‡H�H×ÑÐ6Ñ7÷ TÑ Só,ó9ôq-�
ô q-÷hT(ñ T(ðp  %Ð%6¸ÀÀfÀÑ8MÐ%MÑNÐ �9Ó Nð 
ð Ø$Ø $ðØ ðà#ðð ðð ð	ð
 ðð òó 
ðð 
ð Ø$Ø $ð(Ø,ð(à/ð(ð ð(ð ð	(ð
 ð(ð #ò(ó 
ð(ð Ø$Ø $ðIØ@ðIàDðIð ðIð ð	Ið
 ðIð 7ôIr   