-
Notifications
You must be signed in to change notification settings - Fork 525
fix(export): [NVBug 6525534] preserve nested VLM namespaces #2032
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,6 +264,58 @@ def test_build_reverse_rules_orders_prefix_reorder_after_container(): | |
| assert not any(".mlp.experts." in k for k in out) | ||
|
|
||
|
|
||
| def test_nested_text_prefix_reverse_does_not_capture_vlm_siblings(): | ||
| """A nested text-model conversion must not rewrite the full VLM namespace.""" | ||
| pytest.importorskip("transformers.core_model_loading") | ||
| from transformers.core_model_loading import WeightRenaming | ||
|
Comment on lines
+269
to
+270
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
📍 Affects 1 file
🤖 Prompt for AI AgentsSources: Coding guidelines, Path instructions |
||
|
|
||
| model = torch.nn.Module() | ||
| model.model = torch.nn.Module() | ||
| model.model.visual = torch.nn.Module() | ||
| model.model.visual.patch_embed = torch.nn.Linear(2, 2, bias=False) | ||
| model.model.language_model = torch.nn.Module() | ||
| model.model.language_model.layers = torch.nn.ModuleList([torch.nn.Linear(2, 2, bias=False)]) | ||
| model._weight_conversions = [ | ||
| WeightRenaming( | ||
| source_patterns=r"^model.language_model.", | ||
| target_patterns=r"^model.(?!language_model.)", | ||
| ) | ||
| ] | ||
|
|
||
| state_dict = { | ||
| "model.visual.patch_embed.weight": torch.randn(2, 2), | ||
| "model.language_model.layers.0.weight": torch.randn(2, 2), | ||
| } | ||
| reverted = revert_weight_conversion_quant_aware(model, state_dict) | ||
|
|
||
| assert set(reverted) == set(state_dict) | ||
| assert build_reverse_name_mapper(model) is None | ||
|
|
||
|
|
||
| def test_nested_text_prefix_reverse_still_applies_to_text_model(): | ||
| """The same conversion remains valid when the nested VLM namespace is absent.""" | ||
| pytest.importorskip("transformers.core_model_loading") | ||
| from transformers.core_model_loading import WeightRenaming | ||
|
|
||
| model = torch.nn.Module() | ||
| model.model = torch.nn.Module() | ||
| model.model.layers = torch.nn.ModuleList([torch.nn.Linear(2, 2, bias=False)]) | ||
| model._weight_conversions = [ | ||
| WeightRenaming( | ||
| source_patterns=r"^model.language_model.", | ||
| target_patterns=r"^model.(?!language_model.)", | ||
| ) | ||
| ] | ||
|
|
||
| state_dict = {"model.layers.0.weight": torch.randn(2, 2)} | ||
| reverted = revert_weight_conversion_quant_aware(model, state_dict) | ||
|
|
||
| assert set(reverted) == {"model.language_model.layers.0.weight"} | ||
| mapper = build_reverse_name_mapper(model) | ||
| assert mapper is not None | ||
| assert mapper("model.layers.0") == "model.language_model.layers.0" | ||
|
|
||
|
|
||
| def test_split_collision_raises(): | ||
| """A split whose target key already exists must fail instead of overwriting.""" | ||
| sd = _nvfp4_linear("m.gate_up_proj", 8, 16) | ||
|
|
||
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.
📐 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
📝 Committable suggestion
🤖 Prompt for AI Agents