
     `i                         d dl mZ d dlZdej        dedej        f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j        df         fdZ
dS )    )OptionalNhidden_statesn_repreturnc                     | j         \  }}}}|dk    r| S | dddddddddf                             |||||          } |                     |||z  ||          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_dims         x/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/transformers/integrations/sdpa_paged.py	repeat_kvr      s    
 2?1D.Ehzz!!!!QQQaaa"23::5BUW\^bdlmmM  (;e(CT8TTT            modulequerykeyvalueattention_maskdropoutscalingc           	         |                     dd           }|j |j        ||| j        fi |\  }}|                    dd                              d          }|                    dd                              d          }t          | d          r*t          || j                  }t          || j                  }|}	|                                }|                                }|                                }t          j
        j                            ||||	||d          }
|
                    dd                                          }
|
d fS )Ncacher   r   num_key_value_groupsF)	attn_mask	dropout_pscale	is_causal   )popupdate	layer_idx	transpose	unsqueezehasattrr   r   
contiguoustorchnn
functionalscaled_dot_product_attention)r   r   r   r   r   r   r   kwargsr   causal_maskattn_outputs              r   sdpa_attention_paged_forwardr1      sY    JJw%%E!U\#uf.>II&II
UmmAq!!++A..1%%//22 v-.. >V899%!<== !K E
..

CE(%BB C 	 	K ''1--88::Kr   )r   N)typingr   r*   Tensorintr   r+   Modulefloattupler1    r   r   <module>r9      s          	UU\ 	U# 	U%, 	U 	U 	U 	U$ #* *HO*<* 
* <	*
 U\** * e_* 5<* * * * * *r   