Skip to content

[None][fix] Fix Qwen2-VL Transformers 5 compatibility#15997

Merged
2ez4bz merged 1 commit into
NVIDIA:mainfrom
2ez4bz:dev-nvbug-6420473
Jul 8, 2026
Merged

[None][fix] Fix Qwen2-VL Transformers 5 compatibility#15997
2ez4bz merged 1 commit into
NVIDIA:mainfrom
2ez4bz:dev-nvbug-6420473

Conversation

@2ez4bz

@2ez4bz 2ez4bz commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Improved multimodal vision handling so pooled outputs from vision encoders are supported correctly for both image and video inputs.
    • Ensured additional multimodal position tensors are moved to the right device during distributed execution.
  • Tests

    • Added coverage for pooled vision outputs.
    • Added coverage for device placement of multimodal position data.

Description

  • Why?

Transformers 5.x returns vision features in a pooling wrapper, and MRoPE position tensors must be on the model device for inference.

  • What?

Extract pooled vision embeddings, transfer MRoPE tensors with multimodal data, and add regression coverage for both paths.

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • 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

To see a list of available CI bot commands, please comment /bot help.

* Why?

Transformers 5.x returns vision features in a pooling wrapper, and
MRoPE position tensors must be on the model device for inference.

* What?

Extract pooled vision embeddings, transfer MRoPE tensors with multimodal
data, and add regression coverage for both paths.

Signed-off-by: William Zhang <133824995+2ez4bz@users.noreply.github.com>
@2ez4bz 2ez4bz requested review from a team as code owners July 6, 2026 19:39
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Modifies Qwen2VL vision model forward pass to extract pooler_output when vision encoder returns BaseModelOutputWithPooling objects, and extends multimodal_data_device_paths to include mrope_config position tensor paths for disaggregated multimodal execution. Adds two corresponding unit tests.

Changes

Qwen2VL vision pooling and mrope device paths

Layer / File(s) Summary
Pooled output extraction from vision encoder
tensorrt_llm/_torch/models/modeling_qwen2vl.py, tests/unittest/_torch/modeling/test_modeling_qwen2_5vl.py
Qwen2VisionModelBase.forward detects BaseModelOutputWithPooling results and extracts pooler_output for image and video embeddings; imports updated and a new test validates the wrapper output matches the encoder's pooled output.
Mrope tensor device paths
tensorrt_llm/_torch/models/modeling_qwen2vl.py, tests/unittest/_torch/modeling/test_modeling_qwen2_5vl.py
multimodal_data_device_paths() now includes mrope_config.mrope_position_ids and mrope_config.mrope_position_deltas paths; a new test verifies these tensors move to CUDA via MultimodalParams.to_device.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested reviewers: yechank-nvidia, achartier, laikhtewari, jieli-matrix, Tabrizian

Poem:
A rabbit hopped through vision's maze,
Found pooler_output hidden in the haze,
Mrope tensors packed for their CUDA ride,
Tests confirm each path is verified,
Hop, hop, review — no bugs to chase! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change and follows the required [None][fix] format.
Description check ✅ Passed The description covers why and what, includes the checklist, and is mostly complete despite a blank Test Coverage section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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.

🧹 Nitpick comments (1)
tensorrt_llm/_torch/models/modeling_qwen2vl.py (1)

1081-1093: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate pooler-extraction logic across image/video branches.

The isinstance(embed, BaseModelOutputWithPooling) check and .pooler_output extraction are repeated verbatim for both image and video paths. Extracting a small helper avoids the two copies silently diverging if this logic needs a future tweak (e.g. additional output types).

♻️ Proposed refactor
+    `@staticmethod`
+    def _extract_vision_embed(
+        output: Union[torch.Tensor, BaseModelOutputWithPooling]
+    ) -> torch.Tensor:
+        if isinstance(output, BaseModelOutputWithPooling):
+            return output.pooler_output
+        return output
+
     embeds = []
     if pixel_values is not None:
-            embed = self.visual(pixel_values, grid_thw=image_grid_thw)
-            if isinstance(embed, BaseModelOutputWithPooling):
-                embed = embed.pooler_output
-            embeds.append(embed)
+            embeds.append(
+                self._extract_vision_embed(
+                    self.visual(pixel_values, grid_thw=image_grid_thw)))

     if pixel_values_videos is not None:
-            embed = self.visual(pixel_values_videos, grid_thw=video_grid_thw)
-            if isinstance(embed, BaseModelOutputWithPooling):
-                embed = embed.pooler_output
-            embeds.append(embed)
+            embeds.append(
+                self._extract_vision_embed(
+                    self.visual(pixel_values_videos, grid_thw=video_grid_thw)))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/models/modeling_qwen2vl.py` around lines 1081 - 1093, The
image and video branches in the visual embedding flow duplicate the same
BaseModelOutputWithPooling handling logic. Refactor the repeated
isinstance(embed, BaseModelOutputWithPooling) and pooler_output extraction into
a small helper used by the visual embedding method, so both pixel_values and
pixel_values_videos paths share one implementation and stay consistent if the
output handling changes later.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tensorrt_llm/_torch/models/modeling_qwen2vl.py`:
- Around line 1081-1093: The image and video branches in the visual embedding
flow duplicate the same BaseModelOutputWithPooling handling logic. Refactor the
repeated isinstance(embed, BaseModelOutputWithPooling) and pooler_output
extraction into a small helper used by the visual embedding method, so both
pixel_values and pixel_values_videos paths share one implementation and stay
consistent if the output handling changes later.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 003f477f-eb63-4dde-a265-64eb7f7b69a5

📥 Commits

Reviewing files that changed from the base of the PR and between 7c8dde8 and 4ba2604.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/models/modeling_qwen2vl.py
  • tests/unittest/_torch/modeling/test_modeling_qwen2_5vl.py

@2ez4bz 2ez4bz enabled auto-merge (squash) July 7, 2026 04:50
@2ez4bz

2ez4bz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57935 [ run ] triggered by Bot. Commit: 4ba2604 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57935 [ run ] completed with state FAILURE. Commit: 4ba2604
/LLM/main/L0_MergeRequest_PR pipeline #46623 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@2ez4bz

2ez4bz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58058 [ run ] triggered by Bot. Commit: 4ba2604 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58058 [ run ] completed with state SUCCESS. Commit: 4ba2604
/LLM/main/L0_MergeRequest_PR pipeline #46724 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@2ez4bz

2ez4bz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58075 [ run ] triggered by Bot. Commit: 4ba2604 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58075 [ run ] completed with state SUCCESS. Commit: 4ba2604
/LLM/main/L0_MergeRequest_PR pipeline #46739 completed with status: 'SUCCESS'

CI Report

Link to invocation

@2ez4bz 2ez4bz merged commit b62f605 into NVIDIA:main Jul 8, 2026
12 checks passed
crazydemo pushed a commit to crazydemo/TensorRT-LLM that referenced this pull request Jul 8, 2026
Signed-off-by: William Zhang <133824995+2ez4bz@users.noreply.github.com>
BrianLi23 pushed a commit to BrianLi23/TensorRT-LLM that referenced this pull request Jul 9, 2026
Signed-off-by: William Zhang <133824995+2ez4bz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants