Skip to content

Conversation

@ixlmar
Copy link
Collaborator

@ixlmar ixlmar commented Oct 15, 2025

Description

Changes:

  • Mild refactor of topk-logprobs and batched sampling
  • Reduce number of D2H copies for topk-logprobs
  • Reduce number of D2D copies (removing torch.cat in batched sampling)
  • Remove obsolete code paths in batched sampling
  • Simplify SoftMax logic by batching together requests which do/do not need probs
  • Introduce GroupedStrategySampler ABC to support alternative batching schemes and sampling routines
  • Fix up some type annotations
  • Reformat sampler.py using ruff
  • Move supporting code from sampler.py to new sampling_utils.py

Note: Since GitHub diffs do not annotate moved code, alternative tools might simplify the review process.

Test Coverage

Non-functional change.

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.

Details

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.

Summary by CodeRabbit

  • New Features
    • Added comprehensive sampling utilities module with multiple decoding strategies including top-k, top-p, temperature-based, and combined sampling approaches.
    • Introduced batch sampling functions that return tokens with optional probability distributions.
    • Added grouped sampling abstractions and rejected-token utilities for advanced decoding control.

@ixlmar ixlmar force-pushed the chore/refactor-batched-sampling branch 2 times, most recently from 20d3343 to 89eeeb7 Compare October 15, 2025 14:04
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 15, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21486 [ run ] triggered by Bot

@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 15, 2025

/bot run --disable-fail-fast

@ixlmar ixlmar force-pushed the chore/refactor-batched-sampling branch from 89eeeb7 to f1d7a2d Compare October 15, 2025 14:43
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 15, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21488 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21489 [ ] completed with state ABORTED

@tensorrt-cicd
Copy link
Collaborator

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

@tensorrt-cicd
Copy link
Collaborator

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

@ixlmar ixlmar force-pushed the chore/refactor-batched-sampling branch from f1d7a2d to 8467c5f Compare October 16, 2025 09:11
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 16, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21565 [ run ] triggered by Bot

@ixlmar ixlmar force-pushed the chore/refactor-batched-sampling branch from 8467c5f to fc32e24 Compare October 16, 2025 09:42
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 16, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21566 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

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

@tensorrt-cicd
Copy link
Collaborator

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

@ixlmar ixlmar force-pushed the chore/refactor-batched-sampling branch from fc32e24 to 9233ed2 Compare October 16, 2025 15:19
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 16, 2025

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21591 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21591 [ run ] completed with state DISABLED
L0 testing is limited to prioritized users. User ixlmar is not in the prioritized list. L0 testing cannot be triggered.

@chzblych
Copy link
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21600 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21600 [ run ] completed with state FAILURE

@chzblych
Copy link
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21609 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21609 [ run ] completed with state FAILURE

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: 4

♻️ Duplicate comments (1)
pyproject.toml (1)

38-39: Consolidate file lists to reduce drift across tools.

You added sampler.py and sampling_utils.py consistently. To avoid future misses, prefer a single glob for the directory across isort/yapfignore/autoflake/ruff, e.g., "tensorrt_llm/_torch/pyexecutor/*.py", and then exclude specific files only when needed.

Also applies to: 72-73, 109-111, 156-158

🧹 Nitpick comments (3)
tests/unittest/_torch/sampler/test_torch_sampler.py (1)

40-42: Make xfail strict to catch unexpected passes.

Use strict=True so the suite fails if top_p=0 starts passing and you miss updating docs/checks.

-@pytest.mark.xfail(reason="top_p = 0 disallowed by tensorrt_llm::executor::SamplingConfig")
+@pytest.mark.xfail(reason="top_p = 0 disallowed by tensorrt_llm::executor::SamplingConfig", strict=True)
tests/unittest/_torch/speculative/test_torch_rejection_sampling.py (1)

35-37: Return-type alignment looks good; consider seeding for stability.

Dropping .item() aligns with sample_rejected returning an int. For reproducibility, seed the generator to reduce occasional KL flakiness.

-    generator = torch.Generator()
+    generator = torch.Generator()
+    generator.manual_seed(0)

If sample_rejected is re-exported from a different module, ensure all callsites expect an int (no lingering .item()).

tensorrt_llm/_torch/pyexecutor/sampling_utils.py (1)

156-173: Stability note (optional): torch.sort stability vs comment.

Comment mentions stable=True for exact greedy-equivalence as top_p→0, but torch.sort(...) doesn’t set stable=True here. If you rely on this for bitwise reproducibility, set stable=True (PyTorch 2.0+).

📜 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 bde606f and 9233ed2.

