ó
    !EñiX  ã                   óx  • % S r SSKrSSKJr  SSKJr  SSKJr  SSKr	SSK
Jr  SSKJrJrJr  / SQr\\   \S	'   S
r \\l        S\l        S\SS4S jrSSSSSS.rS\4S jrS"S\4S jjrS"S\S\SS4S jjr\R:                  S"S\\   \-  S\4S jj5       r\R:                  S\4S j5       rS\4S jr SS K!J"r"  \"RF                  r#\"RH                  r$\"RJ                  r%\"RL                  r&\"RN                  r'\"RP                  r(\"RR                  r)\\%l        \\&l        \\'l        \\(l        \\)l        SS!K!J*r*J+r+  g)#zvThis module contains functions and classes that alter the behavior of torch.nn.functional.scaled_dot_product_attentioné    N)ÚIterable)ÚUnion)Úwarn)Ú_SDPBackend)Úcan_use_efficient_attentionÚcan_use_flash_attentionÚ
SDPAParams)Ú
SDPBackendÚsdpa_kernelÚWARN_FOR_UNFUSED_KERNELSÚregister_flash_attention_implÚactivate_flash_attention_implÚlist_flash_attention_implsÚcurrent_flash_attention_implÚrestore_flash_attention_implÚ__all__Fr
   ÚparamsÚreturnc                 ó¶   • [         (       aN  [        U 5      (       d  [        SSS9  [        U S5        [        U 5      (       d  [        SSS9  [        U S5        ggg)z’
If WARN_FOR_UNFUSED_KERNELS is set to True, this will raise warnings
for all the reasons why the fused kernels can't be run. If using subclasses
z*Efficient attention can't be used because:é   )Ú
stacklevelTz&Flash attention can't be used because:N)r   r   r   r   )r   s    ÚX/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/nn/attention/__init__.pyÚ_raise_kernel_warningsr   ;   sT   € ÷
  ÒÜ*¨6×2Ñ2ÜÐ=È!ÒLÜ'¨°Ô5Ü& v×.Ñ.ÜÐ9ÀaÒHÜ# F¨DÕ1ð /ð	  ó    ÚCUDNN_ATTENTIONÚFLASH_ATTENTIONÚEFFICIENT_ATTENTIONÚMATHÚOVERRIDEABLE)ÚcudnnÚflashÚmem_efficientÚmathÚoverrideableÚnamec                 ó"   • [        [        U 5      $ ©N)Úgetattrr
   )r%   s    r   Ú_backend_from_stringr)   R   s   € Ü”:˜tÓ$Ð$r   Úwith_priorityc                 ó>  ^• / n[         R                  5        HN  u  p#[        [        R                  SU S35      " 5       (       d  M/  UR                  [        [        U5      5        MP     U (       a,  [        R                  R                  5       m[        UU4S jS9nU$ )NÚ_get_Ú_sdp_enabledc                 ó8   >• TR                  [        U 5      5      $ r'   )ÚindexÚint)ÚbackendÚcurr_prioritys    €r   Ú<lambda>Ú+_cur_sdpa_kernel_backends.<locals>.<lambda>^   s   ø€ ¨-×*=Ñ*=¼cÀ'»lÔ*Kr   )Úkey)	Ú_backend_namesÚitemsr(   ÚtorchÚ_CÚappendr
   Ú_get_sdp_priority_orderÚsorted)r*   Úbackendsr%   Úvalr2   s       @r   Ú_cur_sdpa_kernel_backendsr?   V   s{   ø€ Ø€HÜ#×)Ñ)Ö+‰	ˆÜ”5—8‘8˜u T F¨,Ð7Ô8×:Ó:Ø�O‰OœG¤J°Ó4Ö5ñ ,ö ÜŸ™×8Ñ8Ó:ˆÜØÔKñ
ˆð €Or   r=   Úset_priorityc                 óÈ  • [         R                  5        H;  u  p#[        [        U5      U ;   n[        [        R
                  SU 35      " U5        M=     U(       aƒ  U  Vs/ s H  n[        U5      PM     nn[        R
                  R                  5       nU H$  nXV;  d  M
  UR                  [        U5      5        M&     [        R
                  R                  U5        g g s  snf )NÚ_set_sdp_use_)
r6   r7   r(   r
   r8   r9   r0   r;   r:   Ú_set_sdp_priority_order)r=   r@   r%   r>   Úenabledr1   Úuser_priorityÚprevious_prioritys           r   Ú_sdpa_kernelrG   c   s°   € Ü#×)Ñ)Ö+‰	ˆÜœ* cÓ*¨hÑ6ˆÜ”—‘˜M¨$¨Ð0Ô1°'Ö:ñ ,ö á5=Ó>²X¨'œ˜Wž±XˆÐ>Ü!ŸH™H×<Ñ<Ó>ÐÛ(ˆGØÕ+Ø×$Ñ$¤S¨£\Ö2ñ )ô 	�‰×(Ñ(¨Õ7ð ùâ>s   ÁCc              #   óX  #   • [        U [        [        45      (       d!  [        S[	        U 5      R
                   35      e[        U [        5      (       a  U /n [        [        R                  U 5      5      n [        US9n [        X5        0 v •  [        X!5        g! [        X!5        f = f7f)aô  
Context manager to select which backend to use for scaled dot product attention.

.. warning:: This function is beta and subject to change.

Args:
    backends (Union[List[SDPBackend], SDPBackend]): A backend or list of backends for scaled dot product attention.
    set_priority (bool=False): Whether the ordering of the backends is interpreted as their priority order.

Example:

.. code-block:: python

    from torch.nn.functional import scaled_dot_product_attention
    from torch.nn.attention import SDPBackend, sdpa_kernel

    # Only enable flash attention backend
    with sdpa_kernel(SDPBackend.FLASH_ATTENTION):
        scaled_dot_product_attention(...)

    # Enable the Math or Efficient attention backends
    with sdpa_kernel([SDPBackend.MATH, SDPBackend.EFFICIENT_ATTENTION]):
        scaled_dot_product_attention(...)

    # Enable the cuDNN or flash attention backends, and in that order
    with sdpa_kernel(
        [SDPBackend.CUDNN_ATTENTION, SDPBackend.FLASH_ATTENTION], set_priority=True
    ):
        scaled_dot_product_attention(...)

This context manager can be used to select which backend to use for scaled dot product attention.
Upon exiting the context manager, the previous state of the flags will be restored, enabling all backends.
zQBackend must be an instance of SDPBackend or a list of SDPBackend instances, got )r*   N)
Ú
isinstanceÚlistr
   ÚAssertionErrorÚtypeÚ__name__ÚdictÚfromkeysr?   rG   )r=   r@   Úprevious_backendss      r   r   r   q   s—   é € ôF �h¤¤zÐ 2×3Ñ3ÜØ_Ô`dÐemÓ`n×`wÑ`wÐ_xÐyó
ð 	
ô �(œJ×'Ñ'Ø�:ˆä”D—M‘M (Ó+Ó,€Hä1ÀÑMÐð6Ü�XÔ,ØŠäÐ&Õ5øŒÐ&Õ5üs   ‚A<B*Á?B ÂB*ÂB'Â'B*c               '   óp   #   • [        [        U 5      5         S v •  S S S 5        g ! , (       d  f       g = f7fr'   )r   rJ   )r=   s    r   Ú_sdpa_kernel_variadicrR   §   s   é € ä	”T˜(“^Õ	$Û÷ 
%×	$Ö	$üs   ‚6—%œ	6¥
3¯6c                  ó   • g)zEThis returns the closest matching tag for the flash attention backendz2.5.7© rT   r   r   Ú_get_flash_versionrU   ­   s   € àr   é   )Ú	_registry)Ú_fa3Ú_fa4)F),Ú__doc__Ú
contextlibÚcollections.abcr   Útypingr   Úwarningsr   Útorch.backends.cudar8   Útorch._Cr   r
   r   r   r	   r   rJ   ÚstrÚ__annotations__r   rM   Ú
__module__r   r6   r)   Úboolr?   rG   Úcontextmanagerr   rR   rU   Ú rW   Ú_FlashAttentionImplÚ_RegisterFnr   r   r   r   r   rX   rY   rT   r   r   Ú<module>ri      s¡  ðâ |ã Ý $Ý Ý ã Ý .÷ñ ò	€ˆˆc‰ó 	ð& !Ð ðð !€
Ô Ø"€
Ô ð2 :ð 2°$ô 2ð ØØ*ØØ"ñ€ð%˜sô %ñ
¨Tõ 
ñ8˜8ð 8°4ð 8ÀDõ 8ð ×Ññ16˜$˜zÑ*¨ZÑ7ð 16Àtô 16ó ð16ðj ×Ñð Zó ó ðð
˜Cô õ
 ð  ×3Ñ3Ð Ø×#Ñ#€Ø )× GÑ GÐ Ø )× GÑ GÐ Ø&×AÑAÐ Ø(×EÑEÐ Ø(×EÑEÐ à+3Ð Ô (Ø+3Ð Ô (Ø(0Ð Ô %Ø*2Ð Ô 'Ø*2Ð Ô '÷ Ð r   