+
    –°³j$ ã                  óî  a € 0 t $ ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHtHtHtHt ^ RIHtHtHt ^ RIt^ RIHt ^ RIHt  ^ R	IHtHt ]'       d$   ^ R
IH t H!t! ^ RI"H#t# ^ RI$H%t% ] ]!,          t&R]'R&   M]PP                  t&R]'R&   ^RI)H*t* . RXOt+]! R4      t,]! R4      t-R R lt.R R lt/]0! ]Pb                  R4      '       g^   ]*! R4      ]Pb                  Pd                  R&   ]*! R4      ]Pb                  Pd                  R&   ]*! R4      ]Pb                  Pd                  R&   ^ RI3H4t4H5t5H6t6 R R lt7R R  lt8R! R" lt9 ! R# R$4      t:]	! 4       t;R%]'R&&   ]	! 4       t<R%]'R'&   ]	! 4       t=R%]'R(&   ]	! 4       t>R%]'R)&   ]	! 4       t?R%]'R*&   R+ R, lt@R- R. ltAR/ R0 ltBR1 R2 ltCR3 R4 ltDR5 R6 ltER7 R8 ltF]	! 4       tGR9]'R:&   R; R< ltHR= R> ltIR? R@ ltJ ! RA R]54      tK ! RB RC]P˜                  4      tMRD RE ltNRFRG/RH RI lltORFRG/RJ RK lltPRL RM ltQ ! RN R4      tR]RO]RP]S3,          3,          tTR]'RQ&   ]RYRR RS ll4       tU]RYRT RU ll4       tURYRV RW lltUR#   ] d	    RtRt ELi ; i)Zé    )ÚannotationsN)ÚOrderedDict)ÚCallable)ÚoverloadÚTYPE_CHECKINGÚ	TypeAliasÚ	TypeGuardÚUnion)Ú	ParamSpecÚSelfÚTypeVar)ÚTensor)Ú_check_cuda_bindings)ÚdriverÚruntime)Ú_POOL_HANDLEÚMemPool©Ú_CUDAGraphInputLivenessTracker©ÚRemovableHandler   Ú
_GraphPool)Ú_dummy_typeÚ	CUDAGraphÚgraphÚ_RÚ_Pc               ó    € V ^8„  d   QhRRRR/# )é   ÚpoolÚobjectÚreturnzTypeGuard[MemPool]© )Úformats   "ÚR/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/cuda/graphs.pyÚ__annotate__r&   ?   s   € ÷ Eñ E�vð EÐ"4ñ Eó    c                óf   € \        \        P                  R R4      pVRJ;'       d    \        W4      # )r   N)ÚgetattrÚtorchÚcudaÚ
isinstance)r    Úmempool_clss   & r%   Ú_is_mem_poolr.   ?   s,   € Üœ%Ÿ*™* i°Ó6€KØ˜dÐ"×DÐD¤z°$Ó'DÐDr'   c               ó    € V ^8„  d   QhRRRR/# )r   r    ú_GraphPool | Noner"   z_POOL_HANDLE | Noner#   )r$   s   "r%   r&   r&   D   s   € ÷ -ñ -Ð(ð -Ð-@ñ -r'   c                ó    € V f   R # \        V 4      '       d"   \        P                  ! RV P                  4      # \        P                  ! RV 4      # )Nr   )r.   ÚtypingÚcastÚid)r    s   &r%   Ú_get_pool_idr5   D   s;   € Ø‚|ÙÜ�D×ÒÜ�{Š{˜>¨4¯7©7Ó3Ð3Ü�;Š;�~ tÓ,Ð,r'   Ú_CudaStreamBaseÚ
_CUDAGraphÚ_graph_pool_handleÚ_cuda_isCurrentStreamCapturing)r9   r7   r8   c               ó   € V ^8„  d   QhRR/# ©r   r"   Úboolr#   )r$   s   "r%   r&   r&   W   s   € ÷ ,ñ , Tñ ,r'   c                 ó   € \        4       # )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.
)r9   r#   r'   r%   Úis_current_stream_capturingr>   W   s   € ô
 *Ó+Ð+r'   c               ó   € V ^8„  d   QhRR/# ©r   r"   r   r#   )r$   s   "r%   r&   r&   `   s   € ÷ 9ñ 9˜<ñ 9r'   c                 óP   € \         P                  P                  \        4       4      # )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.
)r*   r+   r   r8   r#   r'   r%   Úgraph_pool_handlerB   `   s   € ô �:‰:×"Ñ"Ô#5Ó#7Ó8Ð8r'   c               ó   € V ^8„  d   QhRR/# ©r   r"   ÚNoner#   )r$   s   "r%   r&   r&   k   s   € ÷ 

ñ 

 ñ 

r'   c                 ó,   € \         f   \        R4      hR# )zœRaise a uniform error if the cuda-bindings package is unavailable.

``_cuda_runtime`` and ``_cuda_driver`` are imported together, so checking one
suffices.
NzcThis CUDAGraph API requires the cuda-bindings package; install it with `pip install cuda-bindings`.)Ú_cuda_runtimeÚRuntimeErrorr#   r'   r%   Ú_require_cuda_bindingsrI   k   s!   € ô ÒÜð;ó
ð 	
ñ r'   c                  ó2   € ] tR t^xtRtR R ltR R ltRtR# )Ú_RetainedCallbacksa  Holds destroy callbacks and retained objects for a single capture cycle
of a :class:`CUDAGraph`.

A :class:`CUDAGraph` owns one of these and arms a :func:`weakref.finalize`
bound to :meth:`fire`. The holder deliberately does NOT reference the graph,
so the finalizer cannot keep the graph alive; :meth:`fire` can still sync the
replay streams because they are mirrored onto the holder, not read off the
graph. Callbacks and objects live in ``OrderedDict``s keyed by
``RemovableHandle`` id so registrations can be individually removed.
c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   Ú_RetainedCallbacks.__annotate__„   s   € ÷ 
"ñ 
"˜$ñ 
"r'   c                	ó|   € \        4       V n        \        4       V n        \        4       V n        R V n        R V n        R# ©FN)r   Ú	callbacksÚobjectsÚsetÚreplay_streamsÚsync_before_fireÚ_fired©Úselfs   &r%   Ú__init__Ú_RetainedCallbacks.__init__„   s/   € Ü?J»}ˆŒÜ1<³ˆŒô 7:³eˆÔØ&+ˆÔØ!ˆŽr'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   rM   �   s   € ÷ ñ �dñ r'   c                	ó¼  € V P                   '       d   R # RV n         V P                  '       d%   V P                   F  p VP                  4        K  	  \        V P                  P                  4       4       F  p V! 4        K  	  V P                  P                  4        V P                  P                  4        R #   \         d     KŽ  i ; i  \         d     Ke  i ; i)NT)
rU   rT   rS   ÚsynchronizeÚ	ExceptionÚlistrP   ÚvaluesÚclearrQ   )rW   ÚstreamÚcbs   &  r%   ÚfireÚ_RetainedCallbacks.fire�   sµ   € à�;�;ˆ;ÙØˆŒØ× × Ð ð ×-Ô-�ðØ×&Ñ&Ö(ñ .ô
 �t—~‘~×,Ñ,Ó.Ö/ˆBðÙ–ñ 0ð
 	�‰×ÑÔØ�‰×ÑÖøô !ô Úðûô
 ô Úðús#   ¾B:Á9CÂ:C	ÃC	ÃCÃC)rU   rP   rQ   rS   rT   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rX   rc   Ú__static_attributes__r#   r'   r%   rK   rK   x   s   † ñ	õ
"÷ñ r'   rK   ú-OrderedDict[int, Callable[[CUDAGraph], None]]Ú_global_capture_start_hooksÚ_global_capture_end_hooksÚ_global_instantiate_hooksÚ_global_replay_start_hooksÚ_global_replay_end_hooksc               ó$   € V ^8„  d   QhRRRRRR/# )r   Úregistryrk   ÚfnúCallable[[CUDAGraph], None]r"   r   r#   )r$   s   "r%   r&   r&   ¸   s&   € ÷ ñ Ø;ðà#ðð ñr'   c                ó>   € ^ RI Hp V! V 4      pWVP                  &   V# )r   r   )Útorch.utils.hooksr   r4   )rr   rs   r   Úhandles   &&  r%   Ú_register_global_hookrx   ¸   s"   € õ 2á˜XÓ&€FØˆV�Y‰YÑØ€Mr'   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rr   rk   Útorch_cuda_graphr   r"   rE   r#   )r$   s   "r%   r&   r&   Ã   s&   € ÷ ñ Ø;ðàðð 
ñr'   c                ó|   € \        V P                  4       4       F  p V! V4       K  	  R #   \         d     K   i ; i©N)r^   r_   r]   )rr   rz   rs   s   && r%   Ú_run_global_hooksr}   Ã   s<   € ô �8—?‘?Ó$Ö%ˆð	ÙÐÖ ó &øô ô 	Úð	ús   ž,¬;º;c               ó    € V ^8„  d   QhRRRR/# ©r   rs   rt   r"   r   r#   )r$   s   "r%   r&   r&   Î   s    € ÷ Bñ BØ#ðBàñBr'   c                ó"   € \        \        V 4      # )aè  Register a hook run with each CUDA graph as its capture begins. Returns a
RemovableHandle; call ``.remove()`` to unregister.

.. warning::
    The hook runs with capture already live on the current stream, so it must not issue
    CUDA work: anything it launches is captured into the graph, and under the default
    ``"global"`` capture error mode an unsafe call (e.g. an allocation) raises. Querying
    capture state is fine. Do preparation that needs CUDA before the capture instead.
)rx   rl   ©rs   s   &r%   Ú!register_graph_capture_start_hookr‚   Î   s   € ô !Ô!<¸bÓAÐAr'   c               ó    € V ^8„  d   QhRRRR/# r   r#   )r$   s   "r%   r&   r&   Ý   s    € ÷ @ñ @Ø#ð@àñ@r'   c                ó"   € \        \        V 4      # )zàRegister a hook run with each CUDA graph when its capture ends, while the captured
``cudaGraph_t`` is still live (see :meth:`CUDAGraph.register_capture_end_hook`). Returns a
RemovableHandle; call ``.remove()`` to unregister.)rx   rm   r�   s   &r%   Úregister_graph_capture_end_hookr…   Ý   s   € ô !Ô!:¸BÓ?Ð?r'   c               ó    € V ^8„  d   QhRRRR/# r   r#   )r$   s   "r%   r&   r&   æ   s    € ÷ @ñ @Ø#ð@àñ@r'   c                ó"   € \        \        V 4      # )z…Register a hook run with each CUDA graph right after it is instantiated. Returns a
RemovableHandle; call ``.remove()`` to unregister.)rx   rn   r�   s   &r%   Úregister_graph_instantiate_hookrˆ   æ   s   € ô
 !Ô!:¸BÓ?Ð?r'   c               ó    € V ^8„  d   QhRRRR/# r   r#   )r$   s   "r%   r&   r&   î   s    € ÷ 
