Ë
    S²jo  ã                   ó"  — 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y)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y)ÚFlashAttentionHandleNc                  ó   — y )N© )Úselfs    ú[/var/www/html/ia-enhanced/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   .)ÚFA3ÚFA4Ú_FLASH_ATTENTION_IMPLSÚ_FLASH_ATTENTION_ACTIVEÚ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        d¬«       t        j                  | «      }|€t        d| › dt	        «       › �«      ‚ |«       }|�| |fay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
    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!   =   sm   € ô2 !Øõô )×,Ñ,¨TÓ2€KØÐÜØ,¨T¨Fð 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   f   s   € äÔ(×-Ñ-Ó/Ó0Ð0r   c                  ó,   — t         �	t         d   S 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   r   Úcurrent_flash_attention_implr&   k   s#   € ô #Ð.ô 	  Ñ"ðô %ðr   r   c                 ó‚   — d}t         �	t         d   }|�|j                  «        da y| rt        j                  d«       da y)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   sL   € ð €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àCGÐ ˜˜sÐ$8Ð8Ñ9¸DÑ@Ó Gð/Ø
Ð#Ñ
#ð/ð ð/ð 
ó	/ðB&1Ø
Ð#Ñ
#ð&1à	ó&1ðR1 D¨¡Ió 1ð

 c¨D¡jó 
ñ#¨dð #¸dô #r   