o
     i1                     @   sv   d dl Z d dlmZ d dlmZmZ d dlZd dlmZ d dlm	Z	 e 
dZeG dd dZG d	d
 d
ejZdS )    N)	dataclass)OptionalTuple)nn)deprecated_functionxformersc                   @   s&   e Zd ZU eed< eed< eed< dS )InputProjectionConfigin_featuresout_featuresbiasN)__name__
__module____qualname__int__annotations__bool r   r   X/home/ubuntu/.local/lib/python3.10/site-packages/xformers/components/input_projection.pyr      s   
 r   c                       sn   e Zd ZdZ	ddedee dee def fddZd	ej	d
ej	dej	de
ej	ej	ej	f fddZ  ZS )InputProjectionz]
    Handle all the input projections in one go, opportunistically fuse some operations.
    Tquery_proj_paramskey_proj_paramsvalue_proj_paramsuse_separate_proj_weightc                    s   t    t|  |j| _t|j|j|j| _|d ur(t|j|j|j| _	n	t
d | j| _	|d urAt|j|j|j| _n	t
d | j| _|sot  | jj| j	_| jj| j_W d    d S 1 shw   Y  d S d S )NzhNo Key projection parameters were passed, assuming that the weights are shared with the query projectionzjNo Value projection parameters were passed, assuming that the weights are shared with the query projection)super__init__r   r
   r   Linearr	   r   q_projk_projloggerinfov_projtorchno_gradweight)selfr   r   r   r   	__class__r   r   r   "   sD   

"zInputProjection.__init__querykeyvaluereturnc                 C   s2   t dd | j| j| jg|||g\}}}|||fS )Nc                 S   s   | |S )Nr   )fnxr   r   r   <lambda>a   s    z)InputProjection.forward.<locals>.<lambda>)mapr   r   r    )r$   r'   r(   r)   qkvr   r   r   forwardV   s   


zInputProjection.forward)T)r   r   r   __doc__r   r   r   r   r!   Tensorr   r2   __classcell__r   r   r%   r   r      s*    	4r   )loggingdataclassesr   typingr   r   r!   r   xformers._deprecation_warningr   	getLoggerr   r   Moduler   r   r   r   r   <module>   s   	
