[Model] Fix MiniCPM-V 4.6 vit_merger qkv weight loading#43213
Open
tc-mb wants to merge 1 commit into
Open
Conversation
Signed-off-by: tc-mb <tianchi_cai@icloud.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements a load_weights method in the MiniCPMV4_6 model to handle weight loading, specifically for stacked QKV projections. The review feedback identifies a potential crash due to missing key validation when encountering unexpected keys in the checkpoint and points out that the method should return original weight names instead of transformed ones to prevent the model loader from incorrectly reporting unexpected keys.
a17a283 to
2992c66
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In MiniCPMV4_6 (vllm/model_executor/models/minicpmv4_6.py), the vit_merger.self_attn module uses vLLM's fused QKVParallelLinear (a single qkv_proj), while the HuggingFace checkpoint stores the projections as three separate tensors: q_proj, k_proj, and v_proj.
Although the top-level model already declares:
packed_modules_mapping = {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
...
}
AutoWeightsLoader does not correctly stack the three shards into qkv_proj for the vit_merger sub-tree. As a result, vit_merger.self_attn.qkv_proj is never populated with the pretrained weights — loading either raises missing/unexpected-key errors for vit_merger.self_attn.{q,k,v}_proj.*, or silently leaves qkv_proj at its random init, producing corrupted vision features.
Fix: add a dedicated load_weights method on MiniCPMV4_6ViTWindowAttentionSelfAttn that follows vLLM's standard stacked_params_mapping pattern — feeding q_proj / k_proj / v_proj into qkv_proj.weight_loader with shard_id="q"/"k"/"v" respectively, and falling back to default_weight_loader for the remaining parameters (e.g. out_proj).