📒 Files selected for processing (7)
  • pyproject.toml (4 hunks)
  • tensorrt_llm/_torch/auto_deploy/shim/demollm.py (1 hunks)
  • tensorrt_llm/_torch/pyexecutor/py_executor.py (1 hunks)
  • tensorrt_llm/_torch/pyexecutor/sampling_utils.py (1 hunks)
  • tensorrt_llm/_torch/speculative/mtp.py (1 hunks)
  • tests/unittest/_torch/sampler/test_torch_sampler.py (1 hunks)
  • tests/unittest/_torch/speculative/test_torch_rejection_sampling.py (1 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:

  • tests/unittest/_torch/speculative/test_torch_rejection_sampling.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/_torch/speculative/mtp.py
  • tensorrt_llm/_torch/auto_deploy/shim/demollm.py
  • tensorrt_llm/_torch/pyexecutor/sampling_utils.py
  • tests/unittest/_torch/sampler/test_torch_sampler.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:

  • tests/unittest/_torch/speculative/test_torch_rejection_sampling.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/_torch/speculative/mtp.py
  • tensorrt_llm/_torch/auto_deploy/shim/demollm.py
  • tensorrt_llm/_torch/pyexecutor/sampling_utils.py
  • tests/unittest/_torch/sampler/test_torch_sampler.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:

  • tests/unittest/_torch/speculative/test_torch_rejection_sampling.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/_torch/speculative/mtp.py
  • tensorrt_llm/_torch/auto_deploy/shim/demollm.py
  • tensorrt_llm/_torch/pyexecutor/sampling_utils.py
  • tests/unittest/_torch/sampler/test_torch_sampler.py
🧬 Code graph analysis (3)
tests/unittest/_torch/speculative/test_torch_rejection_sampling.py (1)
tensorrt_llm/_torch/pyexecutor/sampling_utils.py (1)
  • sample_rejected (222-234)
tensorrt_llm/_torch/auto_deploy/shim/demollm.py (1)
tensorrt_llm/_torch/pyexecutor/sampling_utils.py (2)
  • greedy_search_sampling_batch (183-192)
  • top_k_sampling_batch (78-92)
tensorrt_llm/_torch/pyexecutor/sampling_utils.py (1)
tensorrt_llm/sampling_params.py (1)
  • params_imply_greedy_decoding (337-345)
🔇 Additional comments (3)
tensorrt_llm/_torch/speculative/mtp.py (1)

258-269: Tensor handoff to add_token: verify CPU/tensor expectations.

new_tokens is now a CPU tensor (from host). Ensure add_token(req, new_tokens, ...) accepts a CPU tensor and not a list; otherwise convert inside add_token or here.
Would you like a quick repo scan script to find add_token implementations/usages to confirm?

tensorrt_llm/_torch/auto_deploy/shim/demollm.py (1)

16-16: Import redirect LGTM.

Switching to sampling_utils is consistent with the refactor; no behavioral change.

tensorrt_llm/_torch/pyexecutor/py_executor.py (1)

1208-1215: Guarding iter stats on sample_state None is correct; pass-through BatchState is cleaner.

This avoids NPEs when sampling fails/returns None and keeps stats consistent. LGTM.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21665 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #16325 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@ixlmar ixlmar force-pushed the chore/refactor-batched-sampling branch from 9233ed2 to 828bd35 Compare October 17, 2025 13:30
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 17, 2025

/bot skip --comment "Changes to never invoked code"

@ixlmar ixlmar requested a review from dcaox October 17, 2025 13:32
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 17, 2025

@dcaox I moved the top-k logprobs to a different location and changed it slightly. Please let me know if you see any problems with this.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21708 [ skip ] triggered by Bot. Commit: 828bd35

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21708 [ skip ] completed with state SUCCESS. Commit: 828bd35
Skipping testing for commit 828bd35

@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 20, 2025

/bot skip --comment "No code changes"

1 similar comment
@ixlmar
Copy link
Collaborator Author

ixlmar commented Oct 20, 2025

/bot skip --comment "No code changes"

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21872 [ skip ] triggered by Bot. Commit: da3f007

@tensorrt-cicd
Copy link
Collaborator

PR_Github #21872 [ skip ] completed with state SUCCESS. Commit: da3f007
Skipping testing for commit da3f007

Copy link
Collaborator

@suyoggupta suyoggupta left a comment

Choose a reason for hiding this comment

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

AutoDeploy changes LGTM

@suyoggupta suyoggupta self-requested a review October 20, 2025 08:30
Copy link
Collaborator

@yweng0828 yweng0828 left a comment

Choose a reason for hiding this comment

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

LGTM for the spec tree decoding part.

Copy link
Collaborator

@dcampora dcampora left a comment

Choose a reason for hiding this comment

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

LGTM

@dcampora dcampora merged commit 97ce0ec into NVIDIA:main Oct 20, 2025
5 checks passed
Copy link
Collaborator

@Funatiq Funatiq left a comment

Choose a reason for hiding this comment

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

Overall lgtm.

  • I was wondering if we should move more utility functions like _request_get_sampling_params to a separate file (different than sampling_utils.py).
  • Also TorchSampler has become quite convoluted and we could probably factor out some member functions.

govind-ramnarayan pushed a commit to nv-auto-deploy/TensorRT-LLM that referenced this pull request Oct 21, 2025
yufeiwu-nv pushed a commit to yufeiwu-nv/TensorRT-LLM that referenced this pull request Oct 24, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 1, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
@ixlmar ixlmar deleted the chore/refactor-batched-sampling branch November 14, 2025 18:58
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.

7 participants