o
    ߗi                     @   s   d dl mZ d dlmZmZ d dlmZmZmZm	Z	 eG dd dZ
e
 Zdeg df deg df fd	d
Zdeg df deg df fddZdS )    )contextmanager)	dataclassfield)AnyCallable	GeneratorListc                   @   s   e Zd ZU eedZeeg df  ed< eedZ	eeg df  ed< deg df deg df fddZ
deg df deg df fd	d
Zdeg df ddfddZdeg df ddfddZdddZdddZededeef fddZdddZdS )CompilationCallbackHandler)default_factoryNstart_callbacksend_callbackscallbackreturnc                 C      | j | |S )z
        Register a callback function to be called when the compilation starts.

        Args:
        - callback (Callable): The callback function to register.
        )r   appendselfr    r   T/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/torch/_dynamo/callback.pyregister_start_callback   s   	z2CompilationCallbackHandler.register_start_callbackc                 C   r   )z
        Register a callback function to be called when the compilation ends.

        Args:
        - callback (Callable): The callback function to register.
        )r   r   r   r   r   r   register_end_callback   s   z0CompilationCallbackHandler.register_end_callbackc                 C      | j | dS )z
        Remove a registered start callback function.

        Args:
        - callback (Callable): The callback function to remove.
        N)r   remover   r   r   r   remove_start_callback!      z0CompilationCallbackHandler.remove_start_callbackc                 C   r   )z
        Remove a registered end callback function.

        Args:
        - callback (Callable): The callback function to remove.
        N)r   r   r   r   r   r   remove_end_callback*   r   z.CompilationCallbackHandler.remove_end_callbackc                 C      | j D ]}|  qdS )z9
        Execute all registered start callbacks.
        N)r   r   r   r   r   run_start_callbacks3      
z.CompilationCallbackHandler.run_start_callbacksc                 C   r   )z7
        Execute all registered end callbacks.
        N)r   r   r   r   r   run_end_callbacks:   r   z,CompilationCallbackHandler.run_end_callbacksc                 c   s*    z|    dV  W |   dS |   w )zc
        Context manager to install the callbacks and run them when the context is exited.
        N)r   r   r   r   r   r   install_callbacksA   s
   z,CompilationCallbackHandler.install_callbacksc                 C   s   | j   | j  dS )z1
        Clear all registered callbacks.
        N)r   clearr   r    r   r   r   r"   L   s   
z CompilationCallbackHandler.clear)r   N)__name__
__module____qualname__r   listr   r   r   __annotations__r   r   r   r   r   r   r   r   r   r   r!   r"   r   r   r   r   r	      s    
 


"
	
	

r	   r   Nr   c                 C      t |  | S )zU
    Decorator to register a callback function for the start of the compilation.
    )callback_handlerr   r   r   r   r   on_compile_startW      
r+   c                 C   r(   )zS
    Decorator to register a callback function for the end of the compilation.
    )r)   r   r*   r   r   r   on_compile_end_   r,   r-   )
contextlibr   dataclassesr   r   typingr   r   r   r   r	   r)   r+   r-   r   r   r   r   <module>   s    M"&