
    i.                         U d Z ddlmZ ddlmZmZ  G d de      Zededz  f   Zed   Zi Z	e
eef   ed	<   daedz  ed
<   i Ze
eef   ed<   deez  deddfdZdeez  ddfdZdee   fdZdedz  fdZy)zRegistry for flash attention implementations.

This module contains the registration system for flash attention implementations.
It has no torch dependencies to avoid circular imports during initialization.
    )Callable)LiteralProtocolc                       e Zd ZddZy)FlashAttentionHandleNc                      y )N )selfs    V/var/www/html/engine/venv/lib/python3.12/site-packages/torch/nn/attention/_registry.pyremovezFlashAttentionHandle.remove   s        )returnN)__name__
__module____qualname__r   r	   r   r   r   r      s    !r   r   .NFA4_FLASH_ATTENTION_IMPLS_FLASH_ATTENTION_ACTIVE_FLASH_ATTENTION_HANDLESimplregister_fnr   c                    |t         | <   y)a#  
    Register the callable that activates a flash attention impl.

    .. note::
        This function is intended for SDPA backend providers to register their
        implementations. End users should use :func:`activate_flash_attention_impl`
        to activate a registered implementation.

    Args:
        impl: Implementation identifier (e.g., ``"FA4"``).
        register_fn: Callable that performs the actual dispatcher registration.
            This function will be invoked by :func:`activate_flash_attention_impl`
            and should register custom kernels with the PyTorch dispatcher.
            It may optionally return a handle implementing
            :class:`FlashAttentionHandle` to keep any necessary state alive.

    Example:
        >>> def my_impl_register(module_path: str = "my_flash_impl"):
        ...     # Register custom kernels with torch dispatcher
        ...     pass  # doctest: +SKIP
        >>> register_flash_attention_impl(
        ...     "MyImpl", register_fn=my_impl_register
        ... )  # doctest: +SKIP
    N)r   )r   r   s     r   register_flash_attention_implr      s    : $/4 r   c                     t         j                  |       }|t        d|  dt                      t        | k(  ry |       }|	|t
        | <   | ay)ac  
    Activate into the dispatcher a previously registered flash attention impl.

    .. note::
        Backend providers should NOT automatically activate their implementation
        on import. Users should explicitly opt-in by calling this function or via
        environment variables to ensure multiple provider libraries can coexist.

    Args:
        impl: Implementation identifier to activate. See
            :func:`~torch.nn.attention.list_flash_attention_impls` for available
            implementations.
            If the backend's :func:`register_flash_attention_impl` callable
            returns a :class:`FlashAttentionHandle`, the registry keeps that
            handle alive for the lifetime of the process (until explicit
            uninstall support exists).

    Example:
        >>> activate_flash_attention_impl("FA4")  # doctest: +SKIP
    NzUnknown flash attention impl 'z'. Available implementations: )r   get
ValueErrorlist_flash_attention_implsr   r   )r   r   handles      r   activate_flash_attention_implr   9   sm    0 ),,T2K,TF 3**D*F)GI
 	
 $&]F)/ &"r   c                  <    t        t        j                               S )zBReturn the names of all available flash attention implementations.)sortedr   keysr	   r   r   r   r   b   s    (--/00r   c                      t         S )z
    Return the currently activated flash attention impl name, if any.

    ``None`` indicates that no custom impl has been activated.
    )r   r	   r   r   current_flash_attention_implr$   g   s
     #"r   )__doc__collections.abcr   typingr   r   r   _RegisterFn_FlashAttentionImplr   dictstr__annotations__r   r   r   r   listr   r$   r	   r   r   <module>r.      s    % $"8 " s04778en 13 S+-. 3&* t *<> $s$889 >/
#
#/ / 
	/@&#
#
#&#	&#R1DI 1
#cDj #r   