Skip to content

Add optional token-level progress bar to LLM.beam_search using tqdm #19301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion vllm/entrypoints/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def beam_search(
prompts: list[Union[TokensPrompt, TextPrompt]],
params: BeamSearchParams,
lora_request: Optional[Union[list[LoRARequest], LoRARequest]] = None,
use_tqdm: bool = False,
) -> list[BeamSearchOutput]:
"""
Generate sequences using beam search.
Expand All @@ -540,6 +541,7 @@ def beam_search(
of token IDs.
params: The beam search parameters.
lora_request: LoRA request to use for generation, if any.
use_tqdm: Whether to use tqdm to display the progress bar.
"""
# TODO: how does beam search work together with length penalty,
# frequency, penalty, and stopping criteria, etc.?
Expand Down Expand Up @@ -602,7 +604,20 @@ def create_tokens_prompt_from_beam(
**mm_kwargs,
), )

for _ in range(max_tokens):
token_iter = range(max_tokens)
if use_tqdm:
token_iter = tqdm(range(max_tokens),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
token_iter = tqdm(range(max_tokens),
token_iter = tqdm(token_iter,

desc="Beam search",
unit="token",
unit_scale=False)
warnings.warn(
"The progress bar shows the upper bound on token steps and "
"may finish early due to stopping conditions. It does not "
"reflect instance-level progress.",
stacklevel=2,
)

for _ in token_iter:
all_beams: list[BeamSearchSequence] = list(
sum((instance.beams for instance in instances), []))
pos = [0] + list(
Expand Down