
    .`i                     >   d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
  G d de          Ze G d d	                      Zd
ej        dej        fdZd Zd Z	 ddedeedf         deedf         dedededz  dedee         dz  deeedz  f         fdZdS )    )	dataclass)EnumN)try_get_optimal_moe_config)next_power_of_2c                       e Zd ZdZdZdZdS )LoRAMappingType         N)__name__
__module____qualname__LANGUAGETOWER	CONNECTOR     j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/lora/layers/utils.pyr   r      s        HEIIIr   r   c                   p    e Zd ZU eedf         ed<   eedf         ed<   dZeed<   ej	        Z
eed<   d ZdS )	LoRAMapping.index_mappingprompt_mappingF
is_prefilltypec                 j    t          | j                  | _        t          | j                  | _        d S N)tupler   r   )selfs    r   __post_init__zLoRAMapping.__post_init__   s.    "4#566#D$788r   N)r   r   r   r   int__annotations__r   boolr   r   r   r   r   r   r   r   r      sp         c?"""#s(O###J+4D/4449 9 9 9 9r   r   
base_layerreturnc                 v   t          | d          r| j        j        S t          | d          r| j        j        S t          | d          r| j        j        S t          | d          r| j        j        S t          | d          r| j        j        S t          | d          r| j        j        S t          d|            )z7Returns the device for where to place the LoRA tensors.weightweight_packedqweight	w2_weightw2_weight_packed
w2_qweightzUnsupported base layer: )	hasattrr&   devicer'   r(   r)   r*   r+   
ValueError)r#   s    r   _get_lora_devicer/       s     z8$$ B ''	_	-	- B'..	Y	'	' B!((	[	)	) 	B#**	/	0	0 B*11	\	*	* B$++@J@@AAAr   c                       fd}|S )zv
    decorator which adds the condition of not using fully sharded loras
    intended to wrap can_replace_layer()
    c                  r    d|v r|                     d          nd}|r|d         j         nd} | i |o|S )NdecorateTlora_config)popfully_sharded_loras)argskwargsr2   	conditioncan_replaces       r   decz+_not_fully_sharded_can_replace.<locals>.dec?   sX    -76-A-A6::j)))tEMW}-AAASW	{D+F++9	9r   r   r9   r:   s   ` r   _not_fully_sharded_can_replacer<   9   s#    : : : : :
 Jr   c                       fd}|S )zl
    decorator which adds the condition of fully sharded loras
    intended to wrap can_replace_layer()
    c                  .     | i |o|d         j         S )Nr3   )r5   )r6   r7   r9   s     r   r:   z'_fully_sharded_can_replace.<locals>.decM   s'    K(((VVM-B-V	
r   r   r;   s   ` r   _fully_sharded_can_replacer?   G   s#    
 
 
 
 

 Jr   op_typew1_shape.w2_shaperanktop_kdtypeMblock_shapec           	      P   t          ||||||                                          }| dv r5t          |                    dd          t	          |                    |d<   nF| dv rBt          dt          |                    dd          t	          |                              |d<   |S )N)fused_moe_lora_w13_shrinkfused_moe_lora_w2_shrinkBLOCK_SIZE_N@   )fused_moe_lora_w13_expandfused_moe_lora_w2_expand   BLOCK_SIZE_K    )r   copymingetr   max)	r@   rA   rB   rC   rD   rE   rF   rG   configs	            r   try_get_optimal_moe_lora_configrW   U   s     ((E5![ 
dff      "%JJ~r**OD,A,A"
 "
~ 
  
 
 "%FJJ~r22OD4I4IJJ"
 "
~ Mr   r   )dataclassesr   enumr   torchtorch.nnnn.vllm.model_executor.layers.fused_moe.fused_moer   vllm.utils.math_utilsr   r   r   Moduler-   r/   r<   r?   strr   r    listdictrW   r   r   r   <module>rc      s   " ! ! ! ! !              U U U U U U 1 1 1 1 1 1    d    9 9 9 9 9 9 9 9B Bu| B B B B2    , %) CHo CHo 	
  :  cT! 
#sTz/     r   