Skip to content

Conversation

@indrajit96
Copy link
Contributor

@indrajit96 indrajit96 commented Jul 30, 2025

Overview:

Introduces multimodal support for Dynamo using the TensorRT-LLM backend. This allows models to process requests that include both text and images. Additionally, it adds experimental support for providing pre-computed embeddings directly in requests, which can improve performance by bypassing the model's own embedding generation.

Details:

  • Multimodal Request Handling: A new MultimodalRequestProcessor has been added to the TRT-LLM worker. This processor handles OpenAI-formatted requests that contain image URLs or paths to local embedding files. It processes this content and prepares it for the model.

  • Configuration:

A --modality command-line argument has been added, which can be set to multimodal to enable this functionality.
New engine configurations (agg.yaml, decode.yaml, prefill.yaml) have been added for multimodal scenarios.

  • Pre-computed Embeddings (Experimental): Users can now provide pre-computed embeddings in .pt, .pth, or .bin formats. The system detects these files, loads the tensors, and passes them directly to the model.

  • Documentation: The README.md has been updated with detailed instructions on how to use the new multimodal and pre-computed embedding features, including example curl commands.

Where should the reviewer start?

  • components/backends/trtllm/src/dynamo/trtllm/utils/multimodal_processor.py: This new file contains the core logic for processing multimodal requests.

  • components/backends/trtllm/src/dynamo/trtllm/request_handlers/handler_base.py: Review the changes for handling and streaming multimodal responses with new modelType = ModelType.Chat

  • components/backends/trtllm/src/dynamo/trtllm/main.py: Note how the MultimodalRequestProcessor is initialized.

Summary by CodeRabbit

  • New Features

    • Added support for multimodal models, enabling processing of both text and image inputs.
    • Introduced a new command-line option to select between text and multimodal modes.
    • Enhanced streaming output to support OpenAI-compatible chat completion formatting for multimodal responses.
    • Added experimental support for using pre-computed embeddings in inference requests.
  • Documentation

    • Expanded documentation with usage examples for multimodal models, benchmarking instructions, and experimental embedding features.
  • Chores

    • Added configuration files and script comments to facilitate multimodal engine setup and deployment.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Jul 30, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

The changes introduce multimodal support to the TensorRT-LLM backend, including new configuration files for multimodal engines, code updates to process multimodal requests, and documentation enhancements. Key updates add a multimodal processor, extend handler logic for multimodal input/output, provide a new command-line modality argument, and document usage, benchmarking, and experimental features.

Changes

Cohort / File(s) Change Summary
Documentation Enhancements
components/backends/trtllm/README.md
Expanded documentation with sections on client usage, benchmarking, experimental pre-computed embeddings, and supported multimodal models. Provides usage examples, curl requests, and configuration notes.
Multimodal Engine Configurations
components/backends/trtllm/engine_configs/multimodal/agg.yaml, .../decode.yaml, .../prefill.yaml
Added YAML configuration files for multimodal aggregation, decode, and prefill engines. Specify parallelism, memory, backend, and scheduler settings for multimodal operation.
Launch Script Hint
components/backends/trtllm/launch/disagg.sh
Added commented lines to suggest enabling multimodal mode by setting the MODALITY environment variable. No functional changes.
Main Backend Initialization
components/backends/trtllm/src/dynamo/trtllm/main.py
Added logic to detect and handle "multimodal" modality, including model type selection and multimodal processor instantiation. Passes new parameters to request handler configuration.
Multimodal Request Processing
components/backends/trtllm/src/dynamo/trtllm/request_handlers/handler_base.py
Extended handler logic to process multimodal requests, support OpenAI-style fields, handle processed inputs, and stream OpenAI-compatible responses. Added support for multimodal processor and tokenizer.
Disaggregation Handler Update
components/backends/trtllm/src/dynamo/trtllm/request_handlers/handlers.py
Modified decode handler to avoid yielding prefill responses directly under DECODE_FIRST strategy; clarified intent with comments.
Multimodal Processor Utility
components/backends/trtllm/src/dynamo/trtllm/utils/multimodal_processor.py
Introduced new class for extracting and processing multimodal inputs from OpenAI-style requests, handling both images and embeddings.
Modality Argument and Config
components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py
Added modality attribute to config and new --modality argument to CLI parser, supporting "text" and "multimodal" values.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Main
    participant Handler
    participant MultimodalProcessor
    participant Engine

    Client->>Main: Send multimodal request (with messages)
    Main->>Handler: Pass request, multimodal_processor, tokenizer
    Handler->>MultimodalProcessor: process_openai_request(request)
    MultimodalProcessor->>Handler: Return processed_inputs
    Handler->>Engine: generate(processed_inputs, sampling_params)
    Engine-->>Handler: Stream tokens
    Handler->>Client: Stream OpenAI-compatible response chunks
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

In the meadow where models play,
Multimodal dreams hop in today.
Images and text, side by side,
With configs and code, we now can ride.
Rabbits benchmark, embeddings in tow—
New features bloom where wildflowers grow!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (6)
components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (1)

39-39: Add modality to Config string representation.

The new modality attribute should be included in the __str__ method for better debugging and logging visibility.

             f"disaggregation_mode={self.disaggregation_mode}, "
             f"disaggregation_strategy={self.disaggregation_strategy}, "
-            f"next_endpoint={self.next_endpoint})"
+            f"next_endpoint={self.next_endpoint}, "
+            f"modality={self.modality})"
components/backends/trtllm/engine_configs/multimodal/agg.yaml (1)

33-33: Add newline at end of file

Following POSIX conventions and general best practices, text files should end with a newline character.

-use_cuda_graph: false
+use_cuda_graph: false
+
components/backends/trtllm/src/dynamo/trtllm/utils/multimodal_processor.py (1)

84-84: Make device configurable

The device is hardcoded to "cuda". Consider making it configurable or detecting available devices.

+    def __init__(self, model_type: str, model_dir: str, device: str = "cuda"):
         self.model_type = model_type
         self.model_dir = model_dir
         self.modality = ""
+        self.device = device

And update line 84:

-    device="cuda",
+    device=self.device,
components/backends/trtllm/README.md (2)

218-220: Add language specification to code block

The response JSON code block should specify the language for proper syntax highlighting.

-```
+```json
 {"id":"unknown-id","choices":[{"index":0,"message":{"content":"The image depicts a serene landscape featuring a large rock formation, likely El Capitan in Yosemite National Park, California. The scene is characterized by a winding road that curves from the bottom-right corner towards the center-left of the image, with a few rocks and trees lining its edge.\n\n**Key Features:**\n\n* **Rock Formation:** A prominent, tall, and flat-topped rock formation dominates the center of the image.\n* **Road:** A paved road winds its way through the landscape, curving from the bottom-right corner towards the center-left.\n* **Trees and Rocks:** Trees are visible on both sides of the road, with rocks scattered along the left side.\n* **Sky:** The sky above is blue, dotted with white clouds.\n* **Atmosphere:** The overall atmosphere of the","refusal":null,"tool_calls":null,"role":"assistant","function_call":null,"audio":null},"finish_reason":"stop","logprobs":null}],"created":1753322607,"model":"meta-llama/Llama-4-Maverick-17B-128E-Instruct","service_tier":null,"system_fingerprint":null,"object":"chat.completion","usage":null}

---

`256-257`: **Maintain consistent list style**

The markdown uses both asterisks and dashes for unordered lists. For consistency, use dashes throughout.

