o
    پiS                     @  s   d dl mZ d dlmZmZ d dlmZmZmZ d dl	Z
d dlmZ d dlmZ er0d dlmZ G dd dZG d	d
 d
ZG dd deZG dd deZG dd deZG dd deZdS )    )annotations)ABCabstractmethod)TYPE_CHECKINGListOptionalN)
ServerArgs)DisaggregationModec                   @  s   e Zd ZU ded< ded< ded< ded< ded< ded< ded	< ded
< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< dS )KVArgsintengine_rank	List[int]kv_data_ptrskv_data_lenskv_item_lensaux_data_ptrsaux_data_lensaux_item_lensstate_data_ptrsstate_data_lensstate_item_lensstr
state_typestate_dim_per_tensor	ib_deviceib_traffic_classgpu_iddecode_tp_sizekv_head_num	page_sizeprefill_pp_sizepp_rankprefill_start_layersystem_dp_rankN)__name__
__module____qualname____annotations__ r(   r(   W/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/disaggregation/base/conn.pyr
      s.   
 r
   c                   @  s    e Zd ZdZdZdZdZdZdS )KVPollr               N)r$   r%   r&   FailedBootstrappingWaitingForInputTransferringSuccessr(   r(   r(   r)   r*   ,   s    r*   c                   @  s"   e Zd ZdZe	ddddZdS )BaseKVManagerz'Base class for managing transfer statesFargsr
   disaggregation_moder	   server_argsr   is_mla_backendOptional[bool]c                 C     d S Nr(   )selfr5   r6   r7   r8   r(   r(   r)   __init__7   s   zBaseKVManager.__init__N)F)r5   r
   r6   r	   r7   r   r8   r9   )r$   r%   r&   __doc__r   r=   r(   r(   r(   r)   r4   4   s
    r4   c                   @  sV   e Zd Zedd
dZedd ddZe	dd!ddZed"ddZedd ZdS )#BaseKVSendermgrr4   bootstrap_addrr   bootstrap_roomr   dest_tp_ranksr   r!   c                 C  r:   r;   r(   )r<   r@   rA   rB   rC   r!   r(   r(   r)   r=   C   s   zBaseKVSender.__init__Nnum_kv_indices	aux_indexOptional[int]c                 C     dS )zz
        Set req's index metadata locally or notify the decoder server about the kv indices length and aux index.
        Nr(   )r<   rD   rE   r(   r(   r)   initM      zBaseKVSender.init
kv_indicesnpt.NDArray[np.int32]state_indicesOptional[List[int]]c                 C  rG   )z
        Send the kv cache at the given kv indices and the extra cache/state at the given indices to the decoder server.
        Nr(   )r<   rJ   rL   r(   r(   r)   sendT   s   	zBaseKVSender.sendreturnr*   c                 C  rG   z<
        Check the status of the kv cache transfer.
        Nr(   r<   r(   r(   r)   poll_   rI   zBaseKVSender.pollc                 C  rG   zD
        Raise an exception if the kv cache transfer fails.
        Nr(   rQ   r(   r(   r)   failure_exceptionf   rI   zBaseKVSender.failure_exception)
r@   r4   rA   r   rB   r   rC   r   r!   r   r;   )rD   r   rE   rF   )rJ   rK   rL   rM   rO   r*   )	r$   r%   r&   r   r=   rH   rN   rR   rT   r(   r(   r(   r)   r?   A   s    	
r?   c                   @  s\   e Zd Ze	dddd	Ze		ddddZedddZedd Zdd Zdd Z	dS ) BaseKVReceiverNr@   r4   rA   r   rB   rF   c                 C  r:   r;   r(   )r<   r@   rA   rB   r(   r(   r)   r=   p   s   zBaseKVReceiver.__init__rJ   rK   rE   rL   rM   c                 C  rG   )z
        Set req's index metadata locally or notify the prefill server about the kv indices, aux index, and state_indices.
        Nr(   )r<   rJ   rE   rL   r(   r(   r)   rH   x   s   
zBaseKVReceiver.initrO   r*   c                 C  rG   rP   r(   rQ   r(   r(   r)   rR      rI   zBaseKVReceiver.pollc                 C  rG   rS   r(   rQ   r(   r(   r)   rT      rI   z BaseKVReceiver.failure_exceptionc                 C  rG   )z,
        Clear any internal states.
        Nr(   rQ   r(   r(   r)   clear      zBaseKVReceiver.clearc                 C  rG   )z-
        Abort the current transfer.
        Nr(   rQ   r(   r(   r)   abort   rX   zBaseKVReceiver.abortr;   )r@   r4   rA   r   rB   rF   )NN)rJ   rK   rE   rF   rL   rM   rU   )
r$   r%   r&   r   r=   rH   rR   rT   rW   rY   r(   r(   r(   r)   rV   n   s    
rV   c                   @  s   e Zd ZedddZdS )	BaseKVBootstrapServerhostr   portr   c                 C  r:   r;   r(   )r<   r[   r\   r(   r(   r)   r=      s   zBaseKVBootstrapServer.__init__N)r[   r   r\   r   )r$   r%   r&   r   r=   r(   r(   r(   r)   rZ      s    rZ   )
__future__r   abcr   r   typingr   r   r   numpynpnumpy.typingnptsglang.srt.server_argsr   sglang.srt.disaggregation.utilsr	   r
   r*   r4   r?   rV   rZ   r(   r(   r(   r)   <module>   s    -1