Skip to content

[https://nvbugs/5596377][fix] Fix mm dummy calculation - #8498

Merged
yechank-nvidia merged 8 commits into
NVIDIA:mainfrom
yechank-nvidia:fix_mm_dummy
Oct 29, 2025
Merged

yechank-nvidia merged 8 commits into
NVIDIA:mainfrom
yechank-nvidia:fix_mm_dummy

Conversation

@yechank-nvidia

@yechank-nvidia yechank-nvidia commented Oct 20, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • Breaking Changes

    • Removed get_dummy_text method from input processor.
  • Improvements

    • Enhanced dummy prompt generation with dynamic image resolution tuning for improved performance.
    • Refactored context request creation for better multimodal input handling.
    • Updated test infrastructure to use local test data instead of remote URLs.

@coderabbitai

coderabbitai Bot commented Oct 20, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes refactor dummy prompt generation for multimodal models by removing a text helper method and reimplementing prompt logic to iteratively adjust image resolution to fit token constraints. Related dummy context request infrastructure is updated to directly use the new prompt generation method with optional mrope configuration support. Test data references are migrated from remote URLs to local paths.

Changes

Cohort / File(s) Change Summary
Multimodal prompt generation refactoring
tensorrt_llm/_torch/models/modeling_qwen2vl.py
Removed get_dummy_text() public method. Rewrote get_dummy_prompt() to use iterative image-resolution tuning loop instead of text generation approach; starts with dynamic resolution based on input_seq_len and halves dimensions until prompt fits or returns None.
Dummy context request infrastructure updates
tensorrt_llm/_torch/pyexecutor/_util.py
Reworked _create_dummy_mm_context_request() to replace hash-based multimodal input path with direct input_processor.get_dummy_prompt() calls. Added optional mrope config support when use_mrope enabled. Updated token management loop and removed previous prompt length assertions. Adjusted _create_dummy_context_requests() to defer input_seq_len clamping to called function.
Test data path migration
tests/unittest/llmapi/apps/_test_openai_chat_multimodal.py
Replaced hard-coded remote image/video URLs with local test data paths derived from llm_models_root(). Applied across single/multi-image, video, and image-embed test cases. Added imports for Path and llm_models_root.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Client
    participant PyExecutor
    participant InputProcessor
    participant Model

    rect rgb(200, 220, 240)
    note over PyExecutor: Old Path (Removed)
    Client->>PyExecutor: _create_dummy_mm_context_request()
    PyExecutor->>InputProcessor: input_processor_with_hash path
    InputProcessor-->>PyExecutor: multimodal_input/multimodal_data
    end

    rect rgb(220, 240, 220)
    note over PyExecutor: New Path
    Client->>PyExecutor: _create_dummy_mm_context_request()
    PyExecutor->>InputProcessor: get_dummy_prompt(input_seq_len)
    alt prompt available
        InputProcessor-->>PyExecutor: dummy_mm_prompt
        PyExecutor->>Model: input_processor.get_prompt_token_ids()
        Model-->>PyExecutor: prompt_token_ids + multimodal_data
    else prompt unavailable
        InputProcessor-->>PyExecutor: None
        PyExecutor->>PyExecutor: fallback to text-only prompt
        alt mrope enabled
            PyExecutor->>PyExecutor: include mrope_config
        end
    end
    PyExecutor-->>Client: GenerationRequest with updated fields
    end
Loading
sequenceDiagram
    autonumber
    participant Caller
    participant GetDummyPrompt
    participant ImageResolution

    rect rgb(220, 240, 220)
    note over GetDummyPrompt: New Iterative Resolution Tuning
    Caller->>GetDummyPrompt: get_dummy_prompt(input_seq_len)
    GetDummyPrompt->>ImageResolution: img_max_dim = input_seq_len
    loop Halve dimensions until fit or exhausted
        ImageResolution->>ImageResolution: create multimodal input with current resolution
        ImageResolution->>ImageResolution: generate prompt tokens with prompts=[""]
        alt token count ≤ input_seq_len
            ImageResolution-->>GetDummyPrompt: test_mm_prompt (success)
            GetDummyPrompt-->>Caller: return test_mm_prompt
        else token count exceeds
            ImageResolution->>ImageResolution: halve width/height
        end
    end
    GetDummyPrompt-->>Caller: None (no suitable resolution)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Rationale: The changes span three distinct areas with varying complexity. The first file involves a non-trivial logic rewrite (iterative resolution tuning) requiring careful verification of token fitting behavior. The second file contains infrastructure rework with conditional branching and fallback paths that demand attention to control flow. The third file consists of homogeneous string replacements with minimal risk. Combined heterogeneity and moderate logic density across files justifies a moderate effort assessment.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is entirely missing. The template requires at minimum a Description section explaining the issue and solution, a Test Coverage section listing relevant tests, and a PR Checklist confirming compliance with coding guidelines and test requirements. No description content was provided by the author, leaving reviewers without context about what problem is being solved, why the changes were necessary, or what tests validate the fixes.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Fix mm dummy calculation" is directly related to the main change in the PR, which involves fixing the multimodal (mm) dummy prompt and context calculation logic. The changes refactor how dummy prompts are generated by replacing the previous text-generation approach with a dynamic image-resolution tuning loop, and updates the dummy context request creation logic across multiple files to use the new approach. While the title doesn't detail the specific implementation approach, it accurately conveys the essence of the changeset and is specific enough to be meaningful, referencing a clear aspect of the codebase being addressed (multimodal dummy calculations) rather than being generic or vague.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
tensorrt_llm/_torch/models/modeling_qwen2vl.py (2)

1-1: Missing NVIDIA Apache-2.0 header (2025).

Add the standard header at file top.

Same header block as suggested in tests file.


291-315: Starting dummy image size = input token limit risks OOM and long loops. Clamp to model-aware max.

Using img_max_dim = input_seq_len can create gigantic images (e.g., 16K×16K) before preprocessing, wasting memory and time. Start from a safe, model-config bound (e.g., vision_config image size) and then halve.

Proposed fix:

-        img_max_dim = input_seq_len  # TODO: Find better starting resolution
+        # Start from a safe, model-aware upper bound to avoid OOM from huge dummy images
+        max_hw = (getattr(self.model_config.vision_config, "image_size", None)
+                  or getattr(self.model_config.vision_config, "max_image_size", None)
+                  or 1024)
+        img_max_dim = int(min(max_hw, max(64, input_seq_len)))

Optional follow-up (binary search to reduce iterations) available if you want.

tensorrt_llm/_torch/pyexecutor/_util.py (1)

1-1: Missing NVIDIA Apache-2.0 header (2025).

Add the standard header at file top.

Same header block as suggested earlier.

🧹 Nitpick comments (5)
tests/unittest/llmapi/apps/_test_openai_chat_multimodal.py (2)

71-75: Use pure pathlib composition instead of os.path.join.

Cleaner and OS-agnostic; avoid mixing os.path with Path.

Example (apply to all occurrences):

-    test_data_root = Path(
-        os.path.join(llm_models_root(), "multimodals", "test_data"))
+    test_data_root = Path(llm_models_root()) / "multimodals" / "test_data"

Also applies to: 127-129, 188-190, 244-246, 301-303


247-249: Confirm encode_base64_content_from_url handles local paths.

The helper name suggests remote URLs; ensure it accepts plain file paths. If not, inline a file read.

Fallback snippet:

-    image64 = encode_base64_content_from_url(image_url)
+    # Fallback if local paths aren’t supported by the helper:
+    # from base64 import b64encode
+    # image64 = b64encode(Path(image_url).read_bytes()).decode("ascii")
tensorrt_llm/_torch/models/modeling_qwen2vl.py (1)

303-305: Empty text prompt is fine; consider annotating intent.

A brief comment like “image-only prompt” improves maintainability.

tensorrt_llm/_torch/pyexecutor/_util.py (2)

155-161: Minor: semantics of input_seq_len vs remaining_tokens.

You clamp input_seq_len = min(max_num_tokens, input_seq_len) and then drive the loop by remaining_tokens = max_num_tokens. That’s fine, but a short comment explaining the intent (pack multiple requests to fill max_num_tokens) would help future readers.


180-186: Non-crypto RNG is OK here; consider reproducibility.

random.randint is fine for dummy profiling. If you want deterministic runs, seed or switch to torch.randint with a fixed RNG.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d05079b and 9b37446.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/models/modeling_qwen2vl.py (2 hunks)
  • tensorrt_llm/_torch/pyexecutor/_util.py (1 hunks)
  • tests/unittest/llmapi/apps/_test_openai_chat_multimodal.py (6 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/models/modeling_qwen2vl.py
  • tests/unittest/llmapi/apps/_test_openai_chat_multimodal.py
  • tensorrt_llm/_torch/pyexecutor/_util.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/models/modeling_qwen2vl.py
  • tests/unittest/llmapi/apps/_test_openai_chat_multimodal.py
  • tensorrt_llm/_torch/pyexecutor/_util.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/models/modeling_qwen2vl.py
  • tests/unittest/llmapi/apps/_test_openai_chat_multimodal.py
  • tensorrt_llm/_torch/pyexecutor/_util.py
🧬 Code graph analysis (1)
tensorrt_llm/_torch/pyexecutor/_util.py (3)
tensorrt_llm/_torch/models/modeling_qwen2vl.py (1)
  • get_dummy_prompt (290-315)
tensorrt_llm/inputs/registry.py (1)
  • get_dummy_prompt (50-52)
tensorrt_llm/_torch/pyexecutor/model_engine.py (1)
  • use_mrope (390-398)
🪛 Ruff (0.14.0)
tensorrt_llm/_torch/pyexecutor/_util.py

181-181: Standard pseudo-random generators are not suitable for cryptographic purposes

(S311)

⏰ 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/llmapi/apps/_test_openai_chat_multimodal.py (1)

74-85: Local filesystem paths in image_url/video_url may not be valid URLs.

OpenAI-style payloads usually expect http(s) or data: URIs. Your RemoteOpenAIServer may support local paths, but please confirm to keep tests portable.

If unsupported, load bytes and use data: URIs (you already do that once) or prefix with file:// where accepted.

I can help switch all cases to data: URIs for consistency if needed.

Also applies to: 130-147, 191-203, 247-260, 312-316

Comment thread tensorrt_llm/_torch/pyexecutor/_util.py Resolved
@yechank-nvidia yechank-nvidia self-assigned this Oct 20, 2025
@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@yechank-nvidia yechank-nvidia changed the title [None][fix] Fix mm dummy calculation [https://nvbugs.com/5596377][fix] Fix mm dummy calculation Oct 20, 2025
@yechank-nvidia yechank-nvidia changed the title [https://nvbugs.com/5596377][fix] Fix mm dummy calculation [https://nvbugs/5596377][fix] Fix mm dummy calculation Oct 20, 2025
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #21893 [ run ] triggered by Bot. Commit: 9b37446

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #21893 [ run ] completed with state SUCCESS. Commit: 9b37446
/LLM/main/L0_MergeRequest_PR pipeline #16504 completed with status: 'FAILURE'

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22248 [ run ] triggered by Bot. Commit: ead90af

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22251 [ run ] triggered by Bot. Commit: 900371a

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22248 [ run ] completed with state ABORTED. Commit: ead90af
LLM/main/L0_MergeRequest_PR #16773 (Blue Ocean) completed with status: ABORTED

Comment thread tensorrt_llm/inputs/registry.py Resolved
Comment thread tensorrt_llm/inputs/registry.py Resolved
Comment thread tensorrt_llm/_torch/pyexecutor/_util.py Resolved
Comment thread tensorrt_llm/_torch/pyexecutor/_util.py Resolved
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22251 [ run ] completed with state SUCCESS. Commit: 900371a
/LLM/main/L0_MergeRequest_PR pipeline #16775 completed with status: 'FAILURE'

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22270 [ run ] triggered by Bot. Commit: 900371a

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22270 [ run ] completed with state SUCCESS. Commit: 900371a
/LLM/main/L0_MergeRequest_PR pipeline #16792 completed with status: 'FAILURE'

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22694 [ run ] triggered by Bot. Commit: 1b2121b

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22712 [ run ] triggered by Bot. Commit: 0797383

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22694 [ run ] completed with state ABORTED. Commit: 1b2121b
/LLM/main/L0_MergeRequest_PR pipeline #17111 completed with status: 'FAILURE'

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22712 [ run ] completed with state SUCCESS. Commit: 0797383
/LLM/main/L0_MergeRequest_PR pipeline #17126 completed with status: 'FAILURE'

@yechank-nvidia yechank-nvidia added the Multimodal Label for issues & PRs regarding Multimodal related objects label Oct 28, 2025
@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22724 [ run ] triggered by Bot. Commit: 0797383

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22724 [ run ] completed with state SUCCESS. Commit: 0797383
/LLM/main/L0_MergeRequest_PR pipeline #17135 completed with status: 'FAILURE'

@yechank-nvidia

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22741 [ run ] triggered by Bot. Commit: 0797383

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #22741 [ run ] completed with state SUCCESS. Commit: 0797383
/LLM/main/L0_MergeRequest_PR pipeline #17147 completed with status: 'SUCCESS'

@yechank-nvidia
yechank-nvidia merged commit cf8a1d2 into NVIDIA:main Oct 29, 2025
sunnyqgg added a commit to sunnyqgg/TensorRT-LLM that referenced this pull request Nov 23, 2026
Re-pin flashinfer-prims-ts-moe from FlashInfer main 855eece4 to 637f9c53,
which adds FlashInfer NVIDIA#8497 (faster MXFP4 x MXFP8 MoE GEMMs: deeper-pipelined
tile configs, 64-byte K-block weights and an opt-in fused FC2 finalize) and
NVIDIA#8498. The integration patch applies unchanged, and the new launch arguments
are optional, so the op keeps the unfused finalize.

NVIDIA#8497 renumbers the tactics. Key the autotuner cache on a digest of the
vendored config mapper and tables instead of a hand-kept version string, so
tuned tactics from other config tables are not replayed.

Signed-off-by: qgai <[email protected]>
sunnyqgg added a commit to sunnyqgg/TensorRT-LLM that referenced this pull request Nov 25, 2026
Re-pin flashinfer-prims-ts-moe from FlashInfer main 855eece4 to 637f9c53,
which adds FlashInfer NVIDIA#8497 (faster MXFP4 x MXFP8 MoE GEMMs: deeper-pipelined
tile configs, 64-byte K-block weights and an opt-in fused FC2 finalize) and
NVIDIA#8498. The integration patch applies unchanged, and the new launch arguments
are optional, so the op keeps the unfused finalize.

NVIDIA#8497 renumbers the tactics. Key the autotuner cache on a digest of the
vendored config mapper and tables instead of a hand-kept version string, so
tuned tactics from other config tables are not replayed.

Signed-off-by: qgai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Multimodal Label for issues & PRs regarding Multimodal related objects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants