-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[TRTLLM-7328][feat] E-PD Disagg Support via llmapi (3/N) #7577
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 MultimodalDisaggParams to the public API and rewires multimodal handling to a disaggregated model: executor/result and llmapi/llm store/pass multimodal_disagg_params, LLaVA Next resolves uncached multimodal embeddings mid-forward, and tests shift from explicit embedding handles to passing disaggregated params, including new multi-request batch coverage. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant LLM as BaseLLM.generate/generate_async
participant Encoder as MM Encoder (optional)
participant Exec as Executor/Runtime
rect rgba(200,230,255,0.3)
note over Client,LLM: Disaggregated multimodal setup
Client->>Encoder: encode(media...) [optional]
Encoder-->>Client: MultimodalDisaggParams{mm_embedding_handles=[...], multimodal_input,...}
Client->>LLM: generate(inputs, multimodal_disagg_params)
end
alt MM-LLM context-only path
LLM->>LLM: validate single mm_embedding_handle
LLM->>Exec: submit request with MultimodalParams{multimodal_input, fused embed}, prompt=None
else Standard path
LLM->>Exec: submit request with prompt_token_ids/multimodal_params as usual
end
Exec-->>Client: RequestOutput{multimodal_disagg_params,...}
sequenceDiagram
autonumber
participant Model as LlavaNextModel.forward
participant Utils as modeling_multimodal_utils
Model->>Model: assemble mm_embeds
Model->>Utils: find_uncached_mm_embeds(mm_embeds, multimodal_params[:num_ctx])
Utils-->>Model: updated/resolved embeds
Model->>Model: fuse_input_embeds(...)
Model-->>Model: continue forward pass
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
✨ 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. 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: 8
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
tests/unittest/_torch/multimodal/test_mm_encoder_standalone.py (1)
62-66
: Stabilize generation for exact-equality assertions.Set deterministic sampling to reduce flakiness in CI.
- sampling_params = SamplingParams(max_tokens=max_tokens) + sampling_params = SamplingParams( + max_tokens=max_tokens, temperature=0.0, top_p=1.0, random_seed=1234 + )tensorrt_llm/executor/result.py (1)
1-1
: Add NVIDIA Apache-2.0 header (2025).Per repo guidelines, prepend the license header.
+ # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. 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.tensorrt_llm/llmapi/llm.py (1)
1-1
: Add NVIDIA Apache-2.0 header (2025).+ # Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. 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.
🧹 Nitpick comments (7)
tensorrt_llm/__init__.py (1)
58-59
: Silence E402 only for this late import.Given the required early DLL/xgrammar setup, add an inline noqa to keep Ruff happy for this import.
-from .mm_disaggregated_params import MultimodalDisaggParams +from .mm_disaggregated_params import MultimodalDisaggParams # ruff: noqa: E402tensorrt_llm/mm_disaggregated_params.py (1)
14-22
: Docstring nit: parameter formatting.Tweak the
opaque_state
entry for consistency.- opaque_state(bytes): Any additional state needing to be exchanged between mm encoder and ctx instance (reserved for future use) + opaque_state (bytes): Any additional state needing to be exchanged between mm encoder and ctx instance (reserved for future use)tests/unittest/_torch/multimodal/test_mm_encoder_standalone.py (1)
157-243
: Batch test: same two improvements + mark as network/integration.
- Use prompts (text-only) with
multimodal_disagg_params
to avoid reprocessing.- Add deterministic sampling as above.
- Optional: mark as network/integration to avoid CI flakes due to external URLs and large HF model downloads.
- sampling_params = SamplingParams(max_tokens=max_tokens) + sampling_params = SamplingParams( + max_tokens=max_tokens, temperature=0.0, top_p=1.0, random_seed=1234 + ) @@ - outputs = llm.generate(inputs, + outputs = llm.generate(prompts, sampling_params=sampling_params, multimodal_disagg_params=[ eo.multimodal_disagg_params for eo in encoder_outputs ])If your test suite supports markers, consider:
# at top of file # pytestmark = [pytest.mark.network, pytest.mark.slow]tensorrt_llm/llmapi/llm.py (4)
56-57
: Clarify attribute docstring for public API.Expand to reflect the container’s contents for users.
- multimodal_disagg_params (MultimodalDisaggParams, optional): The output of the multimodal encoder for the request. + multimodal_disagg_params (MultimodalDisaggParams, optional): Container for MM context-only exchange: + prompt_token_ids, multimodal_input (hashes/positions/lengths), mm_embedding_handles (fused embedding handle list), + ctx_request_id, and opaque_state (reserved).
254-255
: Add docstring entry for new argument in generate().Args: @@ scheduling_params (tensorrt_llm.scheduling_params.SchedulingParams, List[tensorrt_llm.scheduling_params.SchedulingParams], optional): Scheduling parameters. Defaults to None. + multimodal_disagg_params (tensorrt_llm.mm_disaggregated_params.MultimodalDisaggParams | + Sequence[...], optional): Disaggregated multimodal inputs. When provided with a fused + `mm_embedding_handles`, enables MM-LLM context-only path for that request.
332-333
: Add docstring entry for new argument in generate_async().Args: @@ scheduling_params (tensorrt_llm.scheduling_params.SchedulingParams, optional): Scheduling parameters. Defaults to None. + multimodal_disagg_params (tensorrt_llm.mm_disaggregated_params.MultimodalDisaggParams, optional): + Disaggregated multimodal inputs; if it includes exactly one `mm_embedding_handles` entry, + the MM-LLM context-only path is taken.
400-404
: Constructing MultimodalParams LGTM; optional: normalize to handle.If callers ever pass tensors (not handles), consider converting to shared handles for consistency.
multimodal_params = MultimodalParams( multimodal_input=multimodal_disagg_params.multimodal_input, - multimodal_data={"multimodal_embedding": mm_embedding_handles}) + multimodal_data={"multimodal_embedding": mm_embedding_handle}) + # Optional normalization: + # multimodal_params.to_handle("multimodal_data")
📜 Review details
Configuration used: Path: .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 (6)
tensorrt_llm/__init__.py
(2 hunks)tensorrt_llm/_torch/models/modeling_llava_next.py
(2 hunks)tensorrt_llm/executor/result.py
(6 hunks)tensorrt_llm/llmapi/llm.py
(8 hunks)tensorrt_llm/mm_disaggregated_params.py
(1 hunks)tests/unittest/_torch/multimodal/test_mm_encoder_standalone.py
(3 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/mm_disaggregated_params.py
tensorrt_llm/__init__.py
tests/unittest/_torch/multimodal/test_mm_encoder_standalone.py
tensorrt_llm/llmapi/llm.py
tensorrt_llm/_torch/models/modeling_llava_next.py
tensorrt_llm/executor/result.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/mm_disaggregated_params.py
tensorrt_llm/__init__.py
tests/unittest/_torch/multimodal/test_mm_encoder_standalone.py
tensorrt_llm/llmapi/llm.py
tensorrt_llm/_torch/models/modeling_llava_next.py
tensorrt_llm/executor/result.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/mm_disaggregated_params.py
tensorrt_llm/__init__.py
tests/unittest/_torch/multimodal/test_mm_encoder_standalone.py
tensorrt_llm/llmapi/llm.py
tensorrt_llm/_torch/models/modeling_llava_next.py
tensorrt_llm/executor/result.py
🧠 Learnings (1)
📚 Learning: 2025-07-22T09:22:14.726Z
Learnt from: yechank-nvidia
PR: NVIDIA/TensorRT-LLM#6254
File: tensorrt_llm/_torch/pyexecutor/model_engine.py:1201-1204
Timestamp: 2025-07-22T09:22:14.726Z
Learning: In TensorRT-LLM's multimodal processing pipeline, shared tensor recovery using `from_shared_tensor()` is only needed during the context phase. Generation requests reuse the already-recovered tensor data and only need to call `strip_for_generation()` to remove unnecessary multimodal data while preserving the recovered tensors. This avoids redundant tensor recovery operations during generation.
Applied to files:
tensorrt_llm/llmapi/llm.py
🧬 Code graph analysis (6)
tensorrt_llm/mm_disaggregated_params.py (1)
tensorrt_llm/executor/result.py (1)
prompt_token_ids
(532-533)
tensorrt_llm/__init__.py (1)
tensorrt_llm/mm_disaggregated_params.py (1)
MultimodalDisaggParams
(13-27)
tests/unittest/_torch/multimodal/test_mm_encoder_standalone.py (3)
tensorrt_llm/executor/result.py (1)
multimodal_disagg_params
(644-645)tensorrt_llm/llmapi/llm.py (4)
generate
(237-318)LLM
(1034-1050)tokenizer
(712-716)tokenizer
(719-720)tensorrt_llm/inputs/utils.py (1)
default_multimodal_input_loader
(449-612)
tensorrt_llm/llmapi/llm.py (3)
tensorrt_llm/mm_disaggregated_params.py (1)
MultimodalDisaggParams
(13-27)tensorrt_llm/executor/result.py (2)
multimodal_disagg_params
(644-645)prompt_token_ids
(532-533)tensorrt_llm/inputs/multimodal.py (1)
MultimodalParams
(154-412)
tensorrt_llm/_torch/models/modeling_llava_next.py (1)
tensorrt_llm/_torch/models/modeling_multimodal_utils.py (2)
find_uncached_mm_embeds
(33-105)fuse_input_embeds
(108-167)
tensorrt_llm/executor/result.py (2)
tensorrt_llm/mm_disaggregated_params.py (1)
MultimodalDisaggParams
(13-27)tensorrt_llm/_torch/pyexecutor/llm_request.py (1)
mm_embedding_handle
(234-235)
🪛 Ruff (0.12.2)
tensorrt_llm/__init__.py
46-58: Module level import not at top of file
(E402)
⏰ 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 (10)
tensorrt_llm/_torch/models/modeling_llava_next.py (1)
28-29
: Import looks good.Bringing
find_uncached_mm_embeds
into scope is correct and aligns with the new slicing logic.tensorrt_llm/__init__.py (1)
115-116
: Public API re-export is correct.
MultimodalDisaggParams
belongs in__all__
and matches the new encoder/LLM flow.tensorrt_llm/executor/result.py (4)
19-19
: Import looks correct.
625-626
: repr field update LGTM.
643-646
: Accessor LGTM.Matches the new internal field.
522-526
: No changes needed:MultimodalDisaggParams
is akw_only
dataclass, so its generated__init__
acceptsprompt_token_ids
andmultimodal_input
as keyword args.tensorrt_llm/llmapi/llm.py (4)
32-32
: Import LGTM.
86-87
: repr field update LGTM.
306-306
: Batched propagation LGTM.
364-364
: Heuristic for MM context-only looks reasonable.
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.
Thanks for adding E-PD disagg support for multimodal models. This feature would significantly improve the system throughput at the end. I've left several comments. Could you please take a look?
6bf70c0
to
300c862
Compare
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 on the llmapi changes
/bot run |
PR_Github #19239 [ run ] triggered by Bot |
PR_Github #19239 [ run ] completed with state |
30a6ca9
to
19e70fb
Compare
/bot run |
PR_Github #19269 [ run ] triggered by Bot |
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.
Thanks for addressing my previous comments. While I left two more comments, this PR looks good to me itself. My comment can be addressed in a separated PR if those makes slow down dev-speed (as we always faces CI failure issues). @chang-l Please resolve those comments if you won't handle them in this PR.
PR_Github #19269 [ run ] completed with state |
/bot run |
PR_Github #19364 [ run ] triggered by Bot |
Signed-off-by: Chang Liu (Enterprise Products) <9713593+chang-l@users.noreply.github.com>
Signed-off-by: Chang Liu (Enterprise Products) <9713593+chang-l@users.noreply.github.com>
eb90a71
to
9750a6d
Compare
/bot run |
PR_Github #19407 [ run ] triggered by Bot |
PR_Github #19380 [ run ] completed with state |
PR_Github #19407 [ run ] completed with state |
/bot run |
PR_Github #19408 [ run ] triggered by Bot |
PR_Github #19408 [ run ] completed with state |
/bot run |
PR_Github #19409 [ run ] triggered by Bot |
PR_Github #19409 [ run ] completed with state |
/bot run |
PR_Github #19417 [ run ] triggered by Bot |
PR_Github #19417 [ run ] completed with state |
/bot run |
PR_Github #19428 [ run ] triggered by Bot |
PR_Github #19428 [ run ] completed with state |
/bot run |
PR_Github #19485 [ run ] triggered by Bot |
PR_Github #19485 [ run ] completed with state |
Signed-off-by: Chang Liu (Enterprise Products) <9713593+chang-l@users.noreply.github.com>
/bot run |
PR_Github #19515 [ run ] triggered by Bot |
PR_Github #19515 [ run ] completed with state |
/bot run |
PR_Github #19600 [ run ] triggered by Bot |
PR_Github #19600 [ run ] completed with state |
Third PR split from #5000, adding E2E EPD disaggregated support via llmapi, which works together w/ dynamo. cc. @indrajit96
This should also support all TRTLLM multimodal runtime features such as KV-cache reuse, chunked prefill for prefill workers.
A self-contained EPD via trtllm-serve endpoints will follow.
@coderabbitai summary
Description
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 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.