§
    �Štjo  ã                   óD  — U d Z ddlZddlmZ ddlmZmZ  ej        e¦  «        Z	 G d„ de¦  «        Z
ede
dz  f         Zed         Zi aeeef         ed	<   daeee
f         dz  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ddeddfd„ZdS )zÏRegistry 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.
é    N)ÚCallable)ÚLiteralÚProtocolc                   ó   — e Zd Zdd„ZdS )ÚFlashAttentionHandleÚreturnNc                 ó   — d S )N© )Úselfs    úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/nn/attention/_registry.pyÚremovezFlashAttentionHandle.remove   s   € € € ó    )r   N)Ú__name__Ú
__module__Ú__qualname__r   r
   r   r   r   r      s   € € € € € Ø!Ð!Ð!Ð!Ð!Ð!r   r   .)ÚFA3ÚFA4Ú_FLASH_ATTENTION_IMPLSÚ_FLASH_ATTENTION_ACTIVEÚimplÚregister_fnr   c                ó   — |t           | <   dS )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          d¬¦  «         t                               | ¦  «        }|€!t          d| › dt	          ¦   «         › �¦  «        ‚ |¦   «         }|�| |fadS dS )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
    F)Ú_raise_warnNzUnknown flash attention impl 'z'. Available implementations: )Úrestore_flash_attention_implr   ÚgetÚ
ValueErrorÚlist_flash_attention_implsr   )r   r   Úhandles      r   Úactivate_flash_attention_implr!   =   sŸ   € õ2 !Øðñ ô ð õ )×,Ò,¨TÑ2Ô2€KØÐÝðI¨Tð Ið IÝ*DÑ*FÔ*FðIð Iñ
ô 
ð 	
ð
 ˆ[‰]Œ]€FØÐØ#'¨ .ÐÐÐð Ðr   c                  óN   — t          t                               ¦   «         ¦  «        S )zBReturn the names of all available flash attention implementations.)Úsortedr   Úkeysr
   r   r   r   r   f   s   € åÕ(×-Ò-Ñ/Ô/Ñ0Ô0Ð0r   c                  ó8   — t           �t           d         nt           S )z‹
    Return the currently activated flash attention impl name, if any.

    ``None`` indicates that no custom impl has been activated.
    Nr   )r   r
   r   r   Úcurrent_flash_attention_implr&   k   s   € õ #Ð.õ 	  Ô"Ð"å$ðr   Tr   c                 óœ   — d}t           �t           d         }|�|                     ¦   «          n| rt                               d¦  «         da dS )z0
    Restore the default FA2 implementation
    Né   zDTrying to restore default FA2 impl when no custom impl was activated)r   r   ÚloggerÚwarning)r   r    s     r   r   r   x   s]   € ð €FÝÐ*Ý(¨Ô+ˆàÐØ�Š‰ŒˆˆØ	ð 
Ý�ŠØRñ	
ô 	
ð 	
ð #ÐÐÐr   )T)Ú__doc__ÚloggingÚcollections.abcr   Útypingr   r   Ú	getLoggerr   r)   r   Ú_RegisterFnÚ_FlashAttentionImplr   ÚdictÚstrÚ__annotations__r   Útupler   r!   Úlistr   r&   Úboolr   r
   r   r   ú<module>r8      s¶  ððð ð ð €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø $Ð $Ð $Ð $Ð $Ð $Ð $Ð $ð 
ˆÔ	˜8Ñ	$Ô	$€ð"ð "ð "ð "ð "˜8ñ "ô "ð "ð �sÐ0°4Ñ7Ð7Ô8€Ø˜lÔ+Ð à13Ð ˜˜S +Ð-Ô.Ð 3Ð 3Ñ 3àCGÐ ˜˜sÐ$8Ð8Ô9¸DÑ@Ð GÐ GÑ Gð/Ø
Ð#Ñ
#ð/ð ð/ð 
ð	/ð /ð /ð /ðB&1Ø
Ð#Ñ
#ð&1à	ð&1ð &1ð &1ð &1ðR1 D¨¤Ið 1ð 1ð 1ð 1ð

 c¨D¡jð 
ð 
ð 
ð 
ð#ð #¨dð #¸dð #ð #ð #ð #ð #ð #r   