Ë
    [^(hë  ã            
       óf  — U d Z ddlZddlmZmZ ddlZg Zee   e	d<   dej                  defd„Zdej                  d	edej                  fd
„Zdedee   defd„Zg d¢Zdeeej$                  f   defd„Z	 	 	 	 ddej                  dej                  dej                  deej                     fd„Zy)zCDefines utilities for interacting with scaled_dot_product_attentioné    N)ÚOptionalÚUnionÚ__all__ÚtensorsÚreturnc                  ó&   — t        d„ | D «       «      S )z0Returns True if any of the tensors requires gradc              3   ó4   K  — | ]  }|j                   –— Œ y ­w)N)Úrequires_grad)Ú.0Úts     úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/nn/attention/_utils.pyú	<genexpr>z'_input_requires_grad.<locals>.<genexpr>   s   è ø€ Ò0 1ˆq��Ñ0ùs   ‚)Úany)r   s    r   Ú_input_requires_gradr      s   € äÑ0¨Ô0Ó0Ð0ó    Úinpt_tensorÚog_sizec                 ó@   — | j                  d«      |k7  r	| dd|…f   S | S )z'Handles the unpad of the last dimensionéÿÿÿÿ.N)Úsize)r   r   s     r   Ú_postprocess_flash_outputr      s.   € à×Ñ˜Ó˜wÒ&Ø˜3   ˜=Ñ)Ð)ØÐr   Úhead_dim_sizeÚscalec                 ó:   — |�|S dt        j                  | «      z  S )z�
    For FlashAttention we pad the head dimension to be a multiple of 8 so we need to scale the output
    by the original head size and not the padded.
    g      ð?)ÚmathÚsqrt)r   r   s     r   Ú_calculate_scaler      s#   € ð
 ÐØˆØ”—‘˜=Ó)Ñ)Ð)r   )
é   é   é   é   é    é@   é€   é   i   i   Únc                 ó   — | t         v S )z:Returns true if the head dim is supported by FlexAttention)Ú_SUPPORTED_HEAD_DIMS)r&   s    r   Ú_supported_head_dimr)   %   s   € àÔ$Ð$Ð$r   ÚqueryÚkeyÚvalueÚ	attn_maskc           	      óˆ  — | j                   |j                   k7  s| j                   |j                   k7  r3t        d| j                   › d|j                   › d|j                   › d�«      ‚| j                  |j                  k7  s| j                  |j                  k7  r3t        d| j                  › d|j                  › d|j                  › d�«      ‚| j                  «       dk  s&|j                  «       dk  s|j                  «       dk  r?t        d	| j                  «       › d
|j                  «       › d|j                  «       › d�«      ‚y )NzLExpected query, key, and value to have the same dtype, but got query.dtype: z, key.dtype: z, and value.dtype: z	 instead.zSExpected query, key, and value to have the same device type, but got query.device: z, key.device: z, and value.device: r   zUExpected query, key, and value to all be  at least 2 dimensional, but got query.dim: z, key.dim: z and value.dim: )ÚdtypeÚ
ValueErrorÚdeviceÚdim)r*   r+   r,   r-   Ú	dropout_pÚ	is_causalr   s          r   Ú_validate_sdpa_inputr5   *   s"  € ð ‡{�{�c—i‘iÒ 5§;¡;°%·+±+Ò#=Üð$Ø$)§K¡K =°¸c¿i¹i¸[ð I Ø %§¡˜}¨Ið7ó
ð 	
ð
 ‡|�|�s—z‘zÒ! U§\¡\°U·\±\Ò%AÜð%Ø%*§\¡\ N°.ÀÇÁÀð M!Ø!&§¡ ¨ið9ó
ð 	
ð
 ‡y�yƒ{�Q‚˜#Ÿ'™'›) aš-¨5¯9©9«;¸ª?ÜØcØ�y‰y‹{ˆm˜; s§w¡w£y kÐ1AÀ%Ç)Á)Ã+ÀÈiðYó
ð 	
ð ,;r   )Ng        FN)Ú__doc__r   Útypingr   r   Útorchr   ÚlistÚstrÚ__annotations__ÚTensorÚboolr   Úintr   Úfloatr   r(   ÚSymIntr)   r5   © r   r   ú<module>rB      sî   ðâ IÛ ß "ã ð €ˆˆc‰Ó ð1 5§<¡<ð 1°Dó 1ð
¨5¯<©<ð À#ð È%Ï,É,ó ð* Cð *°¸±ð *ÀEó *ò BÐ ð%˜5  e§l¡lÐ!2Ñ3ð %¸ó %ð )-ØØØ
ñ
Ø�<‰<ð
à	�‰ð
ð �<‰<ð
ð ˜Ÿ™Ñ%ô	
r   