Añ 
AØ#ð
Aàñ
Ar'   c                ó"   € \        \        V 4      # )aN  Register a hook run with each CUDA graph at the start of every replay, just before it
is launched. Returns a RemovableHandle; call ``.remove()`` to unregister.

.. note::
    Replay is the hot path and this fires for EVERY graph on EVERY replay -- keep it
    cheap. With nothing registered the cost is a single dict emptiness check.
)rx   ro   r�   s   &r%   Ú register_graph_replay_start_hookr‹   î   s   € ô !Ô!;¸RÓ@Ð@r'   c               ó    € V ^8„  d   QhRRRR/# r   r#   )r$   s   "r%   r&   r&   û   s   € ÷ ?ñ ?Ø#ð?àñ?r'   c                ó"   € \        \        V 4      # )ar  Register a hook run with each CUDA graph at the end of every replay, once the replay is
*enqueued* (the launch is asynchronous, so the GPU work has not completed). Fires even if
the launch raised, so a start hook is always balanced by an end. Returns a RemovableHandle;
call ``.remove()`` to unregister. See the hot-path note on
:func:`register_graph_replay_start_hook`.)rx   rp   r�   s   &r%   Úregister_graph_replay_end_hookrŽ   û   s   € ô !Ô!9¸2Ó>Ð>r'   z,OrderedDict[int, Callable[[set[int]], None]]Ú_global_destroy_hooksc               ó    € V ^8„  d   QhRRRR/# )r   rs   zCallable[[set[int]], None]r"   r   r#   )r$   s   "r%   r&   r&     s   € ÷ ñ Ð$>ð À?ñ r'   c                óP   € ^ RI Hp V! \        4      pV \        VP                  &   V# )ztRegister ``fn(exec_ids)`` to run when a CUDA graph is destroyed. Returns a handle whose
``remove()`` unregisters it.r   )rv   r   r�   r4   )rs   r   rw   s   &  r%   Úregister_graph_destroy_hookr’     s&   € õ 2áÔ2Ó3€FØ')Ô˜&Ÿ)™)Ñ$Ø€Mr'   c               ó   € V ^8„  d   QhRR/# r;   r#   )r$   s   "r%   r&   r&     s   € ÷ 'ñ ' Tñ 'r'   c                 ó    € \        \        4      # )zqTrue when any graph-destroy hook is registered -- the gate a CUDAGraph checks before
arming its destroy callback.)r<   r�   r#   r'   r%   Ú_graph_destroy_hooks_activer•     s   € ô Ô%Ó&Ð&r'   c               ó    € V ^8„  d   QhRRRR/# )r   Úexec_graph_idsúset[int]r"   rE   r#   )r$   s   "r%   r&   r&     s   € ÷ ñ ¨Xð ¸$ñ r'   c                ó„   € \        \        P                  4       4       F  p V! V 4       K  	  R#   \         d     K   i ; i)zêInvoke every registered hook with the destroyed exec graph ids, swallowing per-hook
errors so one failure does not abort the rest (matching the destroy-callback fire
semantics). The single entry point a graph's destroy callback calls.N)r^   r�   r_   r]   )r—   rs   s   & r%   Ú_run_graph_destroy_hooksrš     s>   € ô Ô(×/Ñ/Ó1Ö2ˆð	Ùˆ~Öó 3øô ô 	Úð	ús   ¢0°?¾?c                  ój  a € ] tR tRt$ RtR]R&   R]R&   R]R&   R]R	&   R
]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   RUR V 3R llltR R ltR R  ltR! R" lt	R# R$ lt
R% R& ltR' R( ltR)R/R* R+ lltR)R/R, R- lltR. R/ ltR0 R1 ltR2 R3 ltRVR4 V 3R5 llltR6 V 3R7 lltR8 V 3R9 lltR: R; ltR< V 3R= lltR> V 3R? lltR@ V 3RA lltRB V 3RC lltRD V 3RE lltRF V 3RG lltRH V 3RI lltRJRK/RL RM lltRN V 3RO lltRP V 3RQ lltRR RS lt RTt!V ;t"# )Wr   i(  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 call
        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.

z%_CUDAGraphInputLivenessTracker | NoneÚ_trackerr<   Ú_has_graph_execz
int | NoneÚ_capture_graph_idÚ_remapped_exec_idr˜   Ú_recorded_exec_idsÚ_keep_graphz&dict[int, Callable[[CUDAGraph], None]]Ú_capture_start_hooksÚ_capture_end_hooksÚ_post_instantiate_hooksÚ_caching_graph_datazdict | NoneÚ_instantiate_graph_dataÚ_replay_start_hooksÚ_replay_end_hooksrK   Ú	_retainedzweakref.finalize | NoneÚ_retained_finalizerFc               ó    € V ^8„  d   QhRRRR/# )r   Ú
keep_graphr<   r"   r   r#   )r$   s   "r%   r&   ÚCUDAGraph.__annotate__h  s   € ÷ ñ  ð °$ñ r'   c                	óZ  <€ \         SV `  W4      pR Vn        R Vn        R Vn        \        4       Vn        Wn        \        4       Vn	        \        4       Vn
        \        4       Vn        RVn        R Vn        \        4       Vn        \        4       Vn        R Vn        VP#                  4        V# )NF)ÚsuperÚ__new__rœ   rž   rŸ   rR   r    r¡   r   r¢   r£   r¤   r¥   r¦   r§   r¨   rª   Ú_arm_retained)Úclsr¬   ÚinstanceÚ	__class__s   && €r%   r°   ÚCUDAGraph.__new__h  s”   ø€ Ü‘7‘? 3Ó3ˆØ ˆÔØ%)ˆÔ"Ø%)ˆÔ"Ü&)£eˆÔ#Ø)Ôä(3«ˆÔ%Ü&1£mˆÔ#Ü+6«=ˆÔ(Ø',ˆÔ$Ø+/ˆÔ(Ü'2£}ˆÔ$Ü%0£]ˆÔ"Ø'+ˆÔ$Ø×ÑÔ Øˆr'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   {  s   € ÷ Wñ W˜tñ Wr'   c                	óê   a€ \        4       V n        \        P                  ! W P                  P                  4      V n        \        4       '       d$   V P                  oV P                  V3R  l4       R# R# )c                 ó   <€ \        S 4      # r|   )rš   )Úexec_idss   €r%   Ú<lambda>Ú)CUDAGraph._arm_retained.<locals>.<lambda>Œ  s   ø€ Ô3KÈHÔ3Ur'   N)	rK   r©   ÚweakrefÚfinalizerc   rª   r•   r    Úregister_destroy_callback)rW   r¹   s   &@r%   r±   ÚCUDAGraph._arm_retained{  sV   ø€ ô ,Ó-ˆŒÜ#*×#3Ò#3°D¿.¹.×:MÑ:MÓ#NˆÔ ô '×(Ò(Ø×.Ñ.ˆHØ×*Ñ*Ô+UÖVñ )r'   c               ó    € V ^8„  d   QhRRRR/# ©r   Úhookrt   r"   r   r#   )r$   s   "r%   r&   r­   Ž  s   € ÷ ñ Ø/ðà	ñr'   c                óf   € ^ RI Hp V! V P                  4      pWP                  VP                  &   V# )aÕ  Register ``hook(graph)`` to run when capture begins on this graph, right
after capture is under way on the current stream. Hooks fire in registration
order. Returns a handle whose ``remove()`` deregisters the hook.

.. warning::
    The hook runs inside the capture: any CUDA work it issues is captured into
    the graph, and under the default ``"global"`` capture error mode an unsafe
    call raises. See :func:`torch.cuda.graphs.register_graph_capture_start_hook`.
r   )rv   r   r¢   r4   ©rW   rÂ   r   rw   s   &&  r%   Úregister_capture_start_hookÚ%CUDAGraph.register_capture_start_hookŽ  s.   € õ 	6á  ×!:Ñ!:Ó;ˆØ/3×!Ñ! &§)¡)Ñ,Øˆr'   c               ó    € V ^8„  d   QhRRRR/# rÁ   r#   )r$   s   "r%   r&   r­      ó   € ÷ ñ Ø/ðà	ñr'   c                óf   € ^ RI Hp V! V P                  4      pWP                  VP                  &   V# )a+  Register ``hook(graph)`` to run when capture ends, after capture
completes but before the graph is finalized. The captured ``cudaGraph_t``
is live (via :meth:`raw_cuda_graph`) for both ``keep_graph`` modes. Hooks
fire in registration order. Returns a handle whose ``remove()``
deregisters the hook.
r   )rv   r   r£   r4   rÄ   s   &&  r%   Úregister_capture_end_hookÚ#CUDAGraph.register_capture_end_hook   s.   € õ 	6á  ×!8Ñ!8Ó9ˆØ-1×Ñ §	¡	Ñ*Øˆr'   c               ó    € V ^8„  d   QhRRRR/# rÁ   r#   )r$   s   "r%   r&   r­   ¯  rÈ   r'   c                óf   € ^ RI Hp V! V P                  4      pWP                  VP                  &   V# )a  Register ``hook(graph)`` to run after each instantiation (including
re-instantiation, which produces a fresh exec graph). The instantiated
graph is available via :meth:`raw_cuda_graph_exec`. Hooks fire in
registration order. Returns a handle whose ``remove()`` deregisters the
hook.
r   )rv   r   r¤   r4   rÄ   s   &&  r%   Úregister_post_instantiate_hookÚ(CUDAGraph.register_post_instantiate_hook¯  s.   € õ 	6á  ×!=Ñ!=Ó>ˆØ26×$Ñ$ V§Y¡YÑ/Øˆr'   c               ó    € V ^8„  d   QhRRRR/# rÁ   r#   )r$   s   "r%   r&   r­   ¾  s   € ÷ ñ Ø/ðà	ñr'   c                óf   € ^ RI Hp V! V P                  4      pWP                  VP                  &   V# )aÀ  Register ``hook(graph)`` to run at the start of every :meth:`replay`,
just before the graph is launched (after any on-demand instantiation, so
:meth:`raw_cuda_graph_exec` is valid). Hooks fire in registration order.
Returns a handle whose ``remove()`` deregisters the hook.

.. note::
    Replay is the hot path and a registered hook runs on every replay --
    keep it cheap. With no hook registered the cost is a single dict
    emptiness check.
r   )rv   r   r§   r4   rÄ   s   &&  r%   Úregister_replay_start_hookÚ$CUDAGraph.register_replay_start_hook¾  s.   € õ 	6á  ×!9Ñ!9Ó:ˆØ.2× Ñ  §¡Ñ+Øˆr'   c               ó    € V ^8„  d   QhRRRR/# rÁ   r#   )r$   s   "r%   r&   r­   Ñ  s   € ÷ ñ Ø/ðà	ñr'   c                óf   € ^ RI Hp V! V P                  4      pWP                  VP                  &   V# )a?  Register ``hook(graph)`` to run at the end of every :meth:`replay`,
just after the graph is launched. The launch is asynchronous, so the hook
runs once the replay is *enqueued*, not once the GPU work completes. Hooks
fire in registration order. Returns a handle whose ``remove()``
deregisters the hook. See the hot-path note on
:meth:`register_replay_start_hook`.

End hooks fire even if the launch raises -- so a start hook is always
balanced by an end -- and the launch error then propagates. (Start hooks
that raise abort the replay before launch, and no end hook fires.)
r   )rv   r   r¨   r4   rÄ   s   &&  r%   Úregister_replay_end_hookÚ"CUDAGraph.register_replay_end_hookÑ  s.   € õ 	6á  ×!7Ñ!7Ó8ˆØ,0×Ñ˜vŸy™yÑ)Øˆr'   Úsynchronize_before_releasec               ó$   € V ^8„  d   QhRRRRRR/# )r   rb   zCallable[[], None]rØ   r<   r"   r   r#   )r$   s   "r%   r&   r­   å  s(   € ÷ ñ àðð %)ð	ð
 
ñr'   c               óÀ   € ^ RI Hp V'       d   RV P                  n        V! V P                  P                  4      pWP                  P                  VP
                  &   V# )a¶  Register ``cb()`` to run when this graph is destroyed (finalized) or
explicitly :meth:`reset`, just before its CUDA resources are freed.
Callbacks fire once per capture cycle, in registration order; exceptions
are swallowed so one failure does not abort the rest. ``cb`` must NOT
reference this graph: the finalizer that fires it is held by a global
registry, so a callback reachable to the graph keeps the graph alive
until interpreter exit (it is never collected, hence never fired).
Returns a handle whose ``remove()`` deregisters the callback.

Teardown does not synchronize CUDA, and ``cudaGraphExecDestroy`` frees an
in-flight graph only asynchronously, so a callback that frees device
memory the graph reads/writes is a use-after-free if a replay is still
in flight. Pass ``synchronize_before_release=True`` to synchronize every
stream this graph was replayed on before firing. Otherwise callbacks
must not free anything the graph references.
r   T)rv   r   r©   rT   rP   r4   )rW   rb   rØ   r   rw   s   &&$  r%   r¾   Ú#CUDAGraph.register_destroy_callbackå  sE   € õ, 	6ç%Ø.2ˆD�N‰NÔ+Ù  §¡×!9Ñ!9Ó:ˆØ.0�‰× Ñ  §¡Ñ+Øˆr'   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úobjr!   rØ   r<   r"   r   r#   )r$   s   "r%   r&   r­     s(   € ÷ ñ àðð %)ð	ð
 
ñr'   c               óÀ   € ^ RI Hp V'       d   RV P                  n        V! V P                  P                  4      pWP                  P                  VP
                  &   V# )aê  Keep ``obj`` alive for this graph's current capture cycle and release
it when the graph is destroyed (finalized) or explicitly :meth:`reset`.
No callback runs; normal refcounting drops ``obj`` when the retained
reference is released. Returns a handle whose ``remove()`` drops the
retained reference early. As with :meth:`register_destroy_callback`,
``obj`` must NOT reference this graph, or the graph is kept alive until
interpreter exit and ``obj`` is never released.

``synchronize_before_release`` has the same meaning and caveats as in
:meth:`register_destroy_callback`: set it if releasing ``obj`` frees device
memory the graph reads/writes (e.g. ``obj`` is the last reference to a
tensor the graph uses) and replays may still be in flight.
r   T)rv   r   r©   rT   rQ   r4   )rW   rÝ   rØ   r   rw   s   &&$  r%   Úretain_objectÚCUDAGraph.retain_object  sE   € õ& 	6ç%Ø.2ˆD�N‰NÔ+Ù  §¡×!7Ñ!7Ó8ˆØ,/�‰×Ñ˜vŸy™yÑ)Øˆr'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­     s   € ÷ @ñ @¨$ñ @r'   c                	ó¬   € V P                   f   R # ^ RIHp V! V 4       V P                  e(   V P                  P                  V P                  4       R # R # )N)Úremap_to_exec_graph)rž   Útorch.cuda._graph_annotationsrã   rŸ   r    Úadd)rW   rã   s   & r%   Ú_maybe_remap_annotationsÚ"CUDAGraph._maybe_remap_annotations  sK   € ð ×!Ñ!Ò)ÙÝEá˜DÔ!ð ×!Ñ!Ò-Ø×#Ñ#×'Ñ'¨×(>Ñ(>Ö?ñ .r'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   0  s   € ÷ ñ ¨4ñ r'   c                	óX   € V P                   R uqn         Ve   VP                  4        R # R # r|   )rœ   Ústop)rW   Útrackers   & r%   Ú_release_python_resourcesÚ#CUDAGraph._release_python_resources0  s(   € ð "&§¡°Ðˆ”ØÒØ�L‰LŽNñ r'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   :  s   € ÷ ñ ˜ñ r'   c                	óL   €  V P                  4        R #   \         d     R # i ; ir|   )rì   r]   rV   s   &r%   Ú__del__ÚCUDAGraph.__del__:  s%   € ð	Ø×*Ñ*Ö,øÜô 	Úð	ús   ‚ ”#¢#c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r    r0   Úcapture_error_modeÚstrÚcheck_input_livenessr<   r"   rE   r#   )r$   s   "r%   r&   r­   @  s2   € ÷ 0ñ 0àð0ð  ð0ð #ð	0ð
 
