+
    &j                     V    ^ RI t ^ RIHt ^ RIHt ^ RIt^ RIHt  ! R R]4      tR.t	R# )    N)Literal)Self)_acceleratorGraphc                   ^  a a ] tR t^	t oRtRRRRR/V3R lV 3R lllltRRRRR/V3R lV 3R	 lll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V 3R l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V 3R l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V3R lR ltRtVtV ;t# ) Grapha  
Wrapper around an :ref:`accelerator<accelerators>` graph that supports capture and replay.

A graph captures a sequence of operations and their dependencies, allowing them to be
replayed efficiently with reduced overhead. This class can be used as a context manager
to automatically capture operations on the current stream.

Arguments:
    keep_graph (bool, optional): If ``False``, the underlying graph is destroyed and the
        executable graph is instantiated on the GPU at the end of ``capture_end``.
        If ``True``, the underlying graph is preserved after ``capture_end``. In this case,
        the executable graph is not instantiated automatically; it must be explicitly created
        by calling ``instantiate``, or it will be instantiated on the first call to ``replay``.
        Defaults to ``False``.
    pool (tuple[int, int], optional): Memory pool identifier for this graph. Multiple graphs
        can share the same pool by passing the same identifier, which can reduce memory overhead.
        Defaults to ``None``.
    capture_error_mode (Literal["default", "global", "thread_local", "relaxed"], optional):
        Specifies the behavior of graph capture. The exact semantics are backend-specific.
        ``"default"``: backend-defined default capture behavior.
        ``"global"``: potentially unsafe API calls are prohibited. Errors may occur if capture
        in the current thread affects other threads.
        ``"thread_local"``: potentially unsafe API calls are prohibited. Errors occur only if
        capture in the current thread affects itself.
        ``"relaxed"``: the current thread is allowed to make potentially unsafe API calls, except
        for calls that inherently conflict with stream capture.
        Default: ``"default"``.

Example::

    >>> # xdoctest: +SKIP
    >>> x = torch.zeros([2000], device=0)

    >>> stream = torch.Stream()
    >>> graph = torch.accelerator.Graph()
    >>> with stream, graph:
    ...     x += 1

    >>> graph.replay()
poolNcapture_error_modedefaultc                d   < V ^8  d   QhRS[ RS[S[S[3,          R,          RS[R,          RS[/#    
keep_graphr   Nr	   return)r
   globalthread_localrelaxed)booltupleintr   r   )format__classdict__s   "p/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/accelerator/graphs.py__annotate__Graph.__annotate__3   sH     	0 	0	0 CHo$		0
 $:
	0 
	0    c               "   < \         SV `  W4      # N)super__new__)clsr   r   r	   	__class__s   &&$$r   r   Graph.__new__3   s     ws//r   c                b   < V ^8  d   QhRS[ RS[S[S[3,          R,          RS[R,          RR/# r   )r   r   r   r   )r   r   s   "r   r   r   >   sH     5 55 CHo$	5
 $:
5 
5r   c               >   < \         SV `  V4       W n        W0n        R # r   )r   __init__
graph_poolr	   )selfr   r   r	   r!   s   &&$$r   r%   Graph.__init__>   s     	$"4r   c                   < V ^8  d   QhRR/# r   r   N )r   r   s   "r   r   r   L   s     	
 	
t 	
r   c                R   < \         SV `  V P                  V P                  R7       R# )z
Begin graph capture on the current stream.

All operations on the current stream after this call will be recorded into the graph until
``capture_end`` is called, using the memory pool and capture error mode provided at construction time.
)r   r	   N)r   capture_beginr&   r	   r'   r!   s   &r   r-   Graph.capture_beginL   s&     	T5L5L 	 	
r   c                   < V ^8  d   QhRR/# r*   r+   )r   r   s   "r   r   r   W         T r   c                $   < \         SV `  4        R# )z|
End graph capture on the current stream of the current device.

After this call, the graph can be replayed via ``replay``.
N)r   capture_endr.   s   &r   r3   Graph.capture_endW        	r   c                   < V ^8  d   QhRR/# r*   r+   )r   r   s   "r   r   r   _   r1   r   c                $   < \         SV `  4        R# )z
Instantiate the underlying 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.
N)r   instantiater.   s   &r   r8   Graph.instantiate_   r5   r   c                   < V ^8  d   QhRR/# r*   r+   )r   r   s   "r   r   r   g   s       r   c                $   < \         SV `  4        R# )z'Replay the work captured by this graph.N)r   replayr.   s   &r   r<   Graph.replayg   s    r   c                   < V ^8  d   QhRR/# r*   r+   )r   r   s   "r   r   r   k   s      t r   c                $   < \         SV `  4        R# )z
Delete the graph currently held by this instance.

