Skip to content

Conversation

kris1025
Copy link
Collaborator

@kris1025 kris1025 commented Sep 8, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Enforces consistent sampling when mixed strategies are disabled, preventing unintended mixed behavior and providing a clearer error if strategies conflict.
    • Improves reliability of generation by ensuring a single sampling strategy is applied when required.
  • Tests

    • Expanded coverage to validate both greedy and nucleus sampling paths in speculative decoding, adding scenarios that verify correct behavior across different sampling configurations.

Description

Here are many openai chat tests. It checks if the stream output is equal to non-stream output, so the sampling strategy must be greedy. Thus the default top_p and top_k params should be None.

Test Coverage

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)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • 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

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@kris1025 kris1025 requested a review from a team as a code owner September 8, 2025 09:37
@kris1025 kris1025 requested a review from achartier September 8, 2025 09:37
Copy link
Contributor

coderabbitai bot commented Sep 8, 2025

📝 Walkthrough

Walkthrough

Enforces single-strategy sampling when mixed sampling is disabled in the sampler’s _process_requests; raises on heterogeneous strategies. Mixed-sampler path unchanged. Tests expanded to parameterize greedy vs non-greedy sampling via SamplingParams and verify speculative draft/target behavior under both.

Changes

Cohort / File(s) Summary
Sampler non-mixed strategy enforcement
tensorrt_llm/_torch/pyexecutor/sampler.py
Adds explicit else-branch in _process_requests to assert a single uniform strategy when mixed sampling is disabled; sets batched_strategy accordingly or raises if heterogeneous. Mixed-sampler path unchanged.
Speculative tests parameterization
tests/unittest/_torch/speculative/test_draft_target.py
Extends pytest params with use_greedy_sampling; constructs SamplingParams as greedy (max_tokens only) or non-greedy (max_tokens + top_p) to exercise both paths; rest of test unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Sampler as _process_requests
  participant Mixed as MixedSamplerPath

  Caller->>Sampler: process requests (strategies, mixed_enabled)
  alt mixed sampling enabled
    Sampler->>Mixed: handle mixed strategies
    Mixed-->>Sampler: batched result
    Sampler-->>Caller: return
  else mixed sampling disabled
    Sampler->>Sampler: compute unique strategies
    alt exactly one unique strategy
      Sampler->>Sampler: set batched_strategy = unique
      Sampler-->>Caller: proceed with uniform strategy
    else multiple strategies
      Sampler-->>Caller: raise AssertionError ("mixed sampler is not enabled")
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • schetlur-nv
  • lucaslie
  • nv-yilinf
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
tensorrt_llm/_torch/pyexecutor/sampler.py (2)

300-306: Type alias omits TopKTopP.

Strategy excludes TopKTopP but code handles ("top_k_top_p", …). Align the alias to reflect usage.

-Strategy = TopK | TopP | Greedy
+Strategy = TopK | TopP | TopKTopP | Greedy

1-1: Missing NVIDIA Apache-2.0 header (2025).

Repository guideline requires the header atop source files.

+# Copyright (c) 2025, NVIDIA CORPORATION.  All rights reserved.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
tests/unittest/_torch/speculative/test_draft_target.py (2)

56-60: Undefined name use_greedy_sampling comes from signature mismatch.

Resolved by adding the parameter; no further change needed. Optionally add ids to parametrize for readability.

 @pytest.mark.parametrize(
-    "use_cuda_graph,attn_backend, use_greedy_sampling",
-    [[False, "TRTLLM", True], [True, "TRTLLM", True], [True, "TRTLLM", False]])
+    "use_cuda_graph,attn_backend,use_greedy_sampling",
+    [(False, "TRTLLM", True), (True, "TRTLLM", True), (True, "TRTLLM", False)],
+    ids=["nograph-greedy", "graph-greedy", "graph-top_p"],
+)

1-1: Missing NVIDIA Apache-2.0 header (2025).

Add the standard header.

+# Copyright (c) 2025, NVIDIA CORPORATION.  All rights reserved.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed27a72 and 41c3a5d.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/pyexecutor/sampler.py (1 hunks)
  • tests/unittest/_torch/speculative/test_draft_target.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • tensorrt_llm/_torch/pyexecutor/sampler.py
  • tests/unittest/_torch/speculative/test_draft_target.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

  • tensorrt_llm/_torch/pyexecutor/sampler.py
  • tests/unittest/_torch/speculative/test_draft_target.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • tensorrt_llm/_torch/pyexecutor/sampler.py
  • tests/unittest/_torch/speculative/test_draft_target.py
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/pyexecutor/sampler.py

933-933: Use of assert detected

(S101)

tests/unittest/_torch/speculative/test_draft_target.py

56-56: Undefined name use_greedy_sampling

(F821)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check

@kris1025 kris1025 changed the title fix torch sampler bug [None] [fix] fix torch sampler non-greedy sampling strategy not effected bug Sep 9, 2025
@kris1025
Copy link
Collaborator Author

kris1025 commented Sep 9, 2025

/bot run

@kris1025 kris1025 requested a review from mikeiovine September 9, 2025 03:19
@tensorrt-cicd
Copy link
Collaborator

PR_Github #18139 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18139 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #13595 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

kris1025 commented Sep 9, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18194 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18194 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #13635 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18295 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18295 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #13716 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18314 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18314 [ run ] completed with state FAILURE
/LLM/main/L0_MergeRequest_PR pipeline #13734 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run --reuse-test 18295

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18329 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18329 [ run ] completed with state FAILURE
/LLM/main/L0_MergeRequest_PR pipeline #13746 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18584 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18584 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #13950 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18631 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #18631 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #13989 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19267 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19267 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #14472 completed with status: 'FAILURE'

Signed-off-by: linquanh <[email protected]>
@kris1025
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19334 [ run ] triggered by Bot

@kris1025
Copy link
Collaborator Author

/bot kill

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19479 [ kill ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19479 [ kill ] completed with state SUCCESS
Successfully killed previous jobs for commit 2d23c9e

@kris1025
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19483 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19483 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #14646 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run --reuse-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19529 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19529 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #14679 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run --reuse-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19575 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19575 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #14718 completed with status: 'FAILURE'

@kris1025
Copy link
Collaborator Author

/bot run --reuse-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19668 [ run ] triggered by Bot

@kris1025
Copy link
Collaborator Author

/bot kill

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19685 [ kill ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19668 [ run ] completed with state ABORTED
LLM/main/L0_MergeRequest_PR #14800 (Blue Ocean) completed with status: ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19685 [ kill ] completed with state SUCCESS
Successfully killed previous jobs for commit 2d23c9e

@kris1025
Copy link
Collaborator Author

/bot run --reuse-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #19695 [ run ] triggered by Bot

@kris1025
Copy link
Collaborator Author

kris1025 commented Sep 24, 2025

No longer useful since enable_mixed_sampler is deleted now. The bug has already been fixed in main tot.

@kris1025 kris1025 closed this Sep 24, 2025
@tensorrt-cicd
Copy link
Collaborator

PR_Github #19695 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #14823 completed with status: 'SUCCESS'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants