Skip to content

vllm.entrypoints.generate.beam_search.utils

Classes:

Functions:

BeamSearchOutput dataclass

The 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.

BeamSearchSequence dataclass

A 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.

_build_encoder_decoder_inputs(prompt)

Rebuild the encoder-decoder inputs with the current beam search sequence's tokens.

FIXME (alex) - the encoder multimodal cache is not properly wired up yet, which means that currently we are running the encoder on every new beam because num_computed_tokens is 0 on each new request. This will be fixed once the cache is correctly implemented.

get_beam_search_eos_token_ids(generation_config, eos_token_id)

Return the token ids that end generation: the tokenizer EOS plus the generation config's eos_token_id.

This uses a separate SamplingParams so the params sent to the engine keep their own stop_token_ids and are validated as before.

get_beam_search_score(num_generated_tokens, cumulative_logprob, length_penalty=1.0)

Calculate the beam search score with length penalty.

Like Transformers, the length counts the generated tokens, including a terminating EOS token. Adapted from

https://github.com/huggingface/transformers/blob/09a71e5b32a747dbc7805599457e67c956ef212f/src/transformers/generation/utils.py#L3531