-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[https://nvbugs/5969216][fix] Ministral3 loading fix #12743
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
Open
evezhier
wants to merge
11
commits into
NVIDIA:main
Choose a base branch
from
evezhier:fix/ministral-loading
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a311bef
config load for HF format
evezhier a523f0e
weight loading fix
evezhier 236c966
move permute from callbacks to weight loading
evezhier 6d49bb7
move permute from callbacks to weight loading
evezhier 3c7f5e5
cleanup
evezhier c18be32
tests
evezhier 5ddd811
precommit fix
evezhier 97803c8
openai server fixes
evezhier 045aae1
license
evezhier d89a104
ignore hf as weight mapper
evezhier 3c26c2e
ML3 should use ML3 weight mapper
evezhier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
tests/unittest/_torch/models/checkpoints/mistral/test_weight_mapper.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from tensorrt_llm._torch.models.checkpoints.mistral.weight_mapper import MistralWeightMapper | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def expected_renames(): | ||
| return { | ||
| # Top-level embeddings and output projections | ||
| "tok_embeddings.weight": "model.embed_tokens.weight", | ||
| "output.weight": "lm_head.weight", | ||
| "norm.weight": "model.norm.weight", | ||
| # Per-layer attention projection weights (pixtral_mapping + mistral_llm_mapping) | ||
| "layers.0.attention.wq.weight": "model.layers.0.self_attn.q_proj.weight", | ||
| "layers.0.attention.wk.weight": "model.layers.0.self_attn.k_proj.weight", | ||
| "layers.0.attention.wv.weight": "model.layers.0.self_attn.v_proj.weight", | ||
| "layers.0.attention.wo.weight": "model.layers.0.self_attn.o_proj.weight", | ||
| # Per-layer MLP weights | ||
| "layers.0.feed_forward.w1.weight": "model.layers.0.mlp.gate_proj.weight", | ||
| "layers.0.feed_forward.w2.weight": "model.layers.0.mlp.down_proj.weight", | ||
| "layers.0.feed_forward.w3.weight": "model.layers.0.mlp.up_proj.weight", | ||
| # Layernorms | ||
| "layers.0.attention_norm.weight": "model.layers.0.input_layernorm.weight", | ||
| "layers.0.ffn_norm.weight": "model.layers.0.post_attention_layernorm.weight", | ||
| # Quantization scales: compound key must win over individual token | ||
| "layers.0.attention.kv_fake_quantizer.qscale_act": "model.layers.0.self_attn.kv_scale", | ||
| "layers.0.attention.qscale_act": "model.layers.0.self_attn.input_scale", | ||
| # Unknown keys must pass through unchanged | ||
| "some.unknown.tensor": "some.unknown.tensor", | ||
| } | ||
|
|
||
|
|
||
| def test_rename_by_params_map(expected_renames): | ||
| mapper = MistralWeightMapper() | ||
| dummy = torch.tensor(0.0) | ||
| input_weights = {k: dummy for k in expected_renames} | ||
|
|
||
| result = mapper.rename_by_params_map(mapper.mistral_llm_mapping, input_weights) | ||
|
|
||
| mismatches = {k: v for k, v in expected_renames.items() if v not in result} | ||
| assert not mismatches, ( | ||
| "Keys not renamed as expected (input -> expected):\n" | ||
| + "\n".join(f" {k!r} -> {v!r}" for k, v in mismatches.items()) | ||
| + f"\nActual keys: {sorted(result.keys())}" | ||
| ) | ||
| assert type(result) is dict | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.