Skip to content

[Feature]: Skip unused history for single-token beam stop words #20460

Open

Description

@yifanQi98

🚀 The feature, motivation and pitch

FinishReasonsHandler._get_past_tokens() materializes request.get_tokens(), builds one CPU history tensor per beam, and copies the result to CUDA even when every stop word of a beam-search request is a single token. Matching those stop words only needs the newly generated token.

I propose a small early return for beam-search requests whose nonempty stop-word list contains only single-token words. Allocate zero history directly on CUDA, preserving the handler-wide [max_stop_word_length - 1, max_beam_width] shape. Preserve the existing history path for multi-token stop words and single-beam requests. In mixed batches, shorter stop words are left-padded and their history positions are masked by the existing matcher.

The redundant work remains on main at 9e8e5a270ecd03919f914680581f8c1cc4e5bf25. The affected source file is byte-identical to the installed TensorRT-LLM 1.4.0rc0 file used for validation.

An isolated prototype on Qwen3-0.6B / BF16 / RTX PRO 5000 72GB Blackwell reduced complete LLM.generate latency by 2.89% (3 output tokens, submitted batch 1), 4.17% (3 tokens, batch 2), and 1.64% (8 tokens, batch 2), with beam capacity 500 and variable beam widths. Six independent baseline/candidate process pairs alternated AB/BA order; each case had 10 warmups and 60 timed calls. These are closed-loop latency measurements, not fixed-QPS or saturated-throughput results. A multi-token-stop fallback control showed no measurable gain.

This saves work during request admission/history reprocessing, not at every decode step. It does not change EOS/stop semantics. With the current request conversion, ignore_eos=True clears stop words, so this path is not called and there is no benefit.

Alternatives

Keep the existing implementation; or optimize general multi-token history materialization separately. This proposal keeps the multi-token path unchanged and introduces no public setting or kernel.

Additional context

I have prepared a focused implementation and regression tests covering stop hits/misses, mixed single-/multi-token requests, finish-reason precedence, buffer growth, and slot reuse. I will link the implementation PR here through its issue reference. No API-stability reference change is needed.

Activity

  1. added
    Inference runtime
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Inference runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions