§
    Ë²Åj4	  ã            
       ó4  — U d Z ddlZddlmZ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dS )zCDefines utilities for interacting with scaled_dot_product_attentioné    N)ÚListÚOptionalÚUnionÚ__all__ÚtensorsÚreturnc                  ó4   — t          d„ | D ¦   «         ¦  «        S )z0Returns True if any of the tensors requires gradc              3   ó$   K  — | ]}|j         V — Œd S )N)Úrequires_grad)Ú.0Úts     úJC:\Projects\Historical\venv\Lib\site-packages\torch/nn/attention/_utils.pyú	<genexpr>z'_input_requires_grad.<locals>.<genexpr>   s$   è è € Ð0Ð0 1ˆqŒÐ0Ð0Ð0Ð0Ð0Ð0ó    )Úany)r   s    r   Ú_input_requires_gradr      s   € åÐ0Ð0¨Ð0Ñ0Ô0Ñ0Ô0Ð0r   Úinpt_tensorÚog_sizec                 óP   — |                       d¦  «        |k    r| dd|…f         S | S )z'Handles the unpad of the last dimensionéÿÿÿÿ.N)Úsize)r   r   s     r   Ú_postprocess_flash_outputr      s4   € à×Ò˜ÑÔ˜wÒ&Ð&Ø˜3   ˜=Ô)Ð)ØÐr   Úhead_dim_sizeÚscalec                 ó8   — |�|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.
    Ng      ð?)Ú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   ç        FÚqueryÚkeyÚvalueÚ	attn_maskc           	      óT  — | j         |j         k    s| j         |j         k    r(t          d| j         › d|j         › d|j         › d�¦  «        ‚| j        |j        k    s| j        |j        k    r(t          d| j        › d|j        › d|j        › d�¦  «        ‚|                      ¦   «         dk     s0|                     ¦   «         dk     s|                     ¦   «         dk     rOt          d	|                      ¦   «         › d
|                     ¦   «         › d|                     ¦   «         › d�¦  «        ‚d S )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_inputr7   *   so  € ð „{�c”iÒÐ 5¤;°%´+Ò#=Ð#=Ýð7Ø$)¤Kð7ð 7Ø>A¼ið7ð 7à %¤ð7ð 7ð 7ñ
ô 
ð 	
ð
 „|�s”zÒ!Ð! U¤\°U´\Ò%AÐ%AÝð9Ø%*¤\ð9ð 9ØADÄð9ð 9à!&¤ð9ð 9ð 9ñ
ô 
ð 	
ð
 ‡y‚y�{„{�Q‚€˜#Ÿ'š'™)œ) aš-˜-¨5¯9ª9©;¬;¸ª?¨?ÝðYØ�yŠy‰{Œ{ðYð YØ'*§w¢w¡y¤yðYð YØBGÇ)Â)Á+Ä+ðYð Yð Yñ
ô 
ð 	
ð ,;¨?r   )Nr+   FN)Ú__doc__r   Útypingr   r   r   Útorchr   ÚstrÚ__annotations__ÚTensorÚboolr   Úintr   Úfloatr   r)   ÚSymIntr*   r7   © r   r   ú<module>rC      sq  ðà IÐ IÐ IØ €€€Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (à €€€ð €ˆˆcŒÐ Ð Ñ ð1 5¤<ð 1°Dð 1ð 1ð 1ð 1ð
¨5¬<ð À#ð È%Ì,ð ð ð ð ð* Cð *°¸´ð *ÀEð *ð *ð *ð *ð BÐAÐAÐ ð%˜5  e¤lÐ!2Ô3ð %¸ð %ð %ð %ð %ð )-ØØØ
ð
ð 
ØŒ<ð
à	Œð
ð Œ<ð
ð ˜œÔ%ð	
ð 
ð 
ð 
ð 
ð 
r   