ñ0r'   c                óž  <€ V P                   e"   V P                   P                  4        RV n         \        SV `  \	        V4      VR7       V'       d-   ^ RIHp V! 4       V n         V P                   P                  4        \        '       d   \        \        V 4       \        V P                  P                  4       4       F  pV! V 4       K  	  R# )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>`) or
        :class:`~torch.cuda.MemPool` 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>`_
    check_input_liveness (bool, optional):
        If ``True``, tracks external tensor inputs during graph capture and
        raises an error if any are deallocated before replay. This helps debug "use after free" errors
        where input tensors are garbage collected between capture and replay. Default: ``False``.

        .. note::
            Custom CUDA kernels added outside PyTorch (e.g., via cuLaunchKernel or DLPack) are not
            tracked by this mechanism.
N)r    ró   r   )rœ   rê   r¯   Úcapture_beginr5   Útorch.utils._cuda_debugr   Ústartrl   r}   r^   r¢   r_   )rW   r    ró   rõ   r   rÂ   r´   s   &&&&  €r%   r÷   ÚCUDAGraph.capture_begin@  s�   ø€ ð> �=‰=Ò$Ø�M‰M×ÑÔ Ø ˆDŒMÜ‰ÑÜ˜dÓ#Ð8Jð 	ô 	
÷  ÝNá:Ó<ˆDŒMØ�M‰M×ÑÔ!÷ 'Ó&ÜÔ9¸4Ô@Ü˜×2Ñ2×9Ñ9Ó;Ö<ˆDÙ�ŽJó =r'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   r  s   € ÷ "ñ " ñ "r'   c                ó$   <€ \         SV `  4        R# )zÁEnd capture but do not finalize: leaves the captured ``cudaGraph_t``
live (for both ``keep_graph`` modes) so it can be inspected before
:meth:`capture_end_post` instantiates and/or destroys it.N)r¯   Úcapture_end_pre©rW   r´   s   &€r%   rý   ÚCUDAGraph.capture_end_prer  s   ø€ ô 	‰ÑÖ!r'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   x  s   € ÷ !ñ ! $ñ !r'   c                óx   <€ \         SV `  4        V P                  e   V P                  P                  4        R# R# )zÂFinalize a capture started by :meth:`capture_end_pre`: destroy the
template when ``keep_graph=False`` (the graph must already be
instantiated; :meth:`capture_end` and the context manager do so).N)r¯   Úcapture_end_postrœ   rê   rþ   s   &€r%   r  ÚCUDAGraph.capture_end_postx  s/   ø€ ô 	‰Ñ Ô"Ø�=‰=Ò$Ø�M‰M×ÑÖ ñ %r'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   €  s   € ÷  ñ  ˜Tñ  r'   c                óB  € V P                  4        ^ RIHp V! V 4       \        '       d   \	        \        V 4       \        V P                  P                  4       4       F  pV! V 4       K  	  V P                  '       g   V P                  4        V P                  4        R# )a  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.
)Úmaybe_stamp_capture_graph_idN)rý   rä   r  rm   r}   r^   r£   r_   r¡   Úinstantiater  )rW   r  rÂ   s   &  r%   Úcapture_endÚCUDAGraph.capture_end€  sz   € ð 	×ÑÔõ 	Oá$ TÔ*ß$Ó$ÜÔ7¸Ô>Ü˜×0Ñ0×7Ñ7Ó9Ö:ˆDÙ�ŽJñ ;à××Ðð ×ÑÔØ×ÑÖr'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   œ  s   € ÷ 0ñ 0˜Tñ 0r'   c                ó2  <€ \         SV `  4        V P                  4        RV n         \        '       d   \        \        V 4       \        V P                  P                  4       4       F  pV! V 4       K  	  RV n        RV n	        R#   RT n        RT n	        i ; i)zü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``.
TFN)
r¯   r  ræ   r¥   rn   r}   r^   r¤   r_   r¦   ©rW   rÂ   r´   s   & €r%   r  ÚCUDAGraph.instantiateœ  sˆ   ø€ ô 	‰ÑÔØ×%Ñ%Ô'ð
 $(ˆÔ ð	0ß(Ó(Ü!Ô";¸TÔBÜ˜T×9Ñ9×@Ñ@ÓBÖC�Ù�T–
ñ Dð (-ˆDÔ$Ø+/ˆDÖ(øð (-ˆDÔ$Ø+/ˆDÕ(ús   ¨B ´AB ÂBc               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   ³  s   € ÷ ñ ˜ñ r'   c                óâ  <€ V P                   e*   V P                   P                  V P                  4       4       V P                  P                  '       dB   V P                  P
                  P                  \        P                  P                  4       4       V P                  '       g   V P                  4        \        '       d   \        \        V 4       V P                  '       d3   \        V P                  P!                  4       4       F  pV! V 4       K  	   \"        SV `I  4        \&        '       d   \        \&        V 4       V P(                  '       d5   \        V P(                  P!                  4       4       F  pV! V 4       K  	  R# R#   \&        '       d   \        \&        T 4       T P(                  '       d4   \        T P(                  P!                  4       4       F  pT! T 4       K  	  i i ; i)z,Replay the CUDA work captured by this graph.N)rœ   Úcheck_aliveÚpoolsr©   rT   rS   rå   r*   r+   Úcurrent_streamr�   r  ro   r}   r§   r^   r_   r¯   Úreplayrp   r¨   r  s   & €r%   r  ÚCUDAGraph.replay³  s\  ø€ à�=‰=Ò$Ø�M‰M×%Ñ% d§j¡j£lÔ3Ø�>‰>×*×*Ð*ð �N‰N×)Ñ)×-Ñ-¬e¯j©j×.GÑ.GÓ.IÔJð ×#×#Ð#Ø×ÑÔß%Ó%ÜÔ8¸$Ô?Ø×#×#Ð#Ü˜T×5Ñ5×<Ñ<Ó>Ö?�Ù�T–
ñ @ð	Ü‰G‰NÔç'Ó'Ü!Ô":¸DÔAØ×%×%Ð%Ü  ×!7Ñ!7×!>Ñ!>Ó!@ÖA�DÙ˜–Jó Bñ &ø÷ (Ó'Ü!Ô":¸DÔAØ×%×%Ð%Ü  ×!7Ñ!7×!>Ñ!>Ó!@ÖA�DÙ˜–Jò Bð &ús   ÄF Æ.G.Æ:4G.c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   Ï  s   € ÷ ñ �tñ r'   c                ó"  <€ V P                  4        V P                  P                  4        V P                  e   V P                  P	                  4        \        4       V n        V P                  4        RV n        RV n	        \        SV `-  4        R# )z1Delete the graph currently held by this instance.N)rì   r©   rc   rª   ÚdetachrR   r    r±   rž   rŸ   r¯   Úresetrþ   s   &€r%   r  ÚCUDAGraph.resetÏ  sr   ø€ à×&Ñ&Ô(ð 	�‰×ÑÔØ×#Ñ#Ò/Ø×$Ñ$×+Ñ+Ô-ô #&£%ˆÔØ×ÑÔð "&ˆÔØ!%ˆÔÜ‰‰Žr'   c               ó   € V ^8„  d   QhRR/# r@   r#   )r$   s   "r%   r&   r­   ä  s   € ÷ 7ñ 7�lñ 7r'   c                óZ   <€ \         P                  P                  \        SV `  4       4      # )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+   r   r¯   r    rþ   s   &€r%   r    ÚCUDAGraph.poolä  s    ø€ ô �z‰z×&Ñ&¤u¡w¡|£~Ó6Ð6r'   c               ó   € V ^8„  d   QhRR/# )r   r"   zlist[_POOL_HANDLE]r#   )r$   s   "r%   r&   r­   ì  s   € ÷ Kñ KÐ)ñ Kr'   c                ó„   <€ \         SV `  4        Uu. uF"  p\        P                  P	                  V4      NK$  	  up# u upi )zAReturn opaque tokens for all memory pools retained by this graph.)r¯   r  r*   r+   r   )rW   r    r´   s   & €r%   r  ÚCUDAGraph.poolsì  s0   ø€ ä:?¹'¹-¼/ÓJ¹/°$”—
‘
×'Ñ'¨Ö-¹/ÑJÐJùÒJs   ’(=c               ó    € V ^8„  d   QhRRRR/# )r   r    r   r"   rE   r#   )r$   s   "r%   r&   r­   ð  s   € ÷ -ñ - ð -°ñ -r'   c                	óV   <€ \        V4      pVf   \        R4      h\        SV `  V4      # )Nz-CUDAGraph._retain_pool expected a memory pool)r5   rH   r¯   Ú_retain_pool)rW   r    Úpool_idr´   s   && €r%   r"  ÚCUDAGraph._retain_poolð  s.   ø€ Ü˜tÓ$ˆØŠ?ÜÐNÓOÐOÜ‰wÑ# GÓ,Ð,r'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   r­   ö  s   € ÷  ñ   4ñ  r'   c                ó2   <€ \         SV `  4        RV n        R# )z“Retain the captured graph (equivalent to ``keep_graph=True``) so it
can be inspected, e.g. via :meth:`debug_dump`. Kept for backward
compatibility.TN)r¯   Úenable_debug_moder¡   rþ   s   &€r%   r'  ÚCUDAGraph.enable_debug_modeö  s   ø€ ô 	‰Ñ!Ô#àˆÖr'   ÚverboseTc               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú
debug_pathrô   r)  r<   r"   rE   r#   )r$   s   "r%   r&   r­   þ  s!   € ÷ ;ñ ; Sð ;°dð ;Àdñ ;r'   c               ó    € \        WVR7       R# )al  Dump the captured graph to ``debug_path`` in Graphviz DOT format.

The graph's template must be live: ``keep_graph=True`` (or
:meth:`enable_debug_mode`), or called from a capture-end hook. Requires
the ``cuda.bindings`` package.

Arguments:
    debug_path (required): Path to dump the graph to.
    verbose: If ``True`` (default), use the most verbose DOT output.
©r)  N©Ú_dump_graph_dot)rW   r+  r)  s   &&$r%   Ú
debug_dumpÚCUDAGraph.debug_dumpþ  s   € ô 	˜°'×:r'   c               ó   € V ^8„  d   QhRR/# ©r   r"   Úintr#   )r$   s   "r%   r&   r­     s   € ÷ (ñ ( ñ (r'   c                ó    <€ \         SV `  4       # )a  Returns the underlying cudaGraph_t. The template must be live: this
requires ``keep_graph=True`` (it persists after ``capture_end``), or
access from within a capture-end hook (before the template is destroyed
for ``keep_graph=False``).

See the following for APIs for how to manipulate this object: `Graph Management <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_graphrþ   s   &€r%   r6  ÚCUDAGraph.raw_cuda_graph  s   ø€ ô ‰wÑ%Ó'Ð'r'   c               ó   € V ^8„  d   QhRR/# r3  r#   )r$   s   "r%   r&   r­     s   € ÷ -ñ - Sñ -r'   c                ó    <€ \         SV `  4       # )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_execrþ   s   &€r%   r:  ÚCUDAGraph.raw_cuda_graph_exec  s   ø€ ô
 ‰wÑ*Ó,Ð,r'   c               ó   € V ^8„  d   QhRR/# )r   r"   Údictr#   )r$   s   "r%   r&   r­     s   € ÷ Xñ X ñ Xr'   c                ó’  € V P                   e   V P                   # ^ RIHp \        4        \        e	   \
        f   \        R4      hV! 4       '       d   \        R4      h\        P                  P                  R\        P                  P                  R\        P                  P                  R\        P                  P                  R\        P                  P                  R	\        P                  P                  R
\        P                  P                  R\        P                  P                   R\        P                  P"                  R\        P                  P$                  R\        P                  P&                  R/p\        P                  P                  \        P                  P&                  0p\)        4       pV P+                  4       p\-        \        P.                  ! V^ R7      4      w  rg\-        \        P.                  ! WWR7      4      w  r‡/ p	. p
\1        V4       EFù  pW‹,          pW¹\3        V4      &   \-        \        P4                  ! V4      4      pWÓ9   d!   VP7                  VP9                  WÝ4      4       \-        \        P:                  ! V4      4      pV^ ,	          pVR,          pRpV\        P                  P                  8X  dþ   \
        P<                  ! \3        V4      R7      p\
        P>                  ! V4      w  ppV\
        P@                  PB                  8X  d¦   \3        VPD                  4      '       d‹   \
        PF                  ! \3        VPD                  4      R7      p\
        PH                  ! V4      w  ppV\
        P@                  PB                  8X  d)   \K        V\L        4      '       d   VPO                  4       MTp^ pV\        P                  P                   8X  d*   \3        \-        \        PP                  ! V4      4      4      pMGV\        P                  P                  8X  d)   \3        \-        \        PR                  ! V4      4      4      p^ pRpV\        P                  P                  8X  dY   \        PT                  ! V4      w  ppV\        PV                  PX                  8X  d!   \3        VPZ                  4      p\]        V4      pV
P_                  RVRVP9                  V\a        V4      4      RVRVRVRVRVRVRVR. R. /4       EKü  	  \-        \        Pb                  ! V^ R7      4      w    ppV^ 8”  dÅ   \-        \        Pb                  ! VVR7      4      w  pppp\1        V4       F�  pV	P9                  \3        VV,          4      4      pV	P9                  \3        VV,          4      4      pVf   KK  Vf   KQ  V
V,          R,          P_                  V4       V
V,          R,          P_                  V4       K‘  	  \        Pd                  ! V Pg                  4       R7      p \-        \        Ph                  ! V 4      4      p!V
 F"  p"V!^ ,          V"R,          ,          V"R&   V!V"R&   K$  	  V'       d&   \j        Pl                  ! R\o        V4       R 2^R!7       R"V!R#V
/p#V Pp                  '       d   V#V n         V## )$a–  Return a dictionary describing the graph's topology and node metadata.

``keep_graph`` must be True.  The graph must have been instantiated
(via :meth:`instantiate`) before calling this method.
Requires the ``cuda.bindings`` package.

Returns a dictionary with structure::

    {
        "exec_graph_id": int,
        "nodes": [
            {
                "index": int,
                "node_type": str,
                "tools_id": int,
                "graph_id": int,
                "node_id": int,
                "kernel_name": str or None,
                "event_ptr": int,
                "host_fn_addr": int,
                "host_fn_name": str or None,
                "dependencies": [int, ...],
                "dependents": [int, ...],
            },
            ...,
        ],
    }

``event_ptr`` is the ``cudaEvent_t`` handle (as an int) an event-record
or event-wait node records / waits on -- these nodes produce no timed
CUPTI record, so matching a wait to the record that signals it is the
only way to reason about the cross-stream sync it encodes. It is ``0``
for other node types.

``host_fn_addr`` / ``host_fn_name`` are populated for host nodes (a CPU
callback run as a graph node): the callback address and a best-effort
demangled symbol name for it (``None`` when it resolves to no exported
symbol). They are ``0`` / ``None`` for other node types.

Each node's ``graph_id`` is remapped to the exec graph id so that
``tools_id`` values match those reported by CUPTI-based profilers.
``dependencies`` and ``dependents`` are lists of node indices within
the ``nodes`` list.

This structure is useful for inspecting a profiler trace and
establishing whether a particular dependency observed in the profile
is a true dependency (encoded in the graph) or a fake dependency
caused by mapping of independent streams to the same hardware
channel.

Child-graph and conditional nodes are reported as nodes in their own
right, but this walk does not descend into their bodies (those are
separate ``cudaGraph_t`` objects), so the work inside them is absent
from ``nodes`` and a warning is issued. The ids that *are* reported
stay valid: the exec graph preserves top-level node ids.
N)Ú_is_tools_id_unavailablez6expected _cuda_runtime and _cuda_driver to be not Nonez•get_graph_data requires cudaGraphNodeGetToolsId which needs cuda.bindings >= 13.1 and CUDA driver >= 13.1 (or cuda-compat >= 13.1 in LD_LIBRARY_PATH)ÚkernelÚmemcpyÚmemsetÚhostÚchild_graphÚemptyÚ
wait_eventÚevent_recordÚ	mem_allocÚmem_freeÚconditional)ÚnumNodesl   ÿÿ )Ú
init_valueÚindexÚ	node_typeÚtools_idÚgraph_idÚnode_idÚkernel_nameÚ	event_ptrÚhost_fn_addrÚhost_fn_nameÚdependenciesÚ
dependents)ÚnumEdgesz$get_graph_data: this graph contains z‡ nodes; the work inside them is in a separate cudaGraph_t that this walk does not descend into, so it is absent from the returned nodes)Ú
stacklevelÚexec_graph_idÚnodes)9r¦   rä   r?  rI   rG   Ú_cuda_driverÚAssertionErrorrH   ÚcudaGraphNodeTypeÚcudaGraphNodeTypeKernelÚcudaGraphNodeTypeMemcpyÚcudaGraphNodeTypeMemsetÚcudaGraphNodeTypeHostÚcudaGraphNodeTypeGraphÚcudaGraphNodeTypeEmptyÚcudaGraphNodeTypeWaitEventÚcudaGraphNodeTypeEventRecordÚcudaGraphNodeTypeMemAllocÚcudaGraphNodeTypeMemFreeÚcudaGraphNodeTypeConditionalrR   r6  r   ÚcudaGraphGetNodesÚranger4  ÚcudaGraphNodeGetTyperå   ÚgetÚcudaGraphNodeGetToolsIdÚCUgraphNodeÚcuGraphKernelNodeGetParamsÚCUresultÚCUDA_SUCCESSÚfuncÚ
CUfunctionÚcuFuncGetNamer,   ÚbytesÚdecodeÚ cudaGraphEventRecordNodeGetEventÚcudaGraphEventWaitNodeGetEventÚcudaGraphHostNodeGetParamsÚcudaError_tÚcudaSuccessrs   Ú_resolve_host_fn_nameÚappendrô   ÚcudaGraphGetEdgesÚcudaGraphExec_tr:  ÚcudaGraphExecGetIdÚwarningsÚwarnÚsortedr¥   )$rW   r?  Únode_type_namesÚnested_graph_typesÚnested_node_typesÚrawÚ_Únumr[  Úhandle_to_idxÚ
node_infosÚiÚnodeÚntyperO  rP  rQ  rR  Úcu_nodeÚerrÚparamsÚcu_funcÚnamerS  rT  rU  Ú	num_edgesÚ
from_nodesÚto_nodesÚ
_edge_dataÚsrcÚdstÚexec_handlerZ  ÚinfoÚdatas$   &                                   r%   Úget_graph_dataÚCUDAGraph.get_graph_data  s�  € ðt ×'Ñ'Ò3Ø×/Ñ/Ð/ÝJäÔ äÒ ¤LÒ$8Ü ØHóð ñ $×%Ò%Üð>óð ô ×+Ñ+×CÑCÀXÜ×+Ñ+×CÑCÀXÜ×+Ñ+×CÑCÀXÜ×+Ñ+×AÑAÀ6Ü×+Ñ+×BÑBÀMÜ×+Ñ+×BÑBÀGÜ×+Ñ+×FÑFÈÜ×+Ñ+×HÑHÈ.Ü×+Ñ+×EÑEÀ{Ü×+Ñ+×DÑDÀjÜ×+Ñ+×HÑHÈ-ð
ˆô ×+Ñ+×BÑBÜ×+Ñ+×HÑHð
Ðô '*£eÐà×!Ñ!Ó#ˆä%¤m×&EÒ&EÀcÐTUÔ&VÓW‰ˆÜ)Ü×+Ò+¨CÔ>ó
‰
ˆð )+ˆØ!#ˆ
ä�s—ˆAØ•8ˆDØ'(œ#˜d›)Ñ$ä(¬×)KÒ)KÈDÓ)QÓRˆEØÔ*Ø!×%Ñ% o×&9Ñ&9¸%Ó&GÔHÜ+¬M×,QÒ,QÐRVÓ,WÓXˆHØ 2•~ˆHØ Õ+ˆGàˆKØœ×7Ñ7×OÑOÔOÜ&×2Ò2¼cÀ$»iÔH�Ü*×EÒEÀgÓN‘��VØœ,×/Ñ/×<Ñ<Ô<ÄÀVÇ[Á[×AQÒAQÜ*×5Ò5ÄÀVÇ[Á[ÓAQÔR�GÜ ,× :Ò :¸7Ó C‘I�C˜Øœl×3Ñ3×@Ñ@Ô@Ü7AÀ$Ì×7NÒ7N d§k¡k¤mÐTX˜ð ˆIØœ×7Ñ7×TÑTÔTÜÜ(Ü%×FÒFÀtÓLóó‘	ð
 œ-×9Ñ9×TÑTÔTÜÜ(Ü%×DÒDÀTÓJóó�	ð ˆLØˆLØœ×7Ñ7×MÑMÔMÜ+×FÒFÀtÓL‘��VØœ-×3Ñ3×?Ñ?Ô?Ü#& v§y¡y£>�LÜ#8¸Ó#F�Là×Ñà˜QØ ×!4Ñ!4°U¼CÀ»JÓ!GØ Ø Ø˜wØ! ;Ø Ø" LØ" LØ" BØ  "ð÷ñi ôH 2Ü×+Ò+¨C¸!Ô<ó
Ñˆˆ1ˆa�ð �qŒ=Ü:NÜ×/Ò/°¸iÔHó;Ñ7ˆJ˜ *¨iô ˜9Ö%�Ø#×'Ñ'¬¨J°q­MÓ(:Ó;�Ø#×'Ñ'¬¨H°Q­KÓ(8Ó9�Ø”? s¤Ø˜s•O LÕ1×8Ñ8¸Ô=Ø˜s•O NÕ3×:Ñ:¸3Ö?ñ &ô $×3Ò3Ø×/Ñ/Ó1ô
ˆô -Ü×,Ò,¨[Ó9ó
ˆó ˆDØ -°Õ 3°t¸IµÕFˆD�ÑØ,ˆD�Óñ ÷ ô
 �MŠMØ6´vÐ>OÓ7PÐ6Qð RVð Vð õ	ð ˜]Ø�Zð
ˆð ×#×#Ð#Ø+/ˆDÔ(Øˆr'   )	r¥   rž   r¦   r¡   r    rŸ   r©   rª   rœ   )F)NÚglobalF)#re   rf   rg   rh   ri   Ú__annotations__r°   r±   rÅ   rÊ   rÎ   rÒ   rÖ   r¾   rß   ræ   rì   rð   r÷   rý   r  r  r  r  r  r    r  r"  r'  r0  r6  r:  rž  rj   Ú__classcell__)r´   s   @r%   r   r   (  sb  ø‡ ñð4 4Ó3ð Óð "Ó!ð "Ó!ð !Ó ØÓà@Ó@Ø>Ó>ØCÓCð ÓØ(Ó(ð @Ó?Ø=Ó=ð "Ó!Ø0Ó0÷ò õ&Wõ&õ$õõõ&ð(ð ,1÷	ð<ð ,1÷	õ6@õ$õ÷0ò 0÷d"ð "÷!ð !õ ÷80ð 0÷.ð ÷8ð ÷*7ð 7÷Kð K÷-ð -÷ ð  ð;¸T÷ ;÷(ð (÷-ð -÷Xó Xr'   c                  ó‚   € ] tR tRtR]P
                  3R]P                  3R]P
                  3R]P                  3.tRtR# )Ú_DlInfoi÷  Ú	dli_fnameÚ	dli_fbaseÚ	dli_snameÚ	dli_saddrr#   N)	re   rf   rg   rh   ÚctypesÚc_char_pÚc_void_pÚ_fields_rj   r#   r'   r%   r¤  r¤  ÷  s9   † à	�f—o‘oÐ&Ø	�f—o‘oÐ&Ø	�f—o‘oÐ&Ø	�f—o‘oÐ&ð	„Hr'   r¤  c               ó    € V ^8„  d   QhRRRR/# )r   Úaddrr4  r"   z
str | Noner#   )r$   s   "r%   r&   r&      s   € ÷ 7ñ 7 ð 7¨
ñ 7r'   c                ól  € V '       g   R# \        4       p\        P                  ! R4      P                  \        P                  ! V 4      \        P
                  ! V4      4      '       g   R# VP                  '       g   R# \        P                  P                  VP                  P                  4       4      # )zöBest-effort symbol name for a host-node callback address via dladdr + demangle.
Returns None when the address resolves to no exported symbol (e.g. an anonymous
trampoline). Host nodes carry no name in the CUPTI record, so this is the only source.N)r¤  r©  ÚCDLLÚdladdrr«  Úbyrefr§  r*   Ú_CÚ	_demanglerw  )r®  rœ  s   & r%   r}  r}     sp   € ÷ ÙÜ‹9€DÜ�;Š;�tÓ×#Ñ#¤F§O¢O°DÓ$9¼6¿<º<ÈÓ;M×NÒNÙØ�>�>ˆ>ÙÜ�8‰8×Ñ˜dŸn™n×3Ñ3Ó5Ó6Ð6r'   r)  Tc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   Ú
cuda_graphr   Úpathrô   r)  r<   r"   rE   r#   )r$   s   "r%   r&   r&     s)   € ÷ ñ  	ð °ð À$ð ÐRVñ r'   c               óÜ   € \        4        V'       d   \        P                  P                  M^ p\	        \        P
                  ! V P                  4       VP                  4       V4      4       R# )zCWrite ``cuda_graph``'s template to ``path`` in Graphviz DOT format.N)rI   rG   ÚcudaGraphDebugDotFlagsÚcudaGraphDebugDotFlagsVerboser   ÚcudaGraphDebugDotPrintr6  Úencode)r¶  r·  r)  Úflagss   &&$ r%   r/  r/    sT   € äÔ÷ ô 	×,Ñ,×JÒJàð 
