o
    iy                     @   s   d dl mZmZmZ d dlZd dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ er?d dlmZ d d	lmZ neZeZeeZed
 Zed Zed ZeedddG dd dZdS )    )TYPE_CHECKINGAnyLiteralN)
ConfigDictFieldmodel_validator)Self)config)init_logger)	safe_hash)ModelConfig)CacheConfig)autofloat16bfloat16)	             @         i@     )r   r   T)arbitrary_types_allowedc                   @   s   e Zd ZU dZdZeed< 	 edddZe	ed< 	 dZ
eed< 	 d	Ze	d	B ed
< 	 dZejeB ed< 	 d	Zeeef d	B ed< 	 dZeed< 	 dZeed< 	 defddZedddefddZdefddZd	S )
LoRAConfigzConfiguration for LoRA.r   max_lora_rankr   )defaultge	max_lorasFfully_sharded_lorasNmax_cpu_lorasr   
lora_dtypedefault_mm_lorasenable_tower_connector_loraspecialize_active_lorareturnc                 C   s\   g }| | j | | j | | j | | j | | j tt| dd	 }|S )a  
        WARNING: Whenever a new field is added to this config,
        ensure that it is included in the factors list if
        it affects the computation graph.

        Provide a hash that uniquely identifies all the configs
        that affect the structure of the computation
        graph from input ids/embeddings to the final hidden states,
        excluding anything before input ids/embeddings and after
        the final hidden states.
        F)usedforsecurity)
appendr   r   r   r!   r#   r   strencode	hexdigest)selffactorshash_str r.   F/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm/config/lora.pycompute_hashE   s   zLoRAConfig.compute_hashafter)modec                 C   s@   | j d u r| j| _ | S | j | jk rtd| j  d| j d| S )Nzmax_cpu_loras (z) must be >= max_loras (z).)r    r   
ValueError)r+   r.   r.   r/   _validate_lora_config[   s   

z LoRAConfig._validate_lora_configmodel_configc                 C   s8   | j dv r|j| _ d S t| j trtt| j | _ d S d S )N)Nr   )r!   dtype
isinstancer(   getattrtorch)r+   r5   r.   r.   r/   verify_with_model_configg   s
   
z#LoRAConfig.verify_with_model_config)__name__
__module____qualname____doc__r   MaxLoRARanks__annotations__r   r   intr   boolr    r!   r9   r6   	LoRADTyper"   dictr(   r#   r$   r0   r   r   r4   r   r:   r.   r.   r.   r/   r      s,   
 	r   )typingr   r   r   r9   pydanticr   r   r   typing_extensionsr   vllm.config.utilsr	   vllm.loggerr
   vllm.utils.hashingr   vllm.configr   vllm.config.cacher   r;   loggerrC   r?   LoRAExtraVocabSizer   r.   r.   r.   r/   <module>   s$   