+
    ÐåûjÖ
  ã                   ór   a € R t
0 t R t^ RIt^ RIt. t] ^ k R R ltR R ltR R ltR R	 ltRR
 R llt	R# )zCDefines utilities for interacting with scaled_dot_product_attentionNc                ó~   € V ^8„  d   QhR\         P                  R\        \        R3,          R\         P                  /# )é   ÚqueryÚshape.Úreturn)ÚtorchÚTensorÚtupleÚint)Úformats   "ÚUC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\torch\nn\attention\_utils.pyÚ__annotate__r      s9   € ÷ Wñ WÜ�<‰<ðWÜ %¤c¨3 h¥ðWä
‡\�\ñWó    c                óp  a € \        S P                  4      V8X  d   \        P                  ! S 4      # \	        \        S P                  4       4      V 3R lR7      p^ .\        V4      ,          p^pV F  pWCV&   WAV,          ,          pK  	  \        P                  ! WS P                  S P                  R7      # )z4Allocate an output with the query's dimension order.c                 óŒ   <€ SP                  4       V ,          '       d   SP                  4       V ,          # \        P                  # ©N)ÚstrideÚmathÚinf)Úidxr   s   &€r   Ú<lambda>Ú-_empty_with_matching_layout.<locals>.<lambda>   s,   ø€ ¨u¯|©|«~¸c×/BÔ/B˜Ÿ™› sÕ+ÐPÌÏÉÐPr   )Úkey)ÚdtypeÚdevice)r	   r   r   Ú
empty_likeÚsortedÚrangeÚdimÚlenÚempty_stridedr   r   )r   r   Ú
fill_orderÚstridesr   r   s   f&    r   Ú_empty_with_matching_layoutr#      s•   ø€ ô ˆU�[‰[Ó˜UÔ"Ü×Ò Ó&Ð&äÜˆe�i‰i‹kÓÜPô€Jð ˆc”C˜
“OÕ#€GØ€FÛˆØ�‰Ø˜•*ÕŠñ ô ×Ò˜u°U·[±[ÈÏÉÔVÐVr   c                óD   € V ^8„  d   QhR\         P                  R\        /# )r   Útensorsr   )r   r   Úbool)r   s   "r   r   r      s   € ÷ 1ñ 1¤5§<¡<ð 1´Dñ 1r   c                 ój   € \         ;QJ d    R V  4       F  '       g   K   R# 	  R# ! R V  4       4      # )z0Returns True if any of the tensors requires gradc              3   ó8   "  € T F  qP                   x € K  	  R # 5ir   )Úrequires_grad)Ú.0Úts   & r   Ú	<genexpr>Ú'_input_requires_grad.<locals>.<genexpr>!   s   é € Ð0© 1�Ž«ùs   ‚TF)Úany)r%   s   *r   Ú_input_requires_gradr/      s+   € ç‹3Ñ0©Ó0�3Œ3Ð0Š3Ð0ˆ3Ñ0©Ó0Ó0Ð0r   c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# )r   Úinpt_tensorÚog_sizer   )r   r   r
   )r   s   "r   r   r   $   s)   € ÷ ñ ¬5¯<©<ð Ä#ð Ì%Ï,É,ñ r   c                óL   € V P                  R4      V8w  d   V RRV13,          # V # )z'Handles the unpad of the last dimension.Néÿÿÿÿ)Úsize)r1   r2   s   &&r   Ú_postprocess_flash_outputr6   $   s.   € à×Ñ˜Ó˜wÔ&Ø˜3   ˜=Õ)Ð)ØÐr   c                óJ   € V ^8„  d   QhR\         R\        R,          R\        /# )r   Úhead_dim_sizeÚscaleNr   )r
   Úfloat)r   s   "r   r   r   +   s%   € ÷ *ñ *¤Cð *´¸µð *Äñ *r   c                óH   € Ve   V# R\         P                  ! V 4      ,          # )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      ð?)r   Úsqrt)r8   r9   s   &&r   Ú_calculate_scaler=   +   s#   € ð
 ÒØˆØ”—’˜=Ó)Õ)Ð)r   c          
      óª   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R,          RR/# )r   r   r   ÚvalueÚ	attn_maskNr   )r   r   )r   s   "r   r   r   5   sO   € ÷ 
ñ 
Ü�<‰<ð
ä	�‰ð
ô �<‰<ð
ô �|‰|˜dÕ"ð	
ð 
ñ
r   c           	      ó¶  € V'       gj   V P                   VP                   8w  g   V P                   VP                   8w  d4   \        R V P                    RVP                    RVP                    R24      hV P                  VP                  8w  g   V P                  VP                  8w  d4   \        RV P                   RVP                   RVP                   R24      hV P                  4       ^8  g+   VP                  4       ^8  g   VP                  4       ^8  d@   \        RV P                  4        RVP                  4        R	VP                  4        R24      hR
# )zLExpected 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: zUExpected query, key, and value to all be  at least 2 dimensional, but got query.dim: z, key.dim: z and value.dim: N)r   Ú
ValueErrorr   r   )r   r   r?   r@   Ú	dropout_pÚ	is_causalr9   Úallow_lowp_kvs   &&&&&&&&r   Ú_validate_sdpa_inputrF   5   s%  € ÷ Ø�;‰;˜#Ÿ)™)Ô# u§{¡{°e·k±kÔ'AÜð(Ø(-¯© }°MÀ#Ç)Á)Àð M$Ø$)§K¡K =°	ð;óð ð
 ‡|�|�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   c                óV   € V ^8„  d   Qh/ ^ \         9   d   \        \        ,          ;R&   # )r   Ú__all__)Ú__conditional_annotations__ÚlistÚstr)r   s   "r   r   r      s   € × IÑ I÷ Ò ŒŒc�Ñ ò Jr   )Ng        FNF)rI   Ú__doc__r   r   rH   r#   r/   r6   r=   rF   r   )rI   s   @r   Ú<module>rM      s8   øðæ Iã ã ð €Ó õWõ&1õ
õ*÷
ñ 
r   