ô
 Ü×,Ò,Ø×%Ñ%Ó'¨¯©«¸ó	
ör'   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r·  rô   r)  r<   r"   rt   r#   )r$   s   "r%   r&   r&     s"   € ÷ 	ñ 	�Sð 	 dð 	Ð6Qñ 	r'   c               ó   a a€ R V V3R llpV# )zíReturn a capture-end hook that dumps the captured graph to ``path`` in
Graphviz DOT format. Register it with
:meth:`CUDAGraph.register_capture_end_hook`; works for both ``keep_graph``
modes since it runs while the template is still live.c               ó    € V ^8„  d   QhRRRR/# ©r   r¶  r   r"   rE   r#   )r$   s   "r%   r&   Ú export_dot.<locals>.__annotate__#  s   € ÷ ;ñ ;˜)ð ;¨ñ ;r'   c                ó$   <€ \        V SSR 7       R# )r-  Nr.  )r¶  r·  r)  s   &€€r%   Ú_hookÚexport_dot.<locals>._hook#  s   ø€ Ü˜
 D°'×:r'   r#   )r·  r)  rÄ  s   fd r%   Ú
export_dotrÆ    s   ù€ ÷;ñ ;ð €Lr'   c               ó    € V ^8„  d   QhRRRR/# )r   r·  rô   r"   rt   r#   )r$   s   "r%   r&   r&   )  s   € ÷ ñ ˜Cð Ð$?ñ r'   c                ó   a € R V 3R llpV# )a]  Return a post-instantiate hook that pickles :meth:`CUDAGraph.get_graph_data`
to ``path``. Register it with :meth:`CUDAGraph.register_post_instantiate_hook`:
``get_graph_data`` needs the graph instantiated (it remaps node ids to the
exec graph id), and at post-instantiate time the template is still live, so
this works for both ``keep_graph`` modes.c               ó    € V ^8„  d   QhRRRR/# rÁ  r#   )r$   s   "r%   r&   Ú'export_graph_data.<locals>.__annotate__0  s   € ÷ 8ñ 8˜)ð 8¨ñ 8r'   c                ó²   <€ ^ RI p\        SR4      ;_uu_ 4       pVP                  V P                  4       V4       RRR4       R#   + '       g   i     R# ; i)r   NÚwb)ÚpickleÚopenÚdumprž  )r¶  rÍ  Úfr·  s   &  €r%   rÄ  Ú export_graph_data.<locals>._hook0  s;   ø€ Ûä�$˜×Ô Ø�K‰K˜
×1Ñ1Ó3°QÔ7÷ ××Òús   š!AÁA	r#   )r·  rÄ  s   f r%   Úexport_graph_datarÒ  )  s   ø€ ÷8ð 8ð €Lr'   c                  óR   € ] tR tRt$ RtRtR]R&   RR R lltR R	 ltR
 R lt	Rt
R# )r   i9  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>`) or
        :class:`~torch.cuda.MemPool` 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>`_
    enable_annotations (bool, optional): If ``True``, enables kernel annotation
        recording on entry and automatically calls
        :func:`~torch.cuda._graph_annotations.resolve_pending_annotations` before
        the capture ends.  Annotations are **not** cleared on exit so that multiple
        graphs in the same workload can accumulate annotations.
        Requires ``cuda.bindings`` package and cuda-compat >= 13.1 or CUDA driver >= 13.1.
    check_input_liveness (bool, optional): If ``True``, tracks external tensor inputs during graph capture and
        raises an error if any are deallocated before replay. This helps debug "use after free" errors
        where input tensors are garbage collected between capture and replay. Default: ``False``.

        .. note::
            Custom CUDA kernels added outside PyTorch (e.g., via cuLaunchKernel or DLPack) are not
            tracked by this mechanism.

.. 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               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR
/# )r   r¶  r   r    r0   ra   rÔ  ró   rô   Úenable_annotationsr<   rõ   r#   )r$   s   "r%   r&   Úgraph.__annotate__g  sF   € ÷ 9ñ 9àð9ð  ð9ð )ð	9ð
  ð9ð !ð9ð #ñ9r'   c                	óÊ  € VfF   V P                   P                  f.   \        P                  P	                  4       V P                   n        \        V4      pVf   RMV3V n        Ve   TMV P                   P                  V n        V P                  f   \        R4      h\        P                  P                  V P                  4      V n
        Wn        W@n        WPn        W`n        R # )Nzcapture_stream must not be Noner#   )r´   rÕ  r*   r+   ÚStreamr5   r    Úcapture_streamr]  ra   Ú
stream_ctxr¶  ró   Ú_enable_annotationsrõ   )rW   r¶  r    ra   ró   r×  rõ   r#  s   &&&&&&& r%   rX   Úgraph.__init__g  s¸   € ð Š>˜dŸn™n×CÑCÒKÜ49·J±J×4EÑ4EÓ4GˆD�N‰NÔ1ä˜tÓ$ˆà’/‰B¨ zð 	Œ	ð Ò(‰F¨d¯n©n×.SÑ.Sð 	Ôð ×ÑÒ&Ü Ð!BÓCÐCÜŸ*™*×+Ñ+¨D×,?Ñ,?Ó@ˆŒØ$ŒØ"4ÔØ#5Ô Ø$8Ö!r'   c               ó   € V ^8„  d   QhRR/# rD   r#   )r$   s   "r%   r&   rØ  …  s   € ÷ &>ñ &>˜4ñ &>r'   c                	óh  € \         P                  P                  4        \         P                  P                  P
                  '       d   \        P                  ! 4        \         P                  P                  4        \         P                  P                  4        ^ RIHp V! V P                  4       V P                  P                  4        V P                   P"                  ! V P$                  RV P&                  RV P(                  /  ^ RIHp V! \         P                  P-                  4       4       R# )r   )Ú_set_annotations_enabledró   rõ   )Úmaybe_stamp_capture_rootN)r*   r+   r\   ÚcompilerÚconfigÚforce_cudagraph_gcÚgcÚcollectÚempty_cacher³  Ú_host_emptyCacherä   rá  rÝ  rÜ  Ú	__enter__r¶  r÷   r    ró   rõ   râ  r  )rW   rá  râ  s   &  r%   rê  Úgraph.__enter__…  sÍ   € ä�
‰
×ÑÔ ä�>‰>× Ñ ×3×3Ð3ô �JŠJŒLä�
‰
×ÑÔ ä�‰×!Ñ!Ô#õ 	Ká  ×!9Ñ!9Ô:ð 	�‰×!Ñ!Ô#à�‰×%Ò%à�Y‰Yð	
ð  $×6Ñ6ð		
ð "&×!:Ñ!:ò	
õ 	Ká ¤§¡×!:Ñ!:Ó!<Ö=r'   c               ó    € V ^8„  d   QhRRRR/# )r   Úargsr!   r"   rE   r#   )r$   s   "r%   r&   rØ  ­  s   € ÷ ,ñ ,˜fð ,¨ñ ,r'   c                	óÜ   € ^ RI HpHp  V P                  '       d   V! 4        V P                  P                  4        V P                  P                  ! V!   V! R4       R#   T! R4       i ; i)r   )rá  Úresolve_pending_annotationsFN)rä   rá  rï  rÝ  r¶  r  rÜ  Ú__exit__)rW   rí  rá  rï  s   &*  r%   rð  Úgraph.__exit__­  sV   € ÷	
ð
	,Ø×'×'Ð'Ù+Ô-ð
 �O‰O×'Ñ'Ô)Ø�O‰O×$Ò$ dÒ+ñ % UÖ+øÑ$ UÕ+ús   ŠA! œ;A! Á!
A+)rÝ  ró   rÛ  rõ   r¶  r    rÜ  )NNr   FF)re   rf   rg   rh   ri   rÕ  r¡  rX   rê  rð  rj   r#   r'   r%   r   r   9  s+   ‡ ñ)ðV 8<ÐÐ4Ó;÷9õ<&>÷P,ñ ,r'   útorch.nn.Module.Ú_ModuleOrCallablec               ó8   € V ^8„  d   QhRRRRRRRRR	R
RRRRRR/# )r   Ú	callablesró  Úsample_argsútuple[Tensor, ...]Únum_warmup_itersr4  Úallow_unused_inputr<   r    r0   ró   rô   r×  r"   r#   )r$   s   "r%   r&   r&   Æ  sX   € ÷ ñ Ø ðà#ðð ðð ð	ð
 ðð ðð ðð ñr'   c                ó   € R # r|   r#   ©rõ  rö  rø  rù  r    ró   r×  s   &&&&&&&r%   Úmake_graphed_callablesrü  Å  s   € ñ r'   c               ó8   € V ^8„  d   QhRRRRRRRRR	R
