-
Notifications
You must be signed in to change notification settings - Fork 2k
[TRTLLM-8650][fix] beam search request validation #8433
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
[TRTLLM-8650][fix] beam search request validation #8433
Conversation
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" |
|
PR_Github #21589 [ run ] triggered by Bot |
|
PR_Github #21589 [ run ] completed with state |
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" |
|
PR_Github #21601 [ run ] triggered by Bot |
|
PR_Github #21601 [ run ] completed with state |
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" |
|
PR_Github #21608 [ run ] triggered by Bot |
|
PR_Github #21608 [ run ] completed with state |
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" |
|
PR_Github #21666 [ run ] triggered by Bot |
|
PR_Github #21666 [ run ] completed with state |
|
/bot run --disable-fail-fast --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" |
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" --detailed-log |
|
PR_Github #21680 [ run ] triggered by Bot |
|
PR_Github #21681 [ run ] triggered by Bot |
|
PR_Github #21680 [ run ] completed with state |
|
PR_Github #21681 [ run ] completed with state |
5e1177f to
c42fd3f
Compare
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" --detailed-log |
|
PR_Github #21712 [ run ] triggered by Bot. Commit: |
|
PR_Github #21712 [ run ] completed with state |
7ef2ed8 to
ddbcecf
Compare
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" --detailed-log |
4 similar comments
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" --detailed-log |
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" --detailed-log |
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" --detailed-log |
|
/bot run --stage-list "L40S-PyTorch-1,L40S-PyTorch-2,A30-PyTorch-1,A30-PyTorch-2" --detailed-log |
ddbcecf to
0b006f5
Compare
|
/bot run |
|
PR_Github #21906 [ run ] triggered by Bot. Commit: |
|
@MartinMarciniszyn Could you review this on behalf of |
📝 WalkthroughWalkthroughThis PR refactors beam-width validation from the request queue's filtering stage to the py\_executor's validation layer. The request queue's special item handler now removes beam-width checks and focuses on shutdown and cancellation signals. Concurrently, comprehensive parameter validation tests are added with hardware-aware test behavior for beam search. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Executor as py_executor
participant Queue as executor_queue
rect rgb(220, 240, 255)
note over Client,Queue: Old flow (beam-width in queue)
Client->>Executor: _validate_request()
Executor->>Executor: token range check
Executor-->>Client: validation pass
Client->>Queue: _validate_and_filter_requests()
Queue->>Queue: beam-width check (removed)
Queue-->>Client: filtered requests
end
rect rgb(240, 220, 255)
note over Client,Queue: New flow (beam-width in validator)
Client->>Executor: _validate_request()
Executor->>Executor: beam-width check<br/>(sampling_config.beam_width<br/>vs max_beam_width)
Executor->>Executor: token range check
Executor-->>Client: validation pass/ValueError
Client->>Queue: _handle_special_queue_items()
Queue->>Queue: shutdown/cancellation only
Queue-->>Client: accepted requests
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes The refactoring introduces cohesive changes across production validation layers, but the substantial test additions in test\_beam\_search.py—including hardware-specific branching, fuzzy matching logic, and a new parameter validation test class with multiple assertion patterns—require careful review across heterogeneous test scenarios and dependencies. Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. 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.
Actionable comments posted: 0
🧹 Nitpick comments (5)
tensorrt_llm/_torch/pyexecutor/py_executor.py (2)
1320-1323: Shorten exception message (TRY003) without changing semanticsTrim the message to satisfy linters yet keep tests matching.
- raise ValueError( - f"Request beam width {sampling_config.beam_width} " - f"is not equal to max_beam_width {self.max_beam_width}. This is not supported!" - ) + raise ValueError( + f"Request beam width {sampling_config.beam_width} " + f"is not equal to max_beam_width {self.max_beam_width}" + )
1325-1336: Defensive access to optional multimodal flagAvoid potential AttributeError if py_multimodal_data is missing.
- has_mm = bool(request.py_multimodal_data) + has_mm = bool(getattr(request, "py_multimodal_data", None))tests/unittest/_torch/executor/test_executor_request_queue.py (1)
328-347: Remove stale comment referencing beam validationBeam validation moved to PyExecutor; this unit tests only queue filtering.
- # Create a mock request without sampling_config to avoid beam validation mock_request = Mock() - delattr(mock_request, 'sampling_config') if hasattr( - mock_request, 'sampling_config') else Nonetests/unittest/_torch/sampler/test_beam_search.py (2)
248-267: Use raw regex strings in pytest.raises(match=...) (RUF043)Prefix patterns with r'' to avoid unintended escapes and silence linters.
- with pytest.raises( - ValueError, - match= - ".*Greedy decoding in the LLM API does not allow multiple returns.*" - ): + with pytest.raises( + ValueError, + match=r".*Greedy decoding in the LLM API does not allow multiple returns.*", + ): ... - with pytest.raises( - ValueError, - match= - ".*Greedy decoding in the LLM API does not allow multiple returns.*" - ): + with pytest.raises( + ValueError, + match=r".*Greedy decoding in the LLM API does not allow multiple returns.*", + ): ... - with pytest.raises( - RequestError, - match=".*Request beam width 2 is not equal to max_beam_width 4*" - ): + with pytest.raises( + RequestError, + match=r".*Request beam width 2 is not equal to max_beam_width 4.*", + ):Also applies to: 270-289, 298-309
271-289: Fix test name typoRename “ommitted” -> “omitted” for clarity.
-def test_use_beam_search_ommitted( +def test_use_beam_search_omitted(
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
tensorrt_llm/_torch/pyexecutor/executor_request_queue.py(2 hunks)tensorrt_llm/_torch/pyexecutor/py_executor.py(1 hunks)tests/integration/test_lists/test-db/l0_l40s.yml(1 hunks)tests/unittest/_torch/executor/test_executor_request_queue.py(2 hunks)tests/unittest/_torch/sampler/test_beam_search.py(5 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/executor_request_queue.pytests/unittest/_torch/executor/test_executor_request_queue.pytensorrt_llm/_torch/pyexecutor/py_executor.pytests/unittest/_torch/sampler/test_beam_search.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/executor_request_queue.pytests/unittest/_torch/executor/test_executor_request_queue.pytensorrt_llm/_torch/pyexecutor/py_executor.pytests/unittest/_torch/sampler/test_beam_search.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/executor_request_queue.pytests/unittest/_torch/executor/test_executor_request_queue.pytensorrt_llm/_torch/pyexecutor/py_executor.pytests/unittest/_torch/sampler/test_beam_search.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: dcampora
PR: NVIDIA/TensorRT-LLM#6867
File: tensorrt_llm/_torch/pyexecutor/sampler.py:67-72
Timestamp: 2025-08-13T16:20:37.987Z
Learning: In TensorRT-LLM sampler code, performance is prioritized over additional validation checks. The beam_width helper method intentionally returns the first request's beam_width without validating consistency across all requests to avoid performance overhead from iterating through the entire batch.
🧬 Code graph analysis (4)
tensorrt_llm/_torch/pyexecutor/executor_request_queue.py (2)
tensorrt_llm/executor/executor.py (1)
is_shutdown(289-290)tensorrt_llm/_torch/pyexecutor/llm_request.py (2)
append(79-98)append(125-142)
tests/unittest/_torch/executor/test_executor_request_queue.py (1)
tensorrt_llm/_torch/pyexecutor/executor_request_queue.py (1)
_handle_special_queue_items(453-467)
tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
tensorrt_llm/_torch/pyexecutor/sampler.py (1)
beam_width(78-81)
tests/unittest/_torch/sampler/test_beam_search.py (1)
tensorrt_llm/executor/utils.py (1)
RequestError(76-77)
🪛 Ruff (0.14.0)
tensorrt_llm/_torch/pyexecutor/py_executor.py
1320-1323: Avoid specifying long messages outside the exception class
(TRY003)
tests/unittest/_torch/sampler/test_beam_search.py
258-258: Pattern passed to match= contains metacharacters but is neither escaped nor raw
(RUF043)
280-280: Pattern passed to match= contains metacharacters but is neither escaped nor raw
(RUF043)
300-300: Pattern passed to match= contains metacharacters but is neither escaped nor raw
(RUF043)
🔇 Additional comments (8)
tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
1316-1324: Beam-width guard is correct; keep it per-requestThis enforces uniform beam width before scheduling and complements Sampler.beam_width’s “first-request only” behavior. Good placement. Based on learnings
tensorrt_llm/_torch/pyexecutor/executor_request_queue.py (1)
453-468: Special-item filtering looks goodShutdown/cancel handling is clear and minimal; filtering normal items is correct.
tests/unittest/_torch/sampler/test_beam_search.py (5)
5-9: Imports updated appropriatelyAdding getSMVersion and RequestError aligns tests with hardware gating and API error type.
20-23: Hardware helper LGTMis_l40s() is simple and localized.
27-61: Hardware-aware expectations are fine for nowGiven known nvbugs, the branching expected_outputs is acceptable.
63-69: Centralized FIXED_PARAMS is goodReduces duplication across tests.
1-232: No action required; @force_ampere correctly enables tests on L40SThe
@force_amperedecorator skips tests only when SM < 80 or SM > 89. Since L40S is SM 89 (within the Ampere range), the decorator does not skip this suite on L40S nodes. The test properly handles L40S-specific behavior viais_l40s()and theexpected_outputsfixture already provides hardware-specific assertions for both L40S and other Ampere variants.tests/integration/test_lists/test-db/l0_l40s.yml (1)
17-17: Clarify test duplication across configsThe test file exists and is correctly referenced, but appears in both
l0_l40s.yml(line 17) andl0_a30.yml(line 23). Verify this duplication is intentional (e.g., testing across different hardware SKUs) and not an accidental duplicate that would cause redundant CI runs.
|
PR_Github #21906 [ run ] completed with state |
|
/bot run |
|
PR_Github #21937 [ run ] triggered by Bot. Commit: |
|
PR_Github #21937 [ run ] completed with state |
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Description
Ensure that unsupported request parameters are handled gracefully.
Test Coverage
Relevant tests added.
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
Bug Fixes
Tests