Fix missing property access for multimodal models#966
Merged
lancerts merged 20 commits intolinkedin:mainfrom Dec 15, 2025
Merged
Fix missing property access for multimodal models#966lancerts merged 20 commits intolinkedin:mainfrom
lancerts merged 20 commits intolinkedin:mainfrom
Conversation
Tcc0403
requested changes
Dec 4, 2025
Comment on lines
1525
to
1527
| # Note: language_model and visual properties can be accessed throught conditional class for BC. | ||
| # Not sure if it is subject to changes in the future. | ||
| # Reference: https://github.com/huggingface/transformers/blob/v4.52.4/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py#L1698 |
Collaborator
There was a problem hiding this comment.
Could you help me remove this comment? Thanks!
| @@ -1525,8 +1525,8 @@ def apply_liger_kernel_to_qwen2_vl( | |||
Collaborator
There was a problem hiding this comment.
We also need to update this condition.
model.model.language for XXXForConditionalGeneration, model.language_model for XXXVLModel
albertvillanova
commented
Dec 5, 2025
albertvillanova
commented
Dec 5, 2025
albertvillanova
commented
Dec 5, 2025
Collaborator
|
There still exist some missing attribute error
Similar errors are also listed in #960 (comment). It's just a reminder for myself, not necessarily have to fix all of them in this PR! We can focus on handling all |
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
This PR fixes access to missing attributes for multimodal models in
src/liger_kernel/transformers/monkey_patch.py. The main change is to consistently access attributes (likelanguage_model,vision_tower, andvisual) through the submodel.modelattribute of the parent model, rather than directly from the parent model itself.This fixes AttributeError after this PR was merged in transformers:
get_decoder()for multimodal and delete redundant code 🔪 huggingface/transformers#42156See associated issue in TRL:
Fix #960.
Details
Fix: Consistent attribute access via
.modellanguage_model,vision_tower, andvisualto use the.modelattribute (e.g.,model.model.language_modelinstead ofmodel.language_model) across all kernel application functions for models including LLava, Mllama, Gemma3, PaliGemma, Qwen2 VL, Qwen2.5 VL, Qwen3 VL, Qwen3 VL MoE, GLM4V, GLM4V MoE, and InternVL.Normalization and patching logic updates
.model, ensuring that layer normalization and RMS normalization are consistently applied to the correct components.These changes make the codebase more maintainable and robust against future changes in model class implementations.
Testing Done
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence