Repository navigation
Conversation
Signed-off-by: larkzhang-nv <larkz@nvidia.com>
This branch has not been deployed
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.
Summary
Fix checkpoint key mapping for models whose Transformers conversion mappings are registered by model class rather than by
config.model_type.This primarily fixes Qwen2-VL and Qwen2.5-VL checkpoint loading, while addressing the underlying wrapper-related lookup issue for other class-registered models as well.
Problem
AutoModel's DCP-based Hugging Face checkpoint path uses
get_combined_key_mapping()to build a flat regex mapping before reading safetensors metadata.Previously, this function queried Transformers only with:
However, Transformers registers some conversion mappings by model class name. For example:
Qwen2VLForConditionalGenerationQwen2_5_VLForConditionalGenerationthrough the Qwen2-VL class mapping aliasThere is no corresponding direct mapping registered under
qwen2_vlorqwen2_5_vl.As a result, AutoModel did not apply the required Qwen-VL renames:
This becomes more subtle after FSDP2 parallelization because the runtime model may be represented by a dynamically created subclass. Looking up only
type(model).__name__would find the wrapper class rather than the original Hugging Face model class.Transformers upstream behavior
Transformers introduced fine-grained class-based conversion mappings in PR #45661, merged as commit
f397b9e.The upstream lookup explicitly checks the concrete model class before falling back to
config.model_type:That upstream change also moved model-specific mappings such as Qwen-VL to class-based registrations so that different model heads sharing the same
model_typecan use different checkpoint conversions.AutoModel already consumes Transformers' conversion registry, but its simplified DCP loading path bypassed this model-aware lookup and queried only the low-level
model_typemapping.Root cause
The full Transformers conversion pipeline returns scoped
WeightRenamingandWeightConverterobjects and applies them while loading model weights.AutoModel cannot directly use that pipeline in its standard DCP path because DCP metadata planning requires a flat
{regex: replacement}mapping before reading tensors. AutoModel therefore extracts simple renaming rules from the Transformers registry.During that extraction, AutoModel previously looked up only
config.model_type. This diverged from the class-first behavior introduced by Transformers PR #45661 and made class-registered mappings invisible.Calling the upstream helper with the wrapped model is not sufficient either: FSDP2 may create a dynamic subclass whose runtime class name is not registered in Transformers.
Solution
get_combined_key_mapping().config.model_typewhen no class mapping is registered.modelargument optional so existing callers retain the previous behavior.The resulting lookup order is:
Why this is not Qwen-specific
Transformers also registers mappings by class for models such as:
LlavaModelViTModelCLIPVisionModelQwen2AudioModelDetrModelAny of these mappings can become invisible when a transparent framework wrapper changes the runtime class name.
Resolving the underlying class fixes the general wrapper compatibility issue without maintaining a separate model allowlist or duplicating Transformers conversion rules in AutoModel.
Testing
Added coverage for:
model.language_modelprefixes.Validation:
The following checks also pass: