U
    zh                     @   s(   G d d dZ e  Zdd Zdd ZdS )c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )CompilationCallbackHandlerc                 C   s   g | _ g | _d S )N)start_callbacksend_callbacksself r   H/var/www/html/venv/lib/python3.8/site-packages/torch/_dynamo/callback.py__init__   s    z#CompilationCallbackHandler.__init__c                 C   s   | j | |S )z
        Register a callback function to be called when the compilation starts.

        Args:
        - callback (callable): The callback function to register.
        )r   appendr   callbackr   r   r   register_start_callback   s    z2CompilationCallbackHandler.register_start_callbackc                 C   s   | j | |S )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   s   | 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   s    z0CompilationCallbackHandler.remove_start_callbackc                 C   s   | j | dS )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$   s    z.CompilationCallbackHandler.remove_end_callbackc                 C   s   | j D ]
}|  qdS )z9
        Execute all registered start callbacks.
        N)r   r
   r   r   r   run_start_callbacks-   s    
z.CompilationCallbackHandler.run_start_callbacksc                 C   s   | j D ]
}|  qdS )z7
        Execute all registered end callbacks.
        N)r   r
   r   r   r   run_end_callbacks4   s    
z,CompilationCallbackHandler.run_end_callbacksc                 C   s   | j   | j  dS )z1
        Clear all registered callbacks.
        N)r   clearr   r   r   r   r   r   ;   s    
z CompilationCallbackHandler.clearN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   r   r   r      s   

		r   c                 C   s   t |  | S )zU
    Decorator to register a callback function for the start of the compilation.
    )callback_handlerr   r   r   r   r   on_compile_startF   s    
r   c                 C   s   t |  | S )zS
    Decorator to register a callback function for the end of the compilation.
    )r   r   r   r   r   r   on_compile_endN   s    
r   N)r   r   r   r   r   r   r   r   <module>   s   A