-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[None][fix] Fix llama4 multimodal by skipping request validation #6957
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
📝 WalkthroughWalkthroughAdds a model-specific bypass in PyExecutor._validate_request to skip lm_head and token-range checks when the model is Llama4ForConditionalGeneration and the request contains multimodal data. Also enables a multimodal Llama4 unit test with an image tensor and updated expected output. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PyExecutor
participant Model
Client->>PyExecutor: _validate_request(request, model)
PyExecutor->>Model: is DecoderModelForCausalLM?
alt Model is Llama4ForConditionalGeneration and request has multimodal data
PyExecutor-->>Client: return early (skip lm_head & token-range checks)
else Other models or no multimodal data
PyExecutor->>PyExecutor: check lm_head presence
PyExecutor->>PyExecutor: validate token id ranges
PyExecutor-->>Client: return validation result
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
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: 2
🔭 Outside diff range comments (1)
tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
1-1
: Add NVIDIA copyright header (2025) at the top of the filePer repository guidelines, prepend the NVIDIA copyright header to all Python/C++ sources.
You can add, for example:
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
🧹 Nitpick comments (4)
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py (2)
47-52
: Multimodal test input: make dtype explicit and verify expected formatGood to see the multimodal path exercised. To reduce ambiguity and future flakiness:
- Make the dtype explicit (float32) so preprocessing assumptions are clear.
- If the image preprocessor expects uint8 [0–255], consider using uint8 with value 255. If it expects [0,1] float, the current ones() is fine.
Apply one of the following diffs depending on the preprocessor’s expectation:
- "multi_modal_data": { - "image": [torch.ones(3, 1024, 1024)] - } + "multi_modal_data": { + "image": [torch.ones(3, 1024, 1024, dtype=torch.float32)] + }or, if uint8 is preferred:
- "multi_modal_data": { - "image": [torch.ones(3, 1024, 1024)] - } + "multi_modal_data": { + "image": [(torch.ones(3, 1024, 1024, dtype=torch.uint8) * 255)] + }If needed, I can check the image preprocessor interface in the repo to confirm the expected dtype.
56-58
: Reduce flakiness of the multimodal expected stringThe multimodal output can vary slightly across backends (TRTLLM vs FLASHINFER), seeds, and model variants. Matching a long phrase at 0.9 similarity could still be brittle. Prefer asserting presence of a key token like “white” or relaxing threshold for the multimodal case.
As an example (outside the changed range), you could special-case the multimodal prompt:
# Replace the generic check for the last item (multimodal) with a targeted token check. for idx, (output, expected) in enumerate(zip(outputs, expected_outputs)): output_text = output.outputs[0].text if idx == 2: # multimodal case assert "white" in output_text.lower(), f"Expected color cue 'white' in '{output_text}'" else: assert similar(output_text, expected), f"Expected '{expected}' but got '{output_text}'"Alternatively, lower the threshold for the multimodal case only.
tensorrt_llm/_torch/pyexecutor/py_executor.py (2)
38-38
: Avoid top-level import for model-specific isinstance check; import lazily inside _validate_requestKeeping model-specific imports at top-level increases coupling and potential import-time side effects/cycles. Importing inside the validation method is sufficient and safer.
Apply this diff to remove the top-level import:
-from ..models.modeling_llama import Llama4ForConditionalGeneration
And inline the import inside _validate_request (see next comment for full snippet).
1132-1141
: Consider capability-based check instead of hard-coding classesHard-coding a tuple of classes doesn’t scale. If other multimodal DecoderModelForCausalLM variants are added, they’ll require PRs to update this list.
- Introduce a model capability flag on model instances, e.g., model.supports_multimodal_token_ids or model.skip_token_range_validation, and branch on that.
- Or centralize the check in a small utility so policy isn’t scattered.
Example sketch (outside changed range):
# In modeling_utils.DecoderModelForCausalLM or a shared utils module class DecoderModelForCausalLM(...): # ... skip_token_range_validation: bool = False # default # In Llama4ForConditionalGeneration subclass class Llama4ForConditionalGeneration(DecoderModelForCausalLM): skip_token_range_validation = TrueThen in _validate_request:
if getattr(self.model_engine.model, "skip_token_range_validation", False) and has_mm_payload: returnThis avoids repeated imports and makes future extensions trivial.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
tensorrt_llm/_torch/pyexecutor/py_executor.py
(2 hunks)tests/unittest/_torch/multi_gpu_modeling/test_llama4.py
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py
: Python code must target Python 3.8+
Python indentation: 4 spaces, no tabs
Maintain module namespace in imports (from package.subpackage import foo; then use foo.SomeClass())
Python file names use snake_case
Python class names use PascalCase
Python functions/methods and local variables use snake_case; variables starting with a number get k_ prefix (e.g., k_99th_percentile)
Global variables use G_ prefixed UPPER_SNAKE_CASE (e.g., G_MY_GLOBAL)
Constants use UPPER_SNAKE_CASE in Python
Avoid shadowing variables from outer scopes in Python
Initialize all externally visible members of a Python class in init
Prefer docstrings for interfaces used outside a file; comments for local code
Use Google-style docstrings for classes and functions (Sphinx-parsable)
Document attributes/variables inline with short docstrings
Avoid reflection when simple alternatives exist (e.g., prefer explicit parameters over dict(**locals()))
In try/except, catch the narrowest exceptions possible
For duck-typing with try/except, keep try body minimal and put logic in else
Files:
tensorrt_llm/_torch/pyexecutor/py_executor.py
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh,py}
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
Prepend NVIDIA copyright header (current year) to all source files
Files:
tensorrt_llm/_torch/pyexecutor/py_executor.py
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py
⏰ 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
🔇 Additional comments (1)
tests/unittest/_torch/multi_gpu_modeling/test_llama4.py (1)
4-4
: LGTM: torch import is necessary for multimodal tensor creationThe additional import is appropriate for the new multimodal test.
/bot run |
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 (1)
tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
1132-1141
: Nit: clarify the comment/log to reflect all validations being skipped and guard attribute accessThe early return also bypasses the subsequent
lm_head
presence check, not just token-range validation. Consider tightening the comment/log to reflect that. Also, usinggetattr
makes this resilient if the wrapper changes.Apply this diff:
- # Only skip token‐range checks for Llama4 when the request has multimodal data + # Skip request validation (lm_head presence and token-range) for Llama4 when the request carries multimodal data from ..models.modeling_llama import Llama4ForConditionalGeneration if isinstance(self.model_engine.model, Llama4ForConditionalGeneration): - has_mm = bool(request.py_multimodal_data) + has_mm = bool(getattr(request, "py_multimodal_data", None)) if has_mm: logger.debug( - f"Skipping token-range validation for {type(self.model_engine.model).__name__} " - "(multimodal request)") + f"Skipping request validation (lm_head presence and token-range) for " + f"{type(self.model_engine.model).__name__} (multimodal request)" + ) return
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
tensorrt_llm/_torch/pyexecutor/py_executor.py
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
**/*.py
: Python code must target Python 3.8+
Python indentation: 4 spaces, no tabs
Maintain module namespace in imports (from package.subpackage import foo; then use foo.SomeClass())
Python file names use snake_case
Python class names use PascalCase
Python functions/methods and local variables use snake_case; variables starting with a number get k_ prefix (e.g., k_99th_percentile)
Global variables use G_ prefixed UPPER_SNAKE_CASE (e.g., G_MY_GLOBAL)
Constants use UPPER_SNAKE_CASE in Python
Avoid shadowing variables from outer scopes in Python
Initialize all externally visible members of a Python class in init
Prefer docstrings for interfaces used outside a file; comments for local code
Use Google-style docstrings for classes and functions (Sphinx-parsable)
Document attributes/variables inline with short docstrings
Avoid reflection when simple alternatives exist (e.g., prefer explicit parameters over dict(**locals()))
In try/except, catch the narrowest exceptions possible
For duck-typing with try/except, keep try body minimal and put logic in else
Files:
tensorrt_llm/_torch/pyexecutor/py_executor.py
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh,py}
📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)
Prepend NVIDIA copyright header (current year) to all source files
Files:
tensorrt_llm/_torch/pyexecutor/py_executor.py
🔇 Additional comments (1)
tensorrt_llm/_torch/pyexecutor/py_executor.py (1)
1132-1141
: Scoped Llama4 multimodal bypass looks correct and preserves text-only validationBypassing only when
py_multimodal_data
is present and using a lazy import addresses the earlier feedback and avoids over-broad skips. This should resolve the multimodal assertion while maintaining safety for standard text requests.
PR_Github #15491 [ run ] triggered by Bot |
PR_Github #15491 [ run ] completed with state |
f169dcb
to
d6d2d27
Compare
/bot run |
1 similar comment
/bot run |
PR_Github #15494 [ run ] triggered by Bot |
PR_Github #15494 [ run ] completed with state |
d6d2d27
to
b7f7e15
Compare
/bot run |
PR_Github #15590 [ run ] triggered by Bot |
PR_Github #15590 [ run ] completed with state |
b7f7e15
to
25790c1
Compare
/bot run |
PR_Github #15663 [ run ] triggered by Bot |
PR_Github #15663 [ run ] completed with state |
/bot run |
25790c1
to
bcdb52b
Compare
/bot run |
1 similar comment
/bot run |
PR_Github #15696 [ run ] triggered by Bot |
PR_Github #15699 [ run ] triggered by Bot |
PR_Github #15698 [ run ] triggered by Bot |
PR_Github #15699 [ run ] completed with state |
PR_Github #15696 [ run ] completed with state |
PR_Github #15698 [ run ] completed with state |
/bot run |
PR_Github #15809 [ run ] triggered by Bot |
PR_Github #15809 [ run ] completed with state |
Signed-off-by: Chang Liu (Enterprise Products) <[email protected]>
Signed-off-by: Chang Liu (Enterprise Products) <[email protected]>
bcdb52b
to
1d5feaa
Compare
/bot run |
PR_Github #15825 [ run ] triggered by Bot |
PR_Github #15825 [ run ] completed with state |
/bot run --reuse-test |
PR_Github #15928 [ run ] triggered by Bot |
PR_Github #15928 [ run ] completed with state |
…DIA#6957) Signed-off-by: Chang Liu (Enterprise Products) <[email protected]> Signed-off-by: Yuxin <[email protected]>
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Description
Test Coverage
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 thestage-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.