
    .`iR                         d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	  G d de j
                  Z G d d	e          ZdS )
    N)ABCabstractmethod)Iterable)	BlockHash)LoadStoreSpecc                   R     e Zd ZdZdej        fgZ fdZede	fd            Z
 xZS )BlockStatusaW  
    Offloading status for a single block of KV data.
    Holds the following information:

    ref_cnt - the current number of transfers using this block as a source.
        A value of -1 indicates the block is not yet ready to be read.
    load_store_spec - backend-specific information on how to actually
        read/write the block.
    ref_cntc                 V    t                                                       d| _        d S )N)super__init__r
   )self	__class__s    n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/v1/kv_offload/backend.pyr   zBlockStatus.__init__   s$        returnc                     | j         dk    S )z@
        Returns whether the block is ready to be read.
        r   )r
   r   s    r   is_readyzBlockStatus.is_ready   s    
 |q  r   )__name__
__module____qualname____doc__ctypesc_int32_fields_r   propertyboolr   __classcell__)r   s   @r   r	   r	      sz          FN+,H    
 !$ ! ! ! X! ! ! ! !r   r	   c                       e Zd ZdZdedefdZed             Zede	e
         de	e         fd            Zed	efd
            Zdee
         dee         defdZdS )Backendzi
    An abstract class for allocating and returning specs for writing
    KV blocks to some backend.
    
block_sizemediumc                 "    || _         || _        d S )N)r#   r$   )r   r#   r$   s      r   r   zBackend.__init__+   s    $r   c                     dS )zW
        Returns the number of current number of blocks that can be allocated.
        N r   s    r   get_num_free_blockszBackend.get_num_free_blocks/   s	    
 	r   block_hashesr   c                     dS )a  
        Allocate space for writing blocks.
        This method assumes there is enough space for allocation.
        It is unsafe to use without checking get_num_free_blocks beforehand.

        Args:
            block_hashes: the hashes identifying the blocks to be written.

        Returns:
            A list of BlockStatus for the allocated blocks.
            The ref_cnt of each returned item will be -1, meaning the block
            is not yet ready to be read.
        Nr'   )r   r)   s     r   allocate_blockszBackend.allocate_blocks6   s	     	r   blockc                     dS )z
        Free a previously allocated block.
        You should only call this function with blocks returned by
        allocate_blocks, and only once per each block.

        Args:
            block: The block to be freed.
        Nr'   )r   r,   s     r   freezBackend.freeG   s	     	r   blocksc                     t           )aB  
        Get backend-specific information on how to read/write blocks.

        Args:
            block_hashes: the list of block hashes identifying the blocks.
            blocks: the list of blocks.

        Returns:
            A LoadStoreSpec that can be used by a worker
            to read/write the blocks.
        )NotImplementedError)r   r)   r/   s      r   get_load_store_speczBackend.get_load_store_specS   s
     "!r   N)r   r   r   r   intstrr   r   r(   listr   r	   r+   r.   r   r   r2   r'   r   r   r"   r"   %   s         
3        ^ DO [@Q    ^  	+ 	 	 	 ^	"$Y/"9A+9N"	" " " " " "r   r"   )r   abcr   r   collections.abcr   vllm.v1.core.kv_cache_utilsr   vllm.v1.kv_offload.abstractr   	Structurer	   r"   r'   r   r   <module>r;      s     # # # # # # # # $ $ $ $ $ $ 1 1 1 1 1 1 5 5 5 5 5 5! ! ! ! !&" ! ! !4<" <" <" <" <"c <" <" <" <" <"r   