```diff
-    *   Patch 1: [`302b73b`](https://github.com/chang-l/TensorRT-LLM/commit/302b73be5108f58a6795075e5231a31872e42ddd)
-    *   Patch 2: [`5b7613b`](https://github.com/chang-l/TensorRT-LLM/commit/5b7613bbc78d830efb7c320a3090c3ef862aa0ab)
+    -   Patch 1: [`302b73b`](https://github.com/chang-l/TensorRT-LLM/commit/302b73be5108f58a6795075e5231a31872e42ddd)
+    -   Patch 2: [`5b7613b`](https://github.com/chang-l/TensorRT-LLM/commit/5b7613bbc78d830efb7c320a3090c3ef862aa0ab)

Also applies to: 313-314

components/backends/trtllm/src/dynamo/trtllm/request_handlers/handler_base.py (1)

107-123: Extract request normalization logic

The OpenAI format normalization logic could be extracted to a separate method for better maintainability and reusability.

+def _normalize_openai_request(self, request: dict) -> dict:
+    """Normalize OpenAI format parameters to internal format."""
+    if "stop_conditions" not in request:
+        request["stop_conditions"] = {}
+    if "max_tokens" in request and "max_tokens" not in request["stop_conditions"]:
+        request["stop_conditions"]["max_tokens"] = request.pop("max_tokens")
+    
+    if "sampling_options" not in request:
+        request["sampling_options"] = {}
+    if "temperature" in request and "temperature" not in request["sampling_options"]:
+        request["sampling_options"]["temperature"] = request.pop("temperature")
+    
+    return request

 # Check for multimodal request and process it
 if self.multimodal_processor:
-    # Normalize the request to handle OpenAI format
-    if "stop_conditions" not in request:
-        request["stop_conditions"] = {}
-    if (
-        "max_tokens" in request
-        and "max_tokens" not in request["stop_conditions"]
-    ):
-        request["stop_conditions"]["max_tokens"] = request.pop("max_tokens")
-
-    if "sampling_options" not in request:
-        request["sampling_options"] = {}
-    if (
-        "temperature" in request
-        and "temperature" not in request["sampling_options"]
-    ):
-        request["sampling_options"]["temperature"] = request.pop("temperature")
+    request = self._normalize_openai_request(request)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b69c507 and f3d3c52.

📒 Files selected for processing (10)
  • components/backends/trtllm/README.md (2 hunks)
  • components/backends/trtllm/engine_configs/multimodal/agg.yaml (1 hunks)
  • components/backends/trtllm/engine_configs/multimodal/decode.yaml (1 hunks)
  • components/backends/trtllm/engine_configs/multimodal/prefill.yaml (1 hunks)
  • components/backends/trtllm/launch/disagg.sh (1 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/main.py (5 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/request_handlers/handler_base.py (10 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/request_handlers/handlers.py (2 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/utils/multimodal_processor.py (1 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (3 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: ptarasiewiczNV
PR: ai-dynamo/dynamo#2027
File: container/deps/vllm/install_vllm.sh:0-0
Timestamp: 2025-07-22T10:22:28.972Z
Learning: The `--torch-backend=auto` flag works with vLLM installations via uv pip install, even though it's not a standard pip option. This flag is processed by vLLM's build system during installation to automatically match PyTorch distribution with container CUDA versions.
components/backends/trtllm/engine_configs/multimodal/agg.yaml (2)

Learnt from: ptarasiewiczNV
PR: #2027
File: container/deps/vllm/install_vllm.sh:0-0
Timestamp: 2025-07-22T10:22:28.972Z
Learning: The --torch-backend=auto flag works with vLLM installations via uv pip install, even though it's not a standard pip option. This flag is processed by vLLM's build system during installation to automatically match PyTorch distribution with container CUDA versions.

Learnt from: tanmayv25
PR: #1391
File: examples/tensorrt_llm/common/base_engine.py:171-176
Timestamp: 2025-06-05T01:10:51.865Z
Learning: In examples/tensorrt_llm/common/base_engine.py, the _init_engine method is called only once during initialization, so direct mutation of the _default_sampling_params object during setup is safe and appropriate.

components/backends/trtllm/src/dynamo/trtllm/main.py (2)

Learnt from: ptarasiewiczNV
PR: #2027
File: container/deps/vllm/install_vllm.sh:0-0
Timestamp: 2025-07-22T10:22:28.972Z
Learning: The --torch-backend=auto flag works with vLLM installations via uv pip install, even though it's not a standard pip option. This flag is processed by vLLM's build system during installation to automatically match PyTorch distribution with container CUDA versions.

Learnt from: tanmayv25
PR: #1391
File: examples/tensorrt_llm/common/base_engine.py:171-176
Timestamp: 2025-06-05T01:10:51.865Z
Learning: In examples/tensorrt_llm/common/base_engine.py, the _init_engine method is called only once during initialization, so direct mutation of the _default_sampling_params object during setup is safe and appropriate.

components/backends/trtllm/src/dynamo/trtllm/request_handlers/handler_base.py (2)

Learnt from: tanmayv25
PR: #1391
File: examples/tensorrt_llm/common/base_engine.py:171-176
Timestamp: 2025-06-05T01:10:51.865Z
Learning: In examples/tensorrt_llm/common/base_engine.py, the _init_engine method is called only once during initialization, so direct mutation of the _default_sampling_params object during setup is safe and appropriate.

Learnt from: ishandhanani
PR: #1626
File: lib/llm/src/preprocessor.rs:238-239
Timestamp: 2025-06-24T20:59:35.725Z
Learning: In lib/llm/src/preprocessor.rs, the sampling_options call in the preprocess_request method is placed in the common section after the match statement on request.prompt_input_type(), meaning it applies to both PromptInput::Tokens and PromptInput::Text request types.

🪛 markdownlint-cli2 (0.17.2)
components/backends/trtllm/README.md

218-218: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


256-256: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)


257-257: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)


304-304: Multiple headings with the same content

(MD024, no-duplicate-heading)


313-313: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)


314-314: Unordered list style
Expected: dash; Actual: asterisk

(MD004, ul-style)


357-357: Multiple headings with the same content

(MD024, no-duplicate-heading)

⏰ 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). (4)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: Build and Test - vllm
🔇 Additional comments (6)
components/backends/trtllm/launch/disagg.sh (1)

13-14: LGTM! Clear documentation for enabling multimodal mode.

The commented lines provide helpful guidance for users to enable multimodal functionality without affecting the default behavior.

components/backends/trtllm/src/dynamo/trtllm/request_handlers/handlers.py (1)

127-141: LGTM! Improved prefill response handling.

The change to explicitly capture and extract prefill response state instead of yielding directly provides better control over the processing flow. This approach is beneficial for multimodal support where additional response processing may be needed.

components/backends/trtllm/engine_configs/multimodal/decode.yaml (1)

15-28: Verify multimodal-specific optimizations in decode.yaml

I ran searches across our YAML configs and didn’t find any multimodal-specific tuning or documentation. Please confirm whether parameters like max_batch_size, max_num_tokens, and kv_cache_config are optimal for your target multimodal workloads, or update the config with any required image/vision-specific settings.

• File to review: components/backends/trtllm/engine_configs/multimodal/decode.yaml

components/backends/trtllm/engine_configs/multimodal/prefill.yaml (1)

15-30: LGTM! Appropriate prefill-specific optimizations.

The configuration correctly disables CUDA graphs and overlap scheduler for prefill workloads, with clear documentation explaining the rationale. The chunked prefill feature will be beneficial for handling large multimodal contexts.

components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (2)

151-157: LGTM! Clean implementation of modality configuration.

The command-line argument implementation follows established patterns with appropriate defaults, validation, and clear help text.


210-210: LGTM! Proper config assignment.

The modality value is correctly assigned to the config object, maintaining consistency with other command-line argument handling.

@indrajit96 indrajit96 force-pushed the ibhosale_trtllm_test branch from f3d3c52 to dd4fb75 Compare July 30, 2025 18:19
@indrajit96 indrajit96 requested a review from tanmayv25 August 1, 2025 18:49
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Aug 4, 2025
@indrajit96 indrajit96 requested review from GuanLuo and krishung5 August 4, 2025 18:05
@indrajit96
Copy link
Contributor Author

@coderabbitai resolve

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

✅ Actions performed

Comments resolved.

@indrajit96 indrajit96 enabled auto-merge (squash) August 5, 2025 23:51
@indrajit96 indrajit96 merged commit 12fe355 into main Aug 6, 2025
10 checks passed
@indrajit96 indrajit96 deleted the ibhosale_trtllm_test branch August 6, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants