Repository navigation
Conversation
Signed-off-by: daiting.qyf <[email protected]>
Contributor
yifanQi98
marked this pull request as draft
October 19, 2026 16:39
1 task done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Beam-search request admission currently materializes all token histories and constructs one CPU tensor per beam even when every stop word is a single token. This PR skips that unused work and initializes the history tensor directly on CUDA for those requests. The shared tensor shape is preserved, including when another request needs multi-token history or triggers buffer growth. Multi-token stops, single-beam requests, and EOS/length handling retain their existing paths. No public setting or API change is introduced.
Fixes #20460
Validation
l0_h100.ymlandl0_b200.yml.pre-commit run --files ...andgit diff --checkpass. The repository's lightweight mypy mode was used because this checkout has no compiled bindings.The final in-tree method also passed an exact-output A/B comparison on Qwen3-0.6B at beam capacity 500: 560 measured calls, two independent LLM startups with AB/BA order, seven cases, 20 measured calls per case/side after five warmups (a separate diagnostic call is not timed). Cases cover a real single-token stop hit, a hit on the second of multiple single-token stops, a non-hit, a multi-token stop hit, mixed requests,
ignore_eos=True, and eight-token VBWS. Every case had one stable full-output hash per side and matching hashes between baseline and candidate. Stop hits were independently verified from the handler'sSTOP_WORDSresult and early output termination. Output comparison includes the API finish-reason labels as returned, including existing rc0 beam-finalization labeling behavior.Runtime scope: changes are based on
mainat9e8e5a270ecd03919f914680581f8c1cc4e5bf25. I cannot build current-main binaries in this environment. GPU validation used TensorRT-LLM 1.4.0rc0, PyTorch 2.14.0+cu132, and an RTX PRO 5000 72GB Blackwell. Before this change, the complete affectedfinish_reasons.pyfile on that main revision and in the installed wheel was byte-identical (SHA-256d3c2323c32d877e04ce51e8c3aed7ff372cd291dc3638ce50e76418156246d50). The candidate method was loaded directly from this PR's source into the test process; installed files were not modified. These results are not a claim that a complete current-main build was tested.Independent performance measurement
Qwen3-0.6B, BF16, public weights revision
c1899de289a04d12100db370d81485cdf75e47ca, beam capacity 500, no other local optimizations. These measurements preceded the in-tree patch and used an isolated prototype of this same early return against the byte-identical rc0 baseline.Six independent pairs of fresh processes, alternating AB/BA; 10 warmups and 60 measured calls per case/condition. CUDA synchronization surrounds the complete
LLM.generatecall. Model initialization, warmup, instrumentation, and output hashing are excluded. Table latencies are means of six per-process medians. The reduction is calculated from the geometric mean of paired ratios, with a paired t interval on six log ratios; repeated calls within a process are not treated as independent replicates. No samples were removed.The 2,880 measured public-model calls had identical output hashes across both conditions for each case; hashes include all returned beam token IDs, beam order, finish reasons, and the cumulative-score field (
Nonewith the benchmark'slogprobs=None; numeric score parity is not measured). These fixed prompts are performance cases, so stop-hit correctness is separately covered above.This is single-client, closed-loop latency measurement, with no fixed QPS or saturated-throughput claim. Submitted batch 2 means two requests per
generate, not guaranteed co-scheduling at every executor step. The savings occur at admission/history reprocessing, not on every decode step, so the percentage benefit decreases as generation work grows. With current request conversion,ignore_eos=Trueclears stop words and does not enter this path; it receives no benefit.Additional validation limitation: fixed-width-4 trials, including 32-token generation, were not internally deterministic even in the unchanged baseline. This also occurred in the
ignore_eos=Truecontrol where this history path is never called, and persisted with overlap disabled. Those runs are retained but are not used as an exact-output equivalence result or a performance claim. Their cause has not been established. Small-beam stop semantics are covered by the deterministic handler tests; model-level exact parity for that regime remains inconclusive. The performance claim above is restricted to the measured wide-beam workloads.Configuration and reproduction
[20, 300, 500]; eight-token VBWS:[20, 20, 20, 20, 20, 20, 300, 500].ignore_eos=False, explicitstop_token_ids=[151643]; the fallback case also suppliesstop="UNLIKELY STOP SEQUENCE 8675309"(13 tokens).The capital of France isandA good way to learn mathematics is(5 and 7 input tokens).max_batch_size=32,max_seq_len=1024,max_num_tokens=1024, KV token budget 128000, block reuse disabled, CUDA Graph batch sizes[1, 2], overlap enabled.--candidate-source, and B with--candidate-source /path/to/this/PR/tensorrt_llm/_torch/pyexecutor/sampler/finish_reasons.py. This optional benchmark-only overlay verifies the baseline source checksum and changes only the test process; it is not part of the runtime patch.Per-process paired medians (ms)
Dev Engineer Review
_get_past_tokensnow returns zero-filled CUDA history for requests with beam width greater than one and a nonempty list of single-token stop words. The returned tensor keeps the handler-wide shape andint32dtype. Other requests retain the existing history path. No public API changes.The optimization is limited to history preparation. QA should verify it with mixed batches and when the handler grows its stop-word buffer. The supplied results report 36 new GPU tests and 16 existing finish-reason tests passing, plus pre-commit and
git diff --check; they also report exact-output parity and latency improvements in the tested variable-beam-width cases. Fixed-width-4 model parity remains inconclusive. These results used TensorRT-LLM 1.4.0rc0, not a build of currentmain. Current review severity counts were not supplied.QA Engineer Review
Added
tests/unittest/_torch/sampler/test_stop_word_history.py. Its tests cover history-read avoidance, tensor shape and dtype, fallback prompt suffixes, single-beam behavior, stop matching, finish-reason precedence, streaming, buffer growth, and slot reuse. The tests require CUDA. No matching entry was found intests/integration/test_lists; this is a unit-test file, not an integration test. Coverage verdict: sufficient for the described behavior and fallback paths.Per-File QA Perspective
tensorrt_llm/_torch/pyexecutor/sampler/finish_reasons.py— Verify that multi-beam requests with only single-token stops use zero history, while multi-token and single-beam requests retain history materialization. Confirm shape preservation when requests share a handler.tests/unittest/_torch/sampler/test_stop_word_history.py— CUDA-gated regression tests cover the new path, fallback paths, matching, precedence, buffer growth, and slot reuse. No integration test-list entry applies to this unit-test file.