ó
    pyüiy  ã                   óØ  • S SK r SSKJrJr  SSKJr  \R                  " \5      r\" 5       r	S\ R                  S\ R                  R                  S\ R                  4S jr      SS\ R                  R                  S\ R                  S	\ R                  S
\ R                  S\ R                  S-  S\S\S-  S\S-  S\S-  S\S-  S\ R                  S-  S\\ R                  S4   4S jjrg)é    Né   )Ú_flash_attention_forwardÚ!flash_attn_supports_top_left_mask)ÚloggingÚqueryÚmoduleÚreturnc                 ól  • U R                   [        R                  :X  a–  [        R                  " S5      (       a  [        R                  " S5      $ [        UR                  S5      (       a  UR                  R                   $ [        S UR                  5        5       5      R                  R                   $ g)ziIf the query is in float32, return a target dtype compatible with flash attention. Return None otherwise.ÚcudaÚ_is_quantizedc              3   ó|   #   • U  H2  n[        U[        R                  R                  5      (       d  M.  Uv •  M4     g 7f)N)Ú
isinstanceÚtorchÚnnÚLinear)Ú.0Úlayers     Úf/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/integrations/flash_attention.pyÚ	<genexpr>Ú#get_target_dtype.<locals>.<genexpr>   s*   é € ÐbÒ+; %¼zÈ%ÔQV×QYÑQY×Q`ÑQ`×?aŸ™Ò+;ùs   ‚-<³	<N)
Údtyper   Úfloat32Úis_autocast_enabledÚget_autocast_dtypeÚhasattrÚconfigÚnextÚmodulesÚweight)r   r   s     r   Úget_target_dtyper       s|   € à‡{�{”e—m‘mÓ#Ü×$Ò$ V×,Ñ,Ü×+Ò+¨FÓ3Ð3ä�V—]‘] O×4Ñ4Ø—=‘=×&Ñ&Ð&äÑb¨6¯>©>Ô+;ÓbÓb×iÑi×oÑoÐoØó    ÚkeyÚvalueÚattention_maskÚdropoutÚscalingÚsliding_windowÚsoftcapÚ	is_causalÚs_auxc                 óX  • UR                  SS5      (       a  [        R                  S5        UR                  S   n[	        S UR                   5       5      (       a  [        S5      eUR                  SS5      nUR                  SS5      nUR                  SS5      n[        X5      nU	b  U	OU R                  n	[        UUUU4UU	UUUU[        UU R                  R                  [        U S5      (       a  U R                  OS U
b  U
R                  UR                   5      OS S	.UD6nUS 4$ )
NÚoutput_attentionsFz‚Flash Attention does not support `output_attentions=True`. Please set your attention to `eager` if you want any of these features.r   c              3   ó*   #   • U  H	  oS :H  v •  M     g7f)r   N© )r   Údims     r   r   Ú*flash_attention_forward.<locals>.<genexpr>0   s   é € Ð
+š{˜�!Ž8š{ùs   ‚z•Tensor query has shape  with a zero dimension.
FlashAttention does not support inputs with dim=0.
Please check your input shapes or use SDPA instead.é   Ú	layer_idx)Úquery_lengthr)   r%   Úsoftmax_scaler'   r(   Úuse_top_left_maskÚtarget_dtypeÚattn_implementationr2   r*   )ÚgetÚloggerÚwarning_onceÚshapeÚanyÚ
ValueErrorÚ	transposer    r)   r   Ú_use_top_left_maskr   Ú_attn_implementationr   r2   Útor   )r   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   ÚkwargsÚseq_lenr6   Úattn_outputs                  r   Úflash_attention_forwardrE      s@  € ð ‡z�zÐ% u×-Ñ-Ü×ÑðWô	
ð �k‰k˜!‰n€Gä
Ñ
+˜uŸ{š{Ó
+×+Ñ+ÜðBó
ð 	
ð �O‰O˜A˜qÓ!€EØ
�-‰-˜˜1Ó
€CØ�O‰O˜A˜qÓ!€Eô $ EÓ2€Lð 'Ñ2‘	¸×8HÑ8H€Iä*ØØØØð	ð
 ØØØØ%ØÜ,Ø!Ø"ŸM™M×>Ñ>Ü&-¨f°k×&BÑ&B�&×"Ò"Èð Ñ ð �H‰H�U—[‘[Ô!àñ%ð( ñ)€Kð. ˜ÐÐr!   )g        NNNNN)r   Úmodeling_flash_attention_utilsr   r   Úutilsr   Ú
get_loggerÚ__name__r9   r?   ÚTensorr   ÚModuler   r    ÚfloatÚintÚboolÚtuplerE   r.   r!   r   Ú<module>rP      s1  ðÛ ç hÝ ð 
×	Ò	˜HÓ	%€á6Ó8Ð ð
˜EŸL™Lð 
°%·(±(·/±/ð 
ÀeÇkÁkô 
ð& Ø Ø!%Ø Ø!Ø!%ñCØ�H‰H�O‰OðCà�<‰<ðCð 
�‰ðCð �<‰<ð	Cð
 —L‘L 4Ñ'ðCð ðCð �T‰\ðCð ˜$‘JðCð �T‰\ðCð �d‰{ðCð �<‰<˜$ÑðCð ˆ5�<‰<˜ÐÑöCr!   