RRRRRR/# )r   rõ  ztuple[_ModuleOrCallable, ...]rö  ztuple[tuple[Tensor, ...], ...]rø  r4  rù  r<   r    r0   ró   rô   r×  r"   r#   )r$   s   "r%   r&   r&   Ò  sX   € ÷ (ñ (Ø,ð(à/ð(ð ð(ð ð	(ð
 ð(ð ð(ð ð(ð #ñ(r'   c                ó   € R # r|   r#   rû  s   &&&&&&&r%   rü  rü  Ñ  s   € ñ %(r'   c               ó8   € V ^8„  d   QhRRRRRRRRR	R
RRRRRR/# )r   rõ  z1_ModuleOrCallable | tuple[_ModuleOrCallable, ...]rö  z3tuple[Tensor, ...] | tuple[tuple[Tensor, ...], ...]rø  r4  rù  r<   r    r0   ró   rô   r×  r"   r#   )r$   s   "r%   r&   r&   Ý  sb   € ÷ añ aØ@ðaàDðað ðað ð	að
 ðað ðað ðað 7ñar'   c                ó6  € \         P                  ! 4       '       d'   \         P                  ! 4       '       d   \        R4      hRp\	        V \
        4      '       g0   RpV 3p \        P                  ! \
        \        R3,          V4      3pM5\        P                  ! \
        \
        \        R3,          R3,          V4      p. p	\        W4       EFq  w  r«\	        V
\         P                  P                  4      '       d»   \        V
P                  4      ^ 8X  d5   \        V
P                  4      ^ 8X  d   \        V
P                  4      ^ 8X  g   \!        R4      h\"        ;QJ d*    R V
P%                  4        4       F  '       d   K   RM	  RM! R V
P%                  4        4       4      '       g   \!        R4      h\         P&                  P(                  P*                  ! V!  pV	P-                  \        V4      4       \"        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d   EKi  \!        R4      h	  V	 Uu. uF  p\        V4      NK  	  ppV  U
u. uFH  p
\	        V
\         P                  P                  4      '       d   \        V
P/                  4       4      MRNKJ  	  pp
\1        \        V 4      4       Uu. uF  pWŸ,          Wï,          ,           NK  	  pp\1        \        V 4      4       Uu. uF!  p\         P2                  P5                  4       NK#  	  pp\1        \        V 4      4       Uu. uF!  p\         P2                  P5                  4       NK#  	  ppVf   \7        4       M
\9        V4      p\         P2                  P;                  4        \         P2                  P=                  4       p\         P2                  P?                  V4      ;_uu_ 4        \        WV4       EF  w  pppRRRppp\1        V4       Fæ  p\         P&                  P(                  PA                  V! V!  4      p\
        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      p\        V4      ^ 8”  g   Kn  \         PB                  PE                  T\
        ;QJ d    . R	 V 4       F  NK  	  5M! R	 V 4       4      \
        ;QJ d    . R
 V 4       F  NK  	  5M! R
 V 4       4      RVR7      pKè  	  VVV3 F  p?K  	  EK  	  RRR4       \         P2                  P;                  4        . p. p\        WV4       F™  w  ppp\         P2                  PG                  VVVVVR7      ;_uu_ 4        V! V!  pRRR4       \         P&                  P(                  PI                  X4      w  p p!VP-                  \        V 4      4       VP-                  V!4       K›  	  . p". p#\        \K        V4      \K        V4      \K        V4      4       EF£  w  pp$p%\
        ;QJ d    . R V$ 4       F  NK  	  5M! R V$ 4       4      p&\
        ;QJ d    . R V$ 4       F  NK  	  5M! R V$ 4       4      pRp\        V4      ^ 8”  d®   \         P2                  PG                  V%VVVVR7      ;_uu_ 4        \         PB                  PE                  T\
        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      \
        ;QJ d    . R V& 4       F  NK  	  5M! R V& 4       4      RVR7      pRRR4       . p'^ p(V FM  p)V)PL                  '       d(   Ve$   V'P-                  VV(,          4       V(^,          p(K<  V'P-                  R4       KO  	  \        V'4      p'V"P-                  V&4       V#P-                  V'4       EK¦  	  V"PO                  4        V#PO                  4        R R lp*. p+\Q        V 4       FË  w  ppV*! VV,          VV,          Wï,          Wß,          VV,          VV,          VV,          V"V,          V#V,          4	      p,\	        V\         P                  P                  4      '       d>   R R lp-V-! VVPR                  V,VPT                  4      Vn*        V+P-                  V4       Kº  V+P-                  V,4       KÍ  	  V'       d
   V+^ ,          # \        V+4      # u upi u up
i u upi u upi u upi   + '       g   i     ELç; i  + '       g   i     EL‹; i  + '       g   i     ELù; i)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>`) or
        :class:`~torch.cuda.MemPool` that hints this graph may share memory
        with the indicated pool.  See :ref:`Graph memory management<graph-memory-management>`.
    enable_annotations (bool, optional): If ``True``, the forward and backward
        captures record kernel annotations from
        :func:`torch.cuda.graph_annotations.mark_kernels` scopes inside the
        callables (backward kernels are tagged via the scopes' autograd node
        hooks). See :mod:`torch.cuda.graph_annotations`. Default: ``False``.

.. 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.c              3  ó<   "  € T F  qP                   R J x € K  	  R# 5irO   ©Úrequires_grad©Ú.0Úbs   & r%   Ú	<genexpr>Ú)make_graphed_callables.<locals>.<genexpr>K  s   é € ÐE¹°A—‘¨%Õ/»ùs   ‚c              3  óV   "  € T F  p\        V\        P                  4      x € K!  	  R # 5ir|   )r,   r*   r   )r  Úargs   & r%   r  r  S  s   é € ÐH¹K°S”:˜c¤5§<¡<×0Ð0»Kùs   ‚')Nc              3  óL   "  € T F  qP                   '       g   K  Vx € K  	  R # 5ir|   r  ©r  Úos   & r%   r  r  x  s   é € Ð$K±¨1¿?½?§Q¢Q³ùó   ‚$š
$c              3  óL   "  € T F  qP                   '       g   K  Vx € K  	  R # 5ir|   r  ©r  r�  s   & r%   r  r  |  s   é € ð %Ù'; !¿½ŸAšAÓ';ùr  c              3  ót   "  € T F.  qP                   '       g   K  \        P                  ! V4      x € K0  	  R # 5ir|   ©r  r*   Ú
empty_liker  s   & r%   r  r    s(   é € ð +Ù9@°AÇOÅOÔ/œE×,Ò,¨Q×/Ð/»ùs   ‚8š8)ÚoutputsÚinputsÚgrad_outputsÚonly_inputsÚallow_unused)ra   r    ró   r×  c              3  ót   "  € T F.  qP                   '       d   \        P                  ! V4      MR x € K0  	  R # 5ir|   r  r  s   & r%   r  r  ©  s)   é € ð $
ÙFTÀ§?§? ?ŒE×Ò˜QÔ¸Ô<Ãnùs   ‚68c              3  óL   "  € T F  qP                   '       g   K  Vx € K  	  R # 5ir|   r  r  s   & r%   r  r  ­  s   é € ÐJ© 1¿/½/ŸQšQ«ùr  c              3  óL   "  € T F  qP                   '       g   K  Vx € K  	  R # 5ir|   r  r  s   & r%   r  r  ¹  s   é € Ð TÑ,@ qÇOÅO§¢Ó,@ùr  c              3  ó0   "  € T F  qf   K  Vx € K  	  R # 5ir|   r#   r  s   & r%   r  r  º  s   é € Ð&WÑ2E¨Q§q¢qÓ2Eùs   ‚Œ
c               ó@   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRRRR/
# )r   Ú	fwd_graphr   Ú	bwd_graphÚmodule_paramsztuple[torch.nn.Parameter, ...]Úlen_user_argsr4  Úoutput_unflatten_specztorch.utils._pytree.TreeSpecÚstatic_input_surfacer÷  Ústatic_outputsÚstatic_grad_outputsztuple[Tensor | None, ...]Ústatic_grad_inputsr"   zCallable[..., object]r#   )r$   s   "r%   r&   Ú,make_graphed_callables.<locals>.__annotate__Ô  sl   € ÷ =ñ =Øð=àð=ð 6ð=ð ð	=ð
  <ð=ð 1ð=ð +ð=ð 7ð=ð /ð=ð 
ñ=r'   c	           	     óˆ   a aaaaaaaaa
€  ! VV VVVVV3R  lR\         P                  P                  4      o
R V
VV3R llp	V	# )c                  ó    <€ ] tR tRt]R VVVV3R ll4       t]]P                  P                  P                  R V VV3R ll4       4       t
RtR# )ÚOmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphediß  c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úctxr!   r  r   r"   r÷  r#   )r$   s   "r%   r&   Ú\make_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.__annotate__â  s'   € ÷ 
Añ 
A˜Vð 
A¨fð 
AÐ9Kñ 
Ar'   c                	óš  <€ \        S4       FS  pSV,          P                  4       W,          P                  4       8w  g   K5  SV,          P                  W,          4       KU  	  SP                  4        \	        S\
        4      '       g   \        R \        S4       24      h\
        ;QJ d    . R S 4       F  NK  	  5# ! R S 4       4      # )z"static_outputs must be tuple, got c              3  ó@   "  € T F  qP                  4       x € K  	  R # 5ir|   ©r  r  s   & r%   r  Újmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.forward.<locals>.<genexpr>ì  s   é € Ð@±¨AŸX™XŸZ˜Z³ùs   ‚)rk  Údata_ptrÚcopy_r  r,   Útupler]  Útype)r,  r  r�  r  r!  r#  r$  s   &* €€€€r%   ÚforwardÚWmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.forwardà  s¦   ø€ ô ˜}Ö-�AØ+¨AÕ.×7Ñ7Ó9¸V½Y×=OÑ=OÓ=QÖQØ,¨QÕ/×5Ñ5°fµiÖ@ñ .ð × Ñ Ô"Ü! .´%×8Ò8Ü(Ø<¼TÀ.Ó=QÐ<RÐSóð ÷ ”uÑ@±Ó@—uÐ@�uÑ@±Ó@Ó@Ð@r'   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r,  r!   Úgradsr   r"   r÷  r#   )r$   s   "r%   r&   r-  ñ  s"   € ÷ ñ ˜fð ¨fð Ð9Kñ r'   c                	óð  <€ \        V4      \        S4      8w  d$   \        R \        V4       R\        S4       24      h\        SV4       FA  w  r#Vf   K  VP                  4       VP                  4       8w  g   K0  VP	                  V4       KC  	  SP                  4        \        S\        4      '       g   \        R\        S4       24      h\        ;QJ d    . R S 4       F  NK  	  5# ! R S 4       4      # )zlen(grads)=z != len(static_grad_outputs)=z&static_grad_inputs must be tuple, got c              3  óN   "  € T F  pVe   VP                  4       MTx € K  	  R # 5ir|   r0  r  s   & r%   r  Úkmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.Graphed.backward.<locals>.<genexpr>  s(   é € ð ñ 0˜ð #$¢-�A—H‘H”J°QÔ6Û/ùs   ‚#%)	Úlenr]  Úzipr2  r3  r  r,   r4  r5  )r,  r9  ÚgÚgradr  r&  r%  s   &*  €€€r%   ÚbackwardÚXmake_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Ø”}ð Ÿ:™:›<¨4¯=©=«?Ö:ØŸG™G DžMñ  ?ð × Ñ Ô"ô "Ð"4´e×<Ò<Ü(Ø@ÄÐFXÓAYÐ@ZÐ[óð ÷ ”uñ ñ 0ó—uð �uñ ñ 0óó ð r'   r#   N)re   rf   rg   rh   Ústaticmethodr6  r*   ÚautogradÚfunctionÚonce_differentiablerA  rj   )r  r  r!  r&  r%  r#  r$  s   €€€€€€€r%   ÚGraphedr*  ß  sN   ø† Ø÷
Aò 
Aó ð
Að Ø�^‰^×$Ñ$×8Ñ8÷ñ ó 9ó ôr'   rG  c               ó    € V ^8„  d   QhRRRR/# )r   Ú	user_argsr!   r"   r#   )r$   s   "r%   r&   ÚTmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.__annotate__	  s   € ÷ 	Rñ 	R vð 	R°&ñ 	Rr'   c                 óè   <€ \         P                  P                  P                  ! V !  pSP                  ! \        V4      S,           !  p\         P                  P                  P                  VS4      # r|   )r*   ÚutilsÚ_pytreeÚarg_tree_leavesÚapplyr4  Útree_unflatten)rI  Úflatten_user_argsÚoutrG  r   r"  s   *  €€€r%   ÚfunctionalizedÚVmake_graphed_callables.<locals>.make_graphed_autograd_function.<locals>.functionalized	  sW   ø€ ô !&§¡× 3Ñ 3× CÒ CÀYÑ OÐØ—-’-¤%Ð(9Ó":¸]Õ"JÑLˆCÜ—;‘;×&Ñ&×5Ñ5°cÐ;PÓQÐQr'   )r*   rD  ÚFunction)r  r  r   r!  r"  r#  r$  r%  r&  rS  rG  s   fffffffff @r%   Úmake_graphed_autograd_functionÚ>make_graphed_callables.<locals>.make_graphed_autograd_functionÔ  s4   ÿù€ ÷(	õ (	”e—n‘n×-Ñ-ô (	÷T	Rò 	Rð Ðr'   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   rs  rò  Úgraph_training_stater<   ÚgraphedzCallable[_P, _R]Úorig_fwdr"   r#   )r$   s   "r%   r&   r'  $  s:   € ÷ ñ Ø%ðà&*ðð *ðð +ð	ð
 "ñr'   c                ó&   a aaa€ R  V VVV3R llpV# )c               ó$   € V ^8„  d   QhRRRRRR/# )r   rI  z_P.argsÚuser_kwargsz	_P.kwargsr"   r   r#   )r$   s   "r%   r&   ÚJmake_graphed_callables.<locals>.make_graphed_forward.<locals>.__annotate__*  s&   € ÷ Cñ C¨ð CÀ	ð CÈbñ Cr'   c                 óF   <€ SP                   S8X  d	   S! V / VB # S! V / VB # r|   )Útraining)rI  r^  rs  rY  rZ  r[  s   *,€€€€r%   Únew_fwdÚEmake_graphed_callables.<locals>.make_graphed_forward.<locals>.new_fwd*  s2   ø€ ð —}‘}Ð(<Ô<Ù&¨	ÐA°[ÑAÐAá'¨ÐB°kÑBÐBr'   r#   )rs  rY  rZ  r[  rb  s   ffff r%   Úmake_graphed_forwardÚ4make_graphed_callables.<locals>.make_graphed_forward$  s   û€ ÷Có Cð �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.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``.zfIn the beta API, sample_args for each callable must contain only Tensors. Other types are not allowed.r#   )+r*   Úis_autocast_enabledÚis_autocast_cache_enabledrH   r,   r4  r2   r3   r   r>  ÚnnÚModuler=  Ú_backward_hooksÚ_forward_hooksÚ_forward_pre_hooksr]  ÚallÚbuffersrL  rM  rN  r~  Ú
parametersrk  r+   r   rB   r5   r\   rÚ  ra   Útree_leavesrD  r@  r   Útree_flattenÚreversedr  ÚreverseÚ	enumeratera  r6  ).rõ  rö  rø  rù  r    ró   r×  Újust_one_callableÚ_sample_argsÚflatten_sample_argsÚcrí  Úflatten_argÚper_callable_len_user_argsÚper_callable_module_paramsr�  Ú"per_callable_static_input_surfacesr‰  Ú
fwd_graphsÚ
bwd_graphsÚmempoolra   rs  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
  rV  ÚretrZ  rd  s.   &&&&&&&                                       r%   rü  rü  Ý  s®  € ôd × Ò ×"Ò"¤u×'FÒ'F×'HÒ'HÜØmó
ð 	
ð Ðô �i¤×'Ò'Ø ÐØ�Lˆ	ÜŸš¤E¬&°#¨+Õ$6¸ÓDÐF‰ä—{’{¤5¬¬v°s¨{Õ);¸SÐ)@Õ#AÀ;ÓOˆàÐä�y×/‰ˆÜ�aœŸ™Ÿ™×)Ò)ä�A×%Ñ%Ó&¨!Ô+Ü˜×(Ñ(Ó)¨QÔ.Ü˜×,Ñ,Ó-°Ô2ä$ðaóð ÷ “3ÑE¸¿¹¼ÓE—3—3’3ÑE¸¿¹¼ÓE×EÒEÜ$ð1óð ô
 —k‘k×)Ñ)×9Ò9¸4Ñ@ˆØ×"Ñ"¤5¨Ó#5Ô6ß‹sÑH¹KÓH�s�sŠsÑH¹KÓH×HÕHÜ ð^óð ñ) 0ñ6 9LÓ!LÑ8K°¤# d¦)Ñ8KÐÐ!Lñ ó"áˆAô ",¨A¬u¯x©x¯©×!?Ò!?Œˆa�l‰l‹nÔÀRÒGÙð ð "ô ”s˜9“~Ô&ó*á&ˆAð 	ÕÐ!;Õ!>×>Ð>Ù&ð 'ð *ô
 38¼¸I»Ô2GÓHÑ2G¨Q”%—*‘*×&Ñ&Ö(Ñ2G€JÐHÜ27¼¸I»Ô2GÓHÑ2G¨Q”%—*‘*×&Ñ&Ö(Ñ2G€JÐHà%)¢\ÔÔ!´|ÀDÓ7I€Gô
 
‡J�J×ÑÔô �Z‰Z×ÑÓ €FÜ	�‰×	Ñ	˜6×	"Õ	"Ü03ØÐ%G÷1
Ñ,ˆD�$Ð,ð 26°t¸T ,˜ˆKÜÐ+Ö,�ÜŸ+™+×-Ñ-×9Ñ9¹$À¹+ÓF�ß$œuÑ$K±Ó$KŸu™uÑ$K±Ó$KÓK�Ü�|Ó$ qÖ(Ü"'§.¡.×"5Ñ"5Ø ,ß$œuñ %Ù';ó%Ÿu™uñ %Ù';ó%ó  ÷ &+¤Uñ +Ù9@ó+§U¡Uñ +Ù9@ó+ó &ð %)Ø%7ð #6ó 
#’Kñ	 -ð ˜|¨[Ó9�Úô :ñ'1
÷ 
#ô. 
‡J�J×ÑÔð #%ÐØ)+Ð&Ü!$ Y¸jÖ!IÑˆˆd�IÜ�Z‰Z×ÑØØØØ1Ø1ð ÷ 
õ 
ñ   ™;ˆL÷
ô !&§¡× 3Ñ 3× @Ñ @ÀÓ NÑˆ˜Ø#×*Ñ*¬5°Ó+AÔBØ*×1Ñ1°$Ö7ñ "Jð (*Ð$Ø&(Ð#Ü;>ÜÐ3Ó4ÜÐ,Ó-Ü�Ó÷<Ñ7Ð˜n¨i÷ $œeñ $
ÙFTó$
Ÿe™eñ $
ÙFTó$
ó 
Ð÷ ”uÑJ©ÓJ—u‘uÑJ©ÓJÓJˆØˆÜˆ|Ó˜qÔ Ü—‘×!Ñ!ØØØØ#5Ø#5ð "÷ õ ô $Ÿn™n×1Ñ1Ø(ß œ5Ñ TÑ,@Ó TŸ5™5Ñ TÑ,@Ó TÓTß!&¤Ñ&WÑ2EÓ&W§¡Ñ&WÑ2EÓ&WÓ!WØ $Ø!3ð 2ó �÷ð$  ÐØˆÛ'ˆCØ× × Ð  [Ò%<Ø"×)Ñ)¨+°hÕ*?Ô@Ø˜A•’à"×)Ñ)¨$Ö/ñ (ô #Ð#5Ó6Ðà(×/Ñ/Ð0CÔDØ'×.Ñ.Ð/A×BñW<ð\ %×,Ñ,Ô.Ø#×+Ñ+Ô-õ=ð@ $&€CÜ˜YÖ'‰ˆˆ4Ù0Ø�q�MØ�q�MØ&Õ)Ø&Õ)Ø.¨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ˆä�‹:ÐùòG "Mùò"ùò*ùò
 IùÚH÷ 
#×	"Ð	"ú÷B
÷ 
ð 
ú÷<÷ ð ús]   ÉcÉAcËcË;'cÌ:'cÏBcÑ3$cÒ*cÓ>cÕ*c3ÚAdÛ/(dãc0	ã3däd)r>   rB   r   r   rü  rÆ  rÒ  r‚   r…   rˆ   r‹   rŽ   r’   )é   FNr   F)VÚ__conditional_annotations__Ú
__future__r   r©  ræ  r2   r‚  r¼   Úcollectionsr   Úcollections.abcr   r   r   r   r	   r
   Útyping_extensionsr   r   r   r*   r   Útorch.cuda._utilsr   Úcuda.bindingsr   r\  r   rG   ÚImportErrorÚ
