-
Notifications
You must be signed in to change notification settings - Fork 2k
[TRTLLM-8436][feat] batched sampling and top-k logprobs improvements #8398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
20d3343 to
89eeeb7
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #21486 [ run ] triggered by Bot |
|
/bot run --disable-fail-fast |
89eeeb7 to
f1d7a2d
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #21488 [ run ] triggered by Bot |
|
PR_Github #21489 [ ] completed with state |
|
PR_Github #21486 [ run ] completed with state |
|
PR_Github #21488 [ run ] completed with state |
f1d7a2d to
8467c5f
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #21565 [ run ] triggered by Bot |
8467c5f to
fc32e24
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #21566 [ run ] triggered by Bot |
|
PR_Github #21565 [ run ] completed with state |
|
PR_Github #21566 [ run ] completed with state |
fc32e24 to
9233ed2
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #21591 [ run ] triggered by Bot |
|
PR_Github #21591 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #21600 [ run ] triggered by Bot |
|
PR_Github #21600 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #21609 [ run ] triggered by Bot |
|
PR_Github #21609 [ run ] completed with state |
There was a problem hiding this 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
📒 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.pytensorrt_llm/_torch/pyexecutor/py_executor.pytensorrt_llm/_torch/speculative/mtp.pytensorrt_llm/_torch/auto_deploy/shim/demollm.pytensorrt_llm/_torch/pyexecutor/sampling_utils.pytests/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.pytensorrt_llm/_torch/pyexecutor/py_executor.pytensorrt_llm/_torch/speculative/mtp.pytensorrt_llm/_torch/auto_deploy/shim/demollm.pytensorrt_llm/_torch/pyexecutor/sampling_utils.pytests/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.pytensorrt_llm/_torch/pyexecutor/py_executor.pytensorrt_llm/_torch/speculative/mtp.pytensorrt_llm/_torch/auto_deploy/shim/demollm.pytensorrt_llm/_torch/pyexecutor/sampling_utils.pytests/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.
|
PR_Github #21665 [ run ] completed with state |
Signed-off-by: ixlmar <[email protected]>
9233ed2 to
828bd35
Compare
|
/bot skip --comment "Changes to never invoked code" |
|
@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. |
|
PR_Github #21708 [ skip ] triggered by Bot. Commit: |
|
PR_Github #21708 [ skip ] completed with state |
Signed-off-by: ixlmar <[email protected]>
|
/bot skip --comment "No code changes" |
1 similar comment
|
/bot skip --comment "No code changes" |
|
PR_Github #21872 [ skip ] triggered by Bot. Commit: |
|
PR_Github #21872 [ skip ] completed with state |
suyoggupta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AutoDeploy changes LGTM
yweng0828
left a comment
There was a problem hiding this 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.
dcampora
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Funatiq
left a comment
There was a problem hiding this 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_paramsto a separate file (different thansampling_utils.py). - Also
TorchSamplerhas become quite convoluted and we could probably factor out some member functions.
…VIDIA#8398) Signed-off-by: ixlmar <[email protected]>
…VIDIA#8398) Signed-off-by: ixlmar <[email protected]> Signed-off-by: yufeiwu-nv <[email protected]>
…VIDIA#8398) Signed-off-by: ixlmar <[email protected]>
…VIDIA#8398) Signed-off-by: ixlmar <[email protected]>
…VIDIA#8398) Signed-off-by: ixlmar <[email protected]>
…VIDIA#8398) Signed-off-by: ixlmar <[email protected]>
Description
Changes:
torch.catin batched sampling)GroupedStrategySamplerABC to support alternative batching schemes and sampling routinessampler.pyusingruffsampler.pyto newsampling_utils.pyNote: 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 thestage-listparameter 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.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip 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-pipelineReuse 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