o
    i                     @   s   d dl mZ d dlZddlmZ eeZdejde	dejfdd	Z
	
		ddejjdejdejdejdeej dedee dee deejdf fddZdS )    )OptionalN   )logginghidden_statesn_repreturnc                 C   s^   | j \}}}}|dkr| S | dddddddddf |||||} | ||| ||S )z
    This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
    num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
       N)shapeexpandreshape)r   r   batchnum_key_value_headsslenhead_dim r   k/home/ubuntu/maya3_transcribe/venv/lib/python3.10/site-packages/transformers/integrations/sdpa_attention.py	repeat_kv   s
   0r           modulequerykeyvalueattention_maskdropoutscaling	is_causalc           
   	   K   s  | dds| dd d urtd t| dr$t|| j}t|| j}|d ur@|jdkr@|d d d d d d d |jd f }| }| }| }|d u ra|jd d	ko`|d u o`t	| d
d}t
j rpt|t
jrp| }t
jjj|||||||d}	|	d	d }	|	d fS )Noutput_attentionsF	head_maskz`sdpa` attention does not support `output_attentions=True` or `head_mask`. Please set your attention to `eager` if you want any of these features.num_key_value_groups   r   r   r   T)	attn_mask	dropout_pscaler   )getloggerwarning_oncehasattrr   r   ndimr	   
contiguousgetattrtorchjit
is_tracing
isinstanceTensoritemnn
functionalscaled_dot_product_attention	transpose)
r   r   r   r   r   r   r   r   kwargsattn_outputr   r   r   sdpa_attention_forward   s6   
&"	r7   )r   NN)typingr   r+   utilsr   
get_logger__name__r%   r/   intr   r1   Modulefloatbooltupler7   r   r   r   r   <module>   s6    

