+
    –°³j¡  ã                   óÞ   € R t ^ RIt^ RIt^ RIHtHt ^ RIHt ^ RIH	t	H
t
 ^ RIHt  ! R R]P                  4      t]	 ! R R	4      4       t]	 ! R
 R4      4       t]! 4       tR R ltR R ltR# )a  
This module provides callback management functionality for TorchDynamo's compilation process.

It implements a thread-safe system for registering, managing and executing callbacks that run
at the start and end of TorchDynamo compilations. Key features include:

- Registration and deregistration of compilation callbacks
- Thread-safe callback handling with proper locking mechanisms
- Prevention of duplicate callback execution when configured
- Decorator utilities for easy callback registration
- Context manager for controlled callback lifecycle

The module centers around the CompilationCallbackHandler class which maintains separate
lists for start and end callbacks, manages their execution order, and ensures thread-safety.
Utility decorators @on_compile_start and @on_compile_end provide a convenient way to
register compilation hooks.

Example usage:
    @on_compile_start
    def my_start_callback():
        print("Starting compilation")

    @on_compile_end
    def my_end_callback():
        print("Compilation complete")
N)ÚCallableÚ	Generator)Úcontextmanager)Ú	dataclassÚfield)ÚAnyc                   ó&   € ] tR t^$t^t^t^t^tRtR# )ÚCallbackTrigger© N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚDYNAMOÚLAZY_BACKWARDÚTRITON_AUTOTUNINGÚCUDAGRAPH_RECORDINGÚ__static_attributes__r
   ó    ÚW/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/_dynamo/callback.pyr	   r	   $   s   † à€Fà€MàÐàÔr   r	   c                   ó,   a € ] tR t^/t o V 3R ltRtV tR# )ÚCallbackArgsc                ó2   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   # )é   Úcallback_triggerÚ
compile_id)r	   Ústr)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚCallbackArgs.__annotate__/   s   ø‡ ‚ á%Ñ%ñ ñ �Oò r   r
   N)r   r   r   r   Ú__annotate_func__r   Ú__classdictcell__©r   s   @r   r   r   /   s   ø‡ ‡ „ r   r   c                   ó*  a € ] tR t^5t o ]! ]R7      t]! ]R7      t]! ^ RRR7      t]! ]	P                  RRR7      tV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR ltV 3R lR ltV 3R lR lt]V 3R lR l4       tV 3R lR ltV 3R ltRtV tR# )ÚCompilationCallbackHandler)Údefault_factoryF)ÚdefaultÚinitÚrepr)r&   r(   r)   c                óR   <€ V ^8„  d   QhRS[ S[.R3,          RS[ S[.R3,          /# ©r   ÚcallbackNÚreturn©r   r   )r   r   s   "€r   r   Ú'CompilationCallbackHandler.__annotate__?   ó5   ø€ ÷ 
ñ 
Ù ¡, °Ð!5Õ6ð
á	‘<�. $Ð&Õ	'ñ
r   c                ó<   € V P                   P                  V4       V# )z‰
Register a callback function to be called when the compilation starts.

Args:
- callback (Callable): The callback function to register.
)Ústart_callbacksÚappend©Úselfr,   s   &&r   Úregister_start_callbackÚ2CompilationCallbackHandler.register_start_callback?   s   € ð 	×Ñ×#Ñ# HÔ-Øˆr   c                óR   <€ V ^8„  d   QhRS[ S[.R3,          RS[ S[.R3,          /# r+   r.   )r   r   s   "€r   r   r/   K   r0   r   c                ó<   € V P                   P                  V4       V# )z‡
Register a callback function to be called when the compilation ends.

Args:
- callback (Callable): The callback function to register.
)Úend_callbacksr3   r4   s   &&r   Úregister_end_callbackÚ0CompilationCallbackHandler.register_end_callbackK   s   € ð 	×Ñ×!Ñ! (Ô+Øˆr   c                ó:   <€ V ^8„  d   QhRS[ S[.R3,          RR/# r+   r.   )r   r   s   "€r   r   r/   W   s(   ø€ ÷ .ñ .©h¹°~ÀtÐ7KÕ.Lð .ÐQUñ .r   c                ó<   € V P                   P                  V4       R# )zm
Remove a registered start callback function.

Args:
- callback (Callable): The callback function to remove.
N)r2   Úremover4   s   &&r   Úremove_start_callbackÚ0CompilationCallbackHandler.remove_start_callbackW   s   € ð 	×Ñ×#Ñ# HÖ-r   c                ó:   <€ V ^8„  d   QhRS[ S[.R3,          RR/# r+   r.   )r   r   s   "€r   r   r/   `   s'   ø€ ÷ ,ñ ,©H±l°^ÀTÐ5IÕ,Jð ,Ètñ ,r   c                ó<   € V P                   P                  V4       R# )zk
Remove a registered end callback function.

Args:
- callback (Callable): The callback function to remove.
N)r:   r?   r4   s   &&r   Úremove_end_callbackÚ.CompilationCallbackHandler.remove_end_callback`   s   € ð 	×Ñ×!Ñ! (Ö+r   c                ó$   <€ V ^8„  d   QhRS[ RR/# ©r   Úargsr-   N©r   )r   r   s   "€r   r   r/   i   s   ø€ ÷ ñ ©ð ¸ñ r   c                ó<   € V P                    F  pV! V4       K  	  R# )z)
Execute all registered start callbacks.
N)r2   ©r5   rH   r,   s   && r   Úrun_start_callbacksÚ.CompilationCallbackHandler.run_start_callbacksi   s   € ð ×,Ô,ˆHÙ�TŽNó -r   c                ó$   <€ V ^8„  d   QhRS[ RR/# rG   rI   )r   r   s   "€r   r   r/   p   s   ø€ ÷ ñ ¡lð °tñ r   c                ó<   € V P                    F  pV! V4       K  	  R# )z'
Execute all registered end callbacks.
N)r:   rK   s   && r   Úrun_end_callbacksÚ,CompilationCallbackHandler.run_end_callbacksp   s   € ð ×*Ô*ˆHÙ�TŽNó +r   c          	      óD   <€ V ^8„  d   QhRS[ RS[RS[RS[S[3,          /# )r   Útriggerr   r-   N)r	   r   r   r   )r   r   s   "€r   r   r/   x   s0   ø€ ÷ 6ñ 6Ù&ð6Ù47ð6á	�4™™c�>Õ	"ñ6r   c           	   #  ó,  "  € \        W4      p V P                  ;_uu_ 4        V ;P                  ^,          un        V P                  ^8X  d   V P                  V4       RRR4       Rx € V P                  ;_uu_ 4        V P                  ^ 8:  d   \	        R4      hV P                  ^8X  d   V P                  V4       V ;P                  ^,          un        RRR4       R#   + '       g   i     LŠ; i  + '       g   i     R# ; i  T P                  ;_uu_ 4        T P                  ^ 8:  d   \	        R4      hT P                  ^8X  d   T P                  T4       T ;P                  ^,          un        RRR4       i   + '       g   i     i ; i; i5i)zS
Context manager to install the callbacks and run them when the context is exited.
Nz1Pending callbacks counter cannot become negative.)r   Ú;_CompilationCallbackHandler__pending_callbacks_counter_lockÚ6_CompilationCallbackHandler__pending_callbacks_counterrL   ÚAssertionErrorrP   )r5   rS   r   rH   s   &&& r   Úinstall_callbacksÚ,CompilationCallbackHandler.install_callbacksw   s5  é € ô ˜GÓ0ˆð	6Ø×6×6Ó6Ø×0Ò0°AÕ5Õ0Ø×3Ñ3°qÔ8Ø×,Ñ,¨TÔ2÷ 7ó à×6×6Ó6Ø×3Ñ3°qÔ8Ü(ØKóð ð ×3Ñ3°qÔ8Ø×*Ñ*¨4Ô0Ø×0Ò0°AÕ5Õ0÷ 7Ñ6÷ 7×6ú÷ 7×6Ð6û�×6×6Ó6Ø×3Ñ3°qÔ8Ü(ØKóð ð ×3Ñ3°qÔ8Ø×*Ñ*¨4Ô0Ø×0Ò0°AÕ5Õ0÷ 7×6×6Ð6ÿse   ‚F�D £<C!ÁD Á+FÁ?AC4Ã
FÃ!C1	Ã,D Ã4D	Ã?	FÄFÄAE>	Å5	FÅ>FÆ	FÆFc                ó   <€ V ^8„  d   QhRR/# )r   r-   Nr
   )r   r   s   "€r   r   r/   �   s   ø€ ÷ 	ñ 	�tñ 	r   c                óÂ   € V P                   P                  4        V P                  P                  4        V P                  ^ 8w  d   \	        RV P                   R24      hR# )z!
Clear all registered callbacks.
zCannot clear callbacks while z are pendingN)r2   Úclearr:   rV   rW   )r5   s   &r   r\   Ú CompilationCallbackHandler.clear�   s\   € ð 	×Ñ×"Ñ"Ô$Ø×Ñ× Ñ Ô"Ø×+Ñ+¨qÔ0Ü Ø/°×0PÑ0PÐ/QÐQ]Ð^óð ñ 1r   c                óª   <€ V ^8„  d   Qh/ S[ S[S[.R3,          ,          ;R&   S[ S[S[.R3,          ,          ;R&   S[;R&   S[P
                  ;R&   # )r   Nr2   r:   rV   rU   )Úlistr   r   ÚintÚ	threadingÚLock)r   r   s   "€r   r   r/   5   s_   ø‡ ‚ á™(¡L >°4Ð#7Õ8Õ9ÑWñ ñ ™¡, °Ð!5Õ6Õ7ÑUñ ñ
 "%ÑOñ ñ '0§n¡nñ ò r   r
   N)r   r   r   r   r   r_   r2   r:   rV   ra   rb   rU   r6   r;   r@   rD   rL   rP   r   rX   r\   r!   r   r"   r#   s   @r   r%   r%   5   s¢   ø‡ € á<AÐRVÔ<W€OÙ:?ÐPTÔ:U€Má',°Q¸UÈÔ'OÐÙ7<Ø!Ÿ™¨U¸ô8Ð$÷
ð 
÷
ð 
÷.ð .÷,ð ,÷ð ÷ð ð ÷6ó ð6÷.	ð 	÷u ƒ r   r%   c                óh   € V ^8„  d   QhR\         \        .R3,          R\         \        .R3,          /# r+   r.   )r   s   "r   r   r   ž   ó4   € ÷ ñ Üœ�~ tÐ+Õ,ðäŒ|ˆn˜dÐ"Õ#ñr   c                ó0   € \         P                  V 4       V # )zM
Decorator to register a callback function for the start of the compilation.
)Úcallback_handlerr6   ©r,   s   &r   Úon_compile_startrh   ž   s   € ô ×,Ñ,¨XÔ6Ø€Or   c                óh   € V ^8„  d   QhR\         \        .R3,          R\         \        .R3,          /# r+   r.   )r   s   "r   r   r   ¨   rd   r   c                ó0   € \         P                  V 4       V # )zK
Decorator to register a callback function for the end of the compilation.
)rf   r;   rg   s   &r   Úon_compile_endrk   ¨   s   € ô ×*Ñ*¨8Ô4Ø€Or   )Ú__doc__Úenumra   Úcollections.abcr   r   Ú
contextlibr   Údataclassesr   r   Útypingr   ÚEnumr	   r   r%   rf   rh   rk   r
   r   r   Ú<module>rs      sy   ðñó6 Û ß /Ý %ß (Ý ô�d—i‘iô ð ÷ð ó ðð
 ÷bð bó ðbñJ .Ó/Ð õ÷r   