After this call, the graph can be recaptured. Set :attr:`graph_pool` or
:attr:`capture_error_mode` beforehand to use different settings on the next capture.
N)r   resetr.   s   &r   r@   Graph.resetk   s     	r   c                6   < V ^8  d   QhRS[ S[S[3,          /# )r   r   )r   r   )r   r   s   "r   r   r   t   s      eCHo r   c                    < \         SV `  4       # )a  
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.

Example::
    >>> # xdoctest: +SKIP
    >>> g1 = torch.accelerator.Graph()
    >>> g1.capture_begin()
    >>> # ... operations ...
    >>> g1.capture_end()

    >>> # Share g1's memory pool with a new graph
    >>> pool_id = g1.pool()
    >>> g2 = torch.accelerator.Graph(pool=pool_id)
)r   r   r.   s   &r   r   
Graph.poolt   s    $ w|~r   c                   < V ^8  d   QhRR/# r*   r+   )r   r   s   "r   r   r      s     + +4 +r   c                    < \         SV `  4       # )z)Enable debugging mode for ``debug_dump``.)r   enable_debug_moder.   s   &r   rG   Graph.enable_debug_mode   s    w(**r   c                $   < V ^8  d   QhRS[ RR/# )r   pathr   N)str)r   r   s   "r   r   r      s     ( (s (t (r   c                "   < \         SV `  V4      # )a  
Dump the captured graph to a file for debugging purposes if the debugging is
enabled via ``enable_debug_mode``.

Arguments:
    path (str): Path to dump the graph to.

Example::
    >>> # xdoctest: +SKIP
    >>> s = torch.Stream()
    >>> g = torch.accelerator.Graph()
    >>> g.enable_debug_mode()

    >>> with s, g:
    >>> # ... operations ...

    >>> # Dump captured graph to a file "graph_dump.dot"
    >>> g.debug_dump("graph_dump.dot")
)r   
debug_dump)r'   rJ   r!   s   &&r   rM   Graph.debug_dump   s    ( w!$''r   c                   < V ^8  d   QhRR/# r*   r+   )r   r   s   "r   r   r      s     	 	4 	r   c                X   \         P                  P                  4        \         P                  P                  P
                  '       d   \        P                  ! 4        \         P                  P                  4        \         P                  P                  4        V P                  4        R # r   )torchacceleratorsynchronizecompilerconfigforce_cudagraph_gcgccollectempty_cacheempty_host_cacher-   )r'   s   &r   	__enter__Graph.__enter__   se    %%'>>  333 JJL%%'**,r   c                $   < V ^8  d   QhRS[ RR/# )r   exc_infor   N)object)r   r   s   "r   r   r      s      & T r   c                &    V P                  4        R # r   )r3   )r'   r^   s   &*r   __exit__Graph.__exit__   s    r   )r	   r&   )F)__name__
__module____qualname____firstlineno____doc__r   r%   r-   r3   r8   r<   r@   r   rG   rM   r[   ra   __static_attributes____classdictcell____classcell__)r!   r   s   @@r   r   r   	   s     'R	0 (,		0 	0 	05 (,	5 5 5	
 	
     (+ +( (,	 	  r   r   )
rW   typingr   typing_extensionsr   rQ   torch._Cr   r   __all__r+   r   r   <module>ro      s-    	  "  &e eP )r   