
    -`i!
                         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rd dl
mZ e G d d                      Ze G d d	                      Z G d
 d          Z	 ddee         dedededef
dZdedefdZdS )    )	dataclass)TYPE_CHECKINGAnyOptional)Logprob)LoRARequest)MultiModalDataDictc                       e Zd ZU dZee         ed<   eeeef                  ed<   dZ	e
dz  ed<   dZeed<   dZedz  ed<   dZedz  ed	<   dZeez  dz  ed
<   dZed         ed<   dZeeef         dz  ed<   dS )BeamSearchSequencezA sequence for beam search.
    It keeps track of the tokens and the log probability of the sequence.
    The text field is optional and will only be filled when the sequence is
    about to be returned to the user.
    tokenslogprobsNlora_requestg        cum_logprobtextfinish_reasonstop_reasonr	   multi_modal_datamm_processor_kwargs)__name__
__module____qualname____doc__listint__annotations__dictr   r   r   r   floatr   strr   r   r   r   r   r        d/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/beam_search.pyr   r      s           I4W%&&&&'+L+$+++KD#* $M3:$$$$(KsT!(((7;h34;;;15c3h$.55555r    r   c                   *    e Zd ZU dZee         ed<   dS )BeamSearchOutputzThe output of beam search.
    It contains the list of the best beam search sequences.
    The length of the list is equal to the beam width.
    	sequencesN)r   r   r   r   r   r   r   r   r    r!   r#   r#   "   s0          
 &''''''r    r#   c            
       \    e Zd Z	 	 ddee         dedz  deeeef                  dz  fdZdS )BeamSearchInstanceNprompt_tokensr   r   c                 b    t          d||g nt          |          |d|g| _        g | _        d S )N)r   r   r   r   )r   r   beams	completed)selfr'   r   r   kwargss        r!   __init__zBeamSearchInstance.__init__-   sS      $'/T(^^)  	 0

 46r    )NN)	r   r   r   r   r   r   r   r   r-   r   r    r!   r&   r&   ,   sm         ,048	6 6Cy6 "D(6 tCL)*T1	6 6 6 6 6 6r    r&         ?r   cumulative_logprobeos_token_idlength_penaltyreturnc                 R    t          |           }| d         |k    r|dz  }|||z  z  S )zCalculate the beam search score with length penalty.

    Adapted from

    https://github.com/huggingface/transformers/blob/ccb92be23def445f2afdea94c31286f84b89eb5b/src/transformers/generation/beam_search.py#L938
       )len)r   r/   r0   r1   seq_lens        r!   get_beam_search_scorer8   ?   s7     &kkGbz\!!1.!899r    c                 4     dt           dt          f fd}|S )Nxr2   c                 <    t          | j        | j                  S )N)r8   r   r   )r:   r0   r1   s    r!   sort_beams_keyz6create_sort_beams_key_function.<locals>.sort_beams_keyS   s"    $Ham\>
 
 	
r    )r   r   )r0   r1   r<   s   `` r!   create_sort_beams_key_functionr=   R   s>    
, 
 
 
 
 
 
 
 

 r    N)r.   )dataclassesr   typingr   r   r   vllm.logprobsr   vllm.lora.requestr   vllm.multimodalr	   r   r#   r&   r   r   r   r8   r=   r   r    r!   <module>rC      s   " ! ! ! ! ! / / / / / / / / / / ! ! ! ! ! ! ) ) ) ) ) ) 3222222 6 6 6 6 6 6 6 6& ( ( ( ( ( ( ( (6 6 6 6 6 6 6 6.  	: :I:: : 	:
 : : : :& e      r    