torch.cudar   r   rø   r   rv   r   r   r¡  ÚAnyÚ_utilsr   Ú__all__r   r   r.   r5   Úhasattrr³  Ú__dict__Útorch._Cr9   r7   r8   r>   rB   rI   rK   rl   rm   rn   ro   rp   rx   r}   r‚   r…   rˆ   r‹   rŽ   r�   r’   r•   rš   r   Ú	Structurer¤  r}  r/  rÆ  rÒ  r   r!   ró  rü  )r�  s   @r%   Ú<module>r�     s}  øðç "Ð "ã Û 	Û Û Û Ý #Ý $ß GÕ Gß 6Ñ 6ã Ý Ý 2ð÷÷ ç0ÝFÝ1à(¨7Õ2€J�	Ô2à"ŸJ™J€J�	Ó&å  ò€ñ" ˆTƒ]€Ùˆtƒ_€õEõ
-ñ ˆu�x‰xÐ*×+Ò+á&1°,Ó&?€E‡H�H×Ñ�lÑ#Ù.9Ð:NÓ.O€E‡H�H×ÑÐ*Ñ+Ù:EØ(ó;€E‡H�H×ÑÐ6Ñ7÷ TÑ Sõ,õ9õ

÷+ñ +ñl ƒMð ÐJó ñ LWË=Ð ÐHÓ XÙKVË=Ð ÐHÓ XáƒMð ÐIó ñ KVË-Ð ÐGÓ WõõõBõ@õ@õ
Aõ?ñ GRÃmÐ ÐCÓ Sõõ'õôL�
ô Lô^ˆf×Ñô õ7ðÈ÷ ð	¨T÷ 	õ÷ E,ñ E,ðR  %Ð%6¸ÀÀfÀÕ8MÐ%MÕNÐ �9Ó Nð 
öó 
ðð 
ö(ó 
ð(÷añ aøðK& ô Ø€LØƒMðús   ÁI% É%I4É3I4