Skip to content

[None][chore] Drop the skip_* sampling flags from one-model spec metadata - #17554

Merged
zhaoyangwang-nvidia merged 1 commit into
NVIDIA:mainfrom
zhaoyangwang-nvidia:zhaoyang/unify-skip-sampling-flags
Aug 13, 2026
Merged

[None][chore] Drop the skip_* sampling flags from one-model spec metadata#17554
zhaoyangwang-nvidia merged 1 commit into
NVIDIA:mainfrom
zhaoyangwang-nvidia:zhaoyang/unify-skip-sampling-flags

Conversation

@zhaoyangwang-nvidia

@zhaoyangwang-nvidia zhaoyangwang-nvidia commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Description

SpecMetadata carried skip_temperature / skip_top_k / skip_top_p, recomputed each step from whether any request in the batch used that filter, alongside AdvancedSamplingMode, which expresses the same "disable this filter" intent as deploy-time configuration. The two were introduced independently and never reconciled. This PR removes the skip_* flags.

  • skip_temperature had no reader left. It was a parameter of the sampling op until the FlashInfer sampler refactors ([TRTLLM-13212][refactor] Centralize sampling logic, split backends into isolated modules #15542, [TRTLLM-14198][refactor] Make FlashInfer a hard dependency for the Torch sampler #16160) dropped it from the signature, and the assignment in _scan_one_model_sampling was left behind.
  • skip_top_k / skip_top_p had one reader, in the rejection path, where they selected between passing a tensor and passing None. That choice is made in Python, so CUDA graph capture bakes it in, and unlike is_all_greedy_sample these flags are not part of the graph key: a replayed graph keeps whichever variant capture happened to see, so the per-batch adaptivity the flags suggest does not survive once graphs are enabled. The capture-time override (_force_non_greedy_for_capture) having to force them to False is the same observation from the other side — if they were live at replay, the override would be unnecessary.
  • AdvancedSamplingMode covers the same four sampling sites and, being fixed for the deployment, has no such gap.

Under the default FULL mode a request that sets top_k / top_p now always gets that filter applied. Previously a batch where no request used a filter would skip its kernel, subject to the capture caveat above; a deployment that wants those kernels skipped selects NO_TOPK / NO_TOPP / NO_TOPK_NO_TOPP explicitly. On the eager path this costs two extra kernel launches (~7 us) for batches that use neither filter. Under CUDA graphs there is no change, since the captured graph already contained whatever the capture-time flags selected.

is_all_greedy_sample is unaffected: it is derived from per-request greediness, not from which filters are in use, and stays in the graph key.

Not addressed here: AdvancedSamplingMode is applied at four sampling sites in interface.py, but three further sampling calls bypass it — eagle3_dynamic_tree.py:775 and :883, and dynamic_tree_ops.py:271 — so a deployment using dynamic tree does not get the filter kernels skipped there. skip_* never covered those sites either, so this PR neither improves nor regresses them. Worth a follow-up.

Test Coverage

Validated on H200 NVL (SM 9.0).

  • test_capture_override_leak.py passes (4 cases). It covers the capture-time override path these flags participated in; the three skip_* assertions are dropped and the is_all_greedy_sample assertion, the load-bearing one, stays.
  • End-to-end test_llama_eagle3_rejection_sampling_modes passes (4 cases), covering use_cuda_graph x use_dynamic_tree with temperature=1.0 / top_p=0.9 / top_k=50 so the non-greedy path is exercised.
  • A repository-wide grep confirms no remaining references to the removed flags.
  • Changed-file pre-commit hooks pass.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

…data

SpecMetadata carried skip_temperature / skip_top_k / skip_top_p, recomputed
each step from whether any request in the batch used that filter, alongside
AdvancedSamplingMode which expresses the same "disable this filter" intent as
deploy-time configuration. The two were introduced independently and never
reconciled.

skip_temperature had no reader left: it was a parameter of the sampling op
until the FlashInfer sampler refactors removed it from the signature, leaving
the assignment behind.

skip_top_k / skip_top_p had one reader, in the rejection path, where they
selected between passing a tensor and passing None. That choice is made in
Python, so CUDA graph capture bakes it in, and unlike is_all_greedy_sample
these flags are not part of the graph key -- a replayed graph keeps whichever
variant capture happened to see, so the per-batch adaptivity they suggest does
not hold once graphs are enabled. AdvancedSamplingMode already covers all four
sampling sites and, being fixed for the deployment, has no such gap.

Requests that set top_k / top_p now always get the filter applied under the
default FULL mode; a deployment that wants the kernels skipped selects
NO_TOPK / NO_TOPP / NO_TOPK_NO_TOPP explicitly. The capture-time override no
longer has to force these flags: FULL keeps both filters live, so warmup
captures the complete variant on its own.

is_all_greedy_sample is unaffected -- it is derived from per-request
greediness, not from which filters are in use, and stays in the graph key.

Signed-off-by: ZhaoyangWang <zhaoyangw@nvidia.com>
@zhaoyangwang-nvidia
zhaoyangwang-nvidia marked this pull request as ready for review August 12, 2026 10:13
@zhaoyangwang-nvidia
zhaoyangwang-nvidia requested a review from a team as a code owner August 12, 2026 10:13
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The speculative sampling metadata no longer contains batch-level temperature, top-k, or top-p skip flags. Request normalization retains normalized sampling values and greediness. Rejection sampling resolves filters directly from sampling mode and per-token tensors. Related capture assertions were removed.

Changes

Sampling metadata flow

Layer / File(s) Summary
Request sampling normalization and graph selection
tensorrt_llm/_torch/speculative/interface.py
SpecMetadata removes batch-level sampling skip flags. Request normalization returns sampling values and greediness. All-greedy detection and CUDA-graph warmup behavior remain.
Direct rejection-sampling filter resolution
tensorrt_llm/_torch/speculative/interface.py, tests/unittest/_torch/speculative/test_capture_override_leak.py
Rejection sampling resolves top-k and top-p from advanced_sampling_mode and sliced sampling tensors. Removed tests no longer assert deleted metadata fields.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: bowenfu, yuxianq

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the removal of the skip_* sampling flags from one-model speculative metadata.
Description check ✅ Passed The description explains the motivation, behavior changes, limitations, test coverage, and checklist items with sufficient detail.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tensorrt_llm/_torch/speculative/interface.py (1)

824-828: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the return annotation after removing the skip flags.

_normalize_request_sampling_params returns four values on Lines 820-825, but its annotation on Line 796 still declares a seven-element tuple. Change it to tuple[float, int, float, bool] so type checkers and callers see the correct contract.

Proposed annotation fix
-        ) -> tuple[float, int, float, bool, bool, bool, bool]:
+        ) -> tuple[float, int, float, bool]:

As per coding guidelines, functions must be annotated with precise types.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/speculative/interface.py` around lines 824 - 828, Update
the return annotation of _normalize_request_sampling_params to tuple[float, int,
float, bool], matching its four returned values and the contract consumed by its
callers.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/speculative/interface.py`:
- Around line 1723-1729: Update the direct one-model rejection-sampling flow
around resolve_advanced_sampling_filters and compute_probs_from_logits so
skips_top_p disables filtering without passing None or selecting a different
probability implementation; preserve a graph-safe top_p=1.0 tensor or reuse the
existing top-p kernel. Add token-equivalence coverage for NO_TOPP and
NO_TOPK_NO_TOPP.

---

Outside diff comments:
In `@tensorrt_llm/_torch/speculative/interface.py`:
- Around line 824-828: Update the return annotation of
_normalize_request_sampling_params to tuple[float, int, float, bool], matching
its four returned values and the contract consumed by its callers.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 542aa4ec-dfd6-4a86-a607-d4a0d37eafa1

📥 Commits

Reviewing files that changed from the base of the PR and between 69eea16 and da172ea.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/speculative/interface.py
  • tests/unittest/_torch/speculative/test_capture_override_leak.py
💤 Files with no reviewable changes (1)
  • tests/unittest/_torch/speculative/test_capture_override_leak.py

Comment thread tensorrt_llm/_torch/speculative/interface.py
@zhaoyangwang-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65571 [ run ] triggered by Bot. Commit: da172ea Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65571 [ run ] completed with state SUCCESS. Commit: da172ea
/LLM/main/L0_MergeRequest_PR pipeline #53305 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Ask a member of NVIDIA/trt-llm-ci-approvers to add the label, then re-trigger CI with the same bot command (no rebase needed).

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@zhaoyangwang-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@zhaoyangwang-nvidia
zhaoyangwang-nvidia enabled auto-merge (squash) August 13, 2026 01:49
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65742 [ run ] triggered by Bot. Commit: da172ea Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65742 [ run ] completed with state SUCCESS. Commit: da172ea
/LLM/main/L0_MergeRequest_PR pipeline #53458 completed with status: 'SUCCESS'

CI Report

Link to invocation

@zhaoyangwang-nvidia
zhaoyangwang-nvidia merged commit 21d77d5 into NVIDIA:main Aug 13, 2026
23 checks passed
yihwang-nv pushed a commit to yihwang-nv/TensorRT-LLM that referenced this pull request Aug 18, 2026
…data (NVIDIA#17554)

Signed-off-by: ZhaoyangWang <zhaoyangw@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants