
    rh                         d dl mZ d dlZd dlmZ dej                  dedej                  fdZ	 ddej                  d	ej                  d
ej                  dej                  deej                     dedefdZ	y)    )OptionalN)nnhidden_statesn_repreturnc                     | j                   \  }}}}|dk(  r| S | dddddddddf   j                  |||||      } | j                  |||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/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/transformers/integrations/eager_paged.py	repeat_kvr      so    
 2?1D1D.Ehz!!Qa"23::5BUW\^bdlmM  (;e(CT8TT    modulequerykeyvalueattention_maskscalingdropoutc                 h   |j                  dd       }|" |j                  ||| j                  fi |\  }}t        || j                        }	t        || j                        }
t        j                  ||	j                  dd            |z  }|#|d d d d d d d |	j                  d   f   }||z   }t        j                  j                  |dt
        j                        j                  |j                        }t        j                  ||
      }|j                  dd      j                         }||fS )Ncache      )dimdtyper	   )popupdate	layer_idxr   num_key_value_groupstorchmatmul	transposer
   r   
functionalsoftmaxfloat32tor"   
contiguous)r   r   r   r   r   r   r   kwargsr   
key_statesvalue_statesattn_weightscausal_maskattn_outputs                 r   eager_paged_attention_forwardr5      s    JJw%E!U\\#uf.>.>I&I
U3 ; ;<JUF$?$?@L<<z';';Aq'ABWLL!$Q1.D
0@0@0D.D%DE#k1==((2U]](SVVW\WbWbcL,,|\:K''1-88:K$$r   )g        )
typingr   r'   r   Tensorintr   Modulefloatr5    r   r   <module>r<      s      	UU\\ 	U# 	U%,, 	U& %II%<<% 
% <<	%
 U\\*% % %r   