Skip to content

[Bugfix] Correct prompt lengths for timed_traces benchmark - #45423

Merged
tdoublep merged 3 commits into
vllm-project:mainfrom
s3woz:timed_trace_fix
Aug 13, 2026
Merged

[Bugfix] Correct prompt lengths for timed_traces benchmark#45423
tdoublep merged 3 commits into
vllm-project:mainfrom
s3woz:timed_trace_fix

Conversation

@s3woz

@s3woz s3woz commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Purpose

#39795 introduced timed_traces support for vllm bench serve. The traces look as follows:

{"timestamp": 0, "input_length": 6758, "output_length": 500, "hash_ids": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]}
{"timestamp": 0, "input_length": 7322, "output_length": 490, "hash_ids": [0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]}
{"timestamp": 0, "input_length": 7236, "output_length": 794, "hash_ids": [0, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41]}
{"timestamp": 0, "input_length": 2290, "output_length": 316, "hash_ids": [0, 42, 43, 44, 45]}

Current implementation creates prompts with these input_lengths, and then runs:

prompt = tokenizer.decode(prompt_ids)
[...]
samples.append(
    SampleRequest(
        prompt=prompt,
        prompt_len=prompt_len,

vLLM engine on the server side runs:

prompt_idx = tokenizer.encode(prompt)

Unfortunately, tokenizer logic is not idempotent, so whereas the client generates requests of length 6758, 7322, 7236, 2290, etc., the server receives requests of different length 7253, 7844, 7679, 2445, etc.

Solution: Avoid calling .decode and .encode
The OpenAI API and vLLM engine support direct tokens id passing, see:
vllm/entrypoints/openai/completion/protocol.py

class CompletionRequest(OpenAIBaseModel):
    # Ordered by official OpenAI API documentation
    # https://platform.openai.com/docs/api-reference/completions/create
    model: str | None = None
    prompt: (
        list[Annotated[int, Field(ge=0)]]
        | list[list[Annotated[int, Field(ge=0)]]]
        | str
        | list[str]
        | None
    ) = None

This PR avoids the .encode() to directly pass token ids, maintaining correct prompt lengths on the server side.

Test Plan

Just run any of the traces sequentially (--max-concurrency 1) :

vllm bench serve \
 --model Qwen/Qwen3.5-0.8B \
 --dataset-name timed_trace \
 --num-prompts 50 \
 --dataset-path conversation_trace_optimal_store_and_prefix_match.jsonl \
 --base-url http://localhost:12305 \
 --ignore-eos \
 --self-timed \
 --timed-trace-label-timestamp timestamp \
 --timed-trace-chunk-hash-size 512 \
 --timed-trace-label-hash-ids hash_ids \
 --timed-trace-label-input-length input_length \
 --timed-trace-label-output-length output_length \
 --timed-trace-sec-multiplier 0.001 --max-concurrency 1
  • vLLM serve in debug mode:
vllm serve --port 12305 --enable-prefix-caching --model Qwen/Qwen3.5-0.8B

and observe request.num_tokens in vllm/v1/core/sched/scheduler.py::Scheduler.schedule

Test Result

Json file input_lengths: 6758, 7322, 7236, 2290, ...

Main:
For consecutive scheduling rounds, request.num_tokens=7253, 7844, 7679, 2445,...

This PR:
For consecutive scheduling rounds, request.num_tokens=6758, 7322, 7236, 2290, ...
-- as expected

@animeshtrivedi @tdoublep

Signed-off-by: Stanislaw Wozniak <stw@zurich.ibm.com>
@mergify mergify Bot added performance Performance-related issues bug Something isn't working labels Jun 12, 2026
Comment thread vllm/benchmarks/datasets/datasets.py
Co-authored-by: Thomas Parnell <tpa@zurich.ibm.com>
Signed-off-by: Stanislaw Wozniak <stw@zurich.ibm.com>

@tdoublep tdoublep left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@tdoublep tdoublep added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 13, 2026
@tdoublep

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

@s3woz, CI is now available for this PR.

  • /ci run starts a CI build.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /ci cancel cancels scheduled or running CI builds for this PR branch.

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #83725 for commit d675770f521f.

@tdoublep

Copy link
Copy Markdown
Member

/ci run

@tdoublep
tdoublep enabled auto-merge (squash) August 13, 2026 19:46
@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #83790 for commit 9ff854152ae4.

@tdoublep
tdoublep merged commit 6355051 into vllm-project:main Aug 13, 2026
61 checks passed
Alessandra005 pushed a commit to Alessandra005/vllm that referenced this pull request Aug 17, 2026
…ect#45423)

Signed-off-by: Stanislaw Wozniak <stw@zurich.ibm.com>
Co-authored-by: Thomas Parnell <tpa@zurich.ibm.com>
Signed-off-by: Alessandra005 <aurib032@fiu.edu>
zyp2014 pushed a commit to zyp2014/vllm that referenced this pull request Aug 21, 2026
…ect#45423)

Signed-off-by: Stanislaw Wozniak <stw@zurich.ibm.com>
Co-authored-by: Thomas Parnell <tpa@zurich.ibm.com>
wyettzeng pushed a commit to wyettzeng/vllm that referenced this pull request Aug 21, 2026
…ect#45423)

Signed-off-by: Stanislaw Wozniak <stw@zurich.ibm.com>
Co-authored-by: Thomas Parnell <tpa@zurich.ibm.com>
Signed-off-by: Wyett <wyettzeng@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working performance Performance-related issues ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants