o
    :/i_                     @   s   d dl Z d dlmZ d dlmZmZmZ d dlmZ d dl	m
Z
 ed Zed Zeeef Zdefd	d
ZeG dd dZdS )    N)field)AnyLiteralget_args)config)	safe_hash)kv_producerkv_both)kv_consumerr	   returnc                  C   s   ddl m}  | jS )Nr   current_platform)vllm.platformsr   device_typer    r   d/lsinfo/ai/hellotax_ai/llm_service/venv_vllm/lib/python3.10/site-packages/vllm/config/kv_transfer.py kv_buffer_device_default_factory   s   r   c                   @   sP  e Zd ZU dZdZedB ed< 	 dZedB ed< 	 ee	dZ
eed< 	 dZeed< 	 dZedB ed	< 	 dZedB ed
< 	 dZeed< 	 dZeed< 	 dZeed< 	 eedZeeef ed< 	 dZedB ed< 	 dZeed< 	 dZed ed< 	 defddZd%ddZedefddZedefdd Z edefd!d"Z!defd#d$Z"dS )&KVTransferConfigz0Configuration for distributed KV cache transfer.Nkv_connector	engine_id)default_factorykv_buffer_deviceg    eAkv_buffer_sizekv_rolekv_rank   kv_parallel_sizez	127.0.0.1kv_ipi8  kv_portkv_connector_extra_configkv_connector_module_pathFenable_permute_local_kvfail)	recomputer"   kv_load_failure_policyr   c                 C   s    g }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)r   strencode	hexdigest)selffactorshash_strr   r   r   compute_hashK   s   zKVTransferConfig.compute_hashc                 C   sx   | j d u rtt | _ | jd ur%| jttvr%td| j dtt | jd ur8| jd u r:tdtt d S d S )NzUnsupported kv_role: z. Supported roles are zEPlease specify kv_role when kv_connector is set, supported roles are )	r   r&   uuiduuid4r   r   KVRole
ValueErrorr   r)   r   r   r   __post_init__]   s   

zKVTransferConfig.__post_init__c                 C      | j d uo| jttv S N)r   r   r   r/   r1   r   r   r   is_kv_transfer_instancem      z(KVTransferConfig.is_kv_transfer_instancec                 C   r3   r4   )r   r   r   
KVProducerr1   r   r   r   is_kv_producerq   r6   zKVTransferConfig.is_kv_producerc                 C   r3   r4   )r   r   r   
KVConsumerr1   r   r   r   is_kv_consumeru   r6   zKVTransferConfig.is_kv_consumerc                 C   s   | j ||S r4   )r   get)r)   keydefaultr   r   r   get_from_extra_configy   s   z&KVTransferConfig.get_from_extra_config)r   N)#__name__
__module____qualname____doc__r   r&   __annotations__r   r   r   r   r   floatr   r/   r   intr   r   r   dictr   r   r    r!   boolr$   r   r,   r2   propertyr5   r8   r:   r>   r   r   r   r   r      sJ   
 
r   )r-   dataclassesr   typingr   r   r   vllm.config.utilsr   vllm.utils.hashingr   r7   r9   r/   r&   r   r   r   r   r   r   <module>   s   