o
    )i                     @   sR   d dl m Z  d dlmZ d dlmZ d dlmZmZ d dlm	Z	 G dd dZ
dS )	    )copy)Optional)CompletionOutput)RequestOutputKindSamplingParams)IterationStatsc                	   @   s   e Zd ZU dZeed< eed< ee ed< ee	 ed< e
ed< ee ed< dededd	fd
dZde
defddZde
deeef fddZede
fddZdede	deeee	 ef fddZde
fddZeded  dede
fddZd	S )ParentRequestzInfo, state & processing for parallel sampling request.

    Store parent request ID and sampling params.
    Facilitate generating child request sampling params.
    
request_idsampling_paramschild_requestsoutput_aggregatormax_num_generation_tokenscached_child_sampling_paramsreturnNc                 C   sB   || _ || _t | _|jtjkrd g|j ng | _d| _	d | _
d S )Nr   )r	   r
   setr   output_kindr   
FINAL_ONLYnr   r   r   )selfr	   r
    r   l/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/vllm/v1/engine/parallel_sampling.py__init__"   s   
zParentRequest.__init__indexc                 C   sD   | j j}| jr
| jS t| j }d|_|du r|| _|S || |_|S )aS  Efficiently obtain child `sampling_params`

        If `sampling_params.seed` is not `None` then 
        each child request requires a unique clone of
        parent `sampling_params` with a unique seed.

        Args:
          index: index within `n` child requests

        Returns:
          Child `sampling_params` instance.
           N)r
   seedr   r   r   )r   r   r   Zchild_sampling_paramsr   r   r   _get_child_sampling_params.   s   

z(ParentRequest._get_child_sampling_paramsc                 C   s*   | d| j  }| j| || |fS )zGet child request ID and sampling params.
        
        Args:
          index: index within `n` child requests.
        
        Returns:
          (request ID, sampling_params) tuple
        _)r	   r   addr   )r   r   Zchild_req_idr   r   r   get_child_infoM   s   	zParentRequest.get_child_infoc                 C   s   | j jS N)r
   r   )r   r   r   r   r   Z   s   zParentRequest.nchild_request_idcompletion_outputc                 C   sZ   |  r
| j| | jjtjkr|g}n|| j|j< | jr g n| j}| j }| j	||fS r   )
finishedr   remover
   r   r   r   r   r   r	   )r   r    r!   Zoutputsr"   r   r   r   get_outputs^   s   zParentRequest.get_outputsnum_generation_tokensc                 C   s   t || j| _| jS r   )maxr   )r   r%   r   r   r   observe_num_generation_tokensq   s   z+ParentRequest.observe_num_generation_tokens
parent_reqiteration_statsc                 C   sR   | d ur| j nd}| d ur| |}| d u s| js'|j| |j| d S d S )Nr   )r   r'   r   Zmax_num_generation_tokens_iterappendZn_params_iter)r(   r)   r%   Zn_paramr   r   r   observe_finished_requestv   s   z&ParentRequest.observe_finished_request)__name__
__module____qualname____doc__str__annotations__r   r   listr   intr   r   r   tupler   propertyr   boolr$   r'   staticmethodr   r+   r   r   r   r   r      sF   
 



r   N)r   typingr   Zvllm.outputsr   Zvllm.sampling_paramsr   r   Zvllm.v1.metrics.statsr   r   r   r   r   r   <module>   s   