Skip to content

fix(export): [NVBug 6525534] preserve nested VLM namespaces - #2032

Merged
meenchen merged 2 commits into
mainfrom
fix/nvbug-6525534-qwen35-vlm-export
Jul 30, 2026
Merged

fix(export): [NVBug 6525534] preserve nested VLM namespaces#2032
meenchen merged 2 commits into
mainfrom
fix/nvbug-6525534-qwen35-vlm-export

Conversation

@meenchen

@meenchen meenchen commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

Prevents recursively collected text-submodel reverse mappings from rewriting an already nested multimodal model namespace during unified Hugging Face export.

Transformers reverses the Qwen3.5 text mapping into a broad ^model. -> model.language_model. rename. ModelOpt previously applied that rule to every key in the full VLM state dict, moving model.visual.* under the language model and nesting model.language_model.* twice. This change drops the reverse rule only when its target child namespace is already registered. Standalone text models continue to use the conversion.

Usage

# Existing export_hf_checkpoint usage is unchanged.

Testing

  • python -m pytest -q tests/unit/torch/export (112 passed, 1 skipped because optional Diffusers is not installed)
  • Targeted pre-fix reproduction confirmed both malformed Qwen3.5 namespaces; both regression cases pass after the fix
  • Tiny Qwen3_5MoeForConditionalGeneration meta-device model-tree probe passed
  • python -m pre_commit run --files modelopt/torch/export/quant_aware_conversion.py tests/unit/torch/export/test_quant_aware_conversion.py

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: ✅
  • Did you get Claude approval on this PR?: N/A

Additional Information

No API or dependency changes.

Summary by CodeRabbit

  • Bug Fixes

    • Improved model conversion to prevent incorrect renaming of nested visual or sibling model components.
    • Fixed duplicate namespace prefixes in converted model weights.
    • Preserved correct reverse mapping for text-only model configurations.
  • Tests

    • Added coverage for nested multimodal and text-only model conversion scenarios.

Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change filters shadowed reverse weight-renaming rules using registered module namespaces, preventing nested VLM sibling capture and double-prefixing while preserving text-only nested mappings. Regression tests cover both namespace configurations, and the changelog records the fix.

Changes

Reverse rename scoping

Layer / File(s) Summary
Shadowed reverse-rule filtering
modelopt/torch/export/quant_aware_conversion.py
Adds namespace probing to remove shadowed weight renames before assembling reverse rename rules.
Nested mapping regression coverage
tests/unit/torch/export/test_quant_aware_conversion.py, CHANGELOG.rst
Tests prevent visual-sibling rewrites while preserving text-only nested mappings; the changelog documents the bug fix.

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

Suggested reviewers: aanoosheh, achidiac-nv, ajrasane

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preserving nested VLM namespaces during export.
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.
Security Anti-Patterns ✅ Passed Touched modelopt/test Python changes contain no torch.load/numpy.load/trust_remote_code/eval/exec/nosec patterns and no new deps.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nvbug-6525534-qwen35-vlm-export

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

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-30 06:51 UTC

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.91%. Comparing base (ddd2fb9) to head (362c1e4).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
modelopt/torch/export/quant_aware_conversion.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2032       +/-   ##
===========================================
+ Coverage   66.87%   77.91%   +11.04%     
===========================================
  Files         519      519               
  Lines       59101    59123       +22     
===========================================
+ Hits        39521    46066     +6545     
+ Misses      19580    13057     -6523     
Flag Coverage Δ
examples 43.14% <81.81%> (-0.24%) ⬇️
gpu 58.97% <81.81%> (+37.87%) ⬆️
regression 15.01% <4.54%> (+0.01%) ⬆️
unit 55.09% <95.45%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: weimingc <17592131+meenchen@users.noreply.github.com>
@meenchen meenchen changed the title fix(export): preserve nested VLM namespaces fix(export): [NVBug 6525534] preserve nested VLM namespaces Jul 29, 2026
@meenchen
meenchen marked this pull request as ready for review July 29, 2026 19:48
@meenchen
meenchen requested review from a team as code owners July 29, 2026 19:48
@meenchen
meenchen requested review from Edwardf0t1 and cjluo-nv July 29, 2026 19:48

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 2

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

Inline comments:
In `@CHANGELOG.rst`:
- Around line 88-89: Convert the nested submodel reverse-mappings entry in
CHANGELOG.rst into a separate bullet by adding the changelog list marker at its
start, keeping the existing text unchanged.

In `@tests/unit/torch/export/test_quant_aware_conversion.py`:
- Around line 269-270: Document the optional Transformers dependency before both
local WeightRenaming imports in
tests/unit/torch/export/test_quant_aware_conversion.py at lines 269-270 and
297-298. Add a brief rationale stating that Transformers is optional and the
test is skipped when unavailable; no other import behavior needs to change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 26e031e9-4198-4140-8c3c-f8eaa03b1b2d

📥 Commits

Reviewing files that changed from the base of the PR and between 943c0b2 and 362c1e4.

📒 Files selected for processing (3)
  • CHANGELOG.rst
  • modelopt/torch/export/quant_aware_conversion.py
  • tests/unit/torch/export/test_quant_aware_conversion.py

Comment thread CHANGELOG.rst
Comment on lines +88 to +89
Nested submodel reverse mappings are now scoped against registered model namespaces, preventing text-only mappings from capturing an already nested VLM's ``model.visual.*`` namespace or double-prefixing ``model.language_model.*`` (observed on Qwen3.5).

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Make this a separate changelog bullet.

Without the - marker, this text continues the preceding bug-fix entry instead of creating the new item described by the PR.

Suggested fix
-  Nested submodel reverse mappings are now scoped against registered model namespaces, preventing text-only mappings from capturing an already nested VLM's ``model.visual.*`` namespace or double-prefixing ``model.language_model.*`` (observed on Qwen3.5).
+- Nested submodel reverse mappings are now scoped against registered model namespaces, preventing text-only mappings from capturing an already nested VLM's ``model.visual.*`` namespace or double-prefixing ``model.language_model.*`` (observed on Qwen3.5).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Nested submodel reverse mappings are now scoped against registered model namespaces, preventing text-only mappings from capturing an already nested VLM's ``model.visual.*`` namespace or double-prefixing ``model.language_model.*`` (observed on Qwen3.5).
- Nested submodel reverse mappings are now scoped against registered model namespaces, preventing text-only mappings from capturing an already nested VLM's ``model.visual.*`` namespace or double-prefixing ``model.language_model.*`` (observed on Qwen3.5).
🤖 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 `@CHANGELOG.rst` around lines 88 - 89, Convert the nested submodel
reverse-mappings entry in CHANGELOG.rst into a separate bullet by adding the
changelog list marker at its start, keeping the existing text unchanged.

Comment on lines +269 to +270
pytest.importorskip("transformers.core_model_loading")
from transformers.core_model_loading import WeightRenaming

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document the optional dependency for both local imports.

The conditional placement is valid, but each local import needs a brief comment explaining that Transformers is optional and the test is skipped when unavailable. As per coding guidelines and path instructions, optional in-function imports require this justification.

  • tests/unit/torch/export/test_quant_aware_conversion.py#L269-L270: add the rationale before the WeightRenaming import.
  • tests/unit/torch/export/test_quant_aware_conversion.py#L297-L298: add the same rationale before the WeightRenaming import.
📍 Affects 1 file
  • tests/unit/torch/export/test_quant_aware_conversion.py#L269-L270 (this comment)
  • tests/unit/torch/export/test_quant_aware_conversion.py#L297-L298
🤖 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 `@tests/unit/torch/export/test_quant_aware_conversion.py` around lines 269 -
270, Document the optional Transformers dependency before both local
WeightRenaming imports in tests/unit/torch/export/test_quant_aware_conversion.py
at lines 269-270 and 297-298. Add a brief rationale stating that Transformers is
optional and the test is skipped when unavailable; no other import behavior
needs to change.

Sources: Coding guidelines, Path instructions

@cjluo-nv cjluo-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bot review (gpt-5.6-sol) — DM the bot to share feedback.

The fix is focused and appears correct. It detects broad reverse prefix renames whose destination is already an explicitly registered child namespace, preventing Qwen3.5 VLM sibling capture and duplicate language_model nesting while retaining the rename for standalone text models. The two regression tests cover both sides of that behavior, and the changelog is updated. No licensing text is changed.

@meenchen

Copy link
Copy Markdown
Contributor Author

/ok to test 362c1e4

@meenchen
meenchen merged commit 4c3d364 into main Jul 30, 2026
71 of 73 checks passed
@meenchen
meenchen deleted the fix/nvbug-6525534-qwen35-vlm-export branch July 30, 2026 06:50
@meenchen meenchen self-assigned this Jul 30, 2026
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.

2 participants