Skip to content

Fix missing property access for multimodal models#966

Merged
lancerts merged 20 commits intolinkedin:mainfrom
albertvillanova:fix-960-trl-4601
Dec 15, 2025
Merged

Fix missing property access for multimodal models#966
lancerts merged 20 commits intolinkedin:mainfrom
albertvillanova:fix-960-trl-4601

Conversation

@albertvillanova
Copy link
Contributor

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 (like language_model, vision_tower, and visual) through the submodel .model attribute of the parent model, rather than directly from the parent model itself.

This fixes AttributeError after this PR was merged in transformers:

See associated issue in TRL:

Fix #960.

Details

Fix: Consistent attribute access via .model

  • Updated all references to submodules such as language_model, vision_tower, and visual to use the .model attribute (e.g., model.model.language_model instead of model.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

  • Adjusted normalization and patching calls to operate on submodels accessed via .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

  • Hardware Type:
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help me remove this comment? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -1525,8 +1525,8 @@ def apply_liger_kernel_to_qwen2_vl(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to update this condition.

model.model.language for XXXForConditionalGeneration, model.language_model for XXXVLModel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@Tcc0403
Copy link
Collaborator

Tcc0403 commented Dec 5, 2025

There still exist some missing attribute error

  • MllamaForConditionalGeneration
  • Qwen2VLForConditionalGeneration
  • Qwen2_5_VLForConditionalGeneration
  • InternVLForConditionalGeneration
  • Glm4vForConditionalGeneration
  • Glm4vMoeForConditionalGeneration
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mllama_for_conditional_generation - AttributeError: 'MllamaForConditionalGeneration' object has no attribute 'language_model'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_qwen2_vl_for_conditional_generation - AttributeError: 'Qwen2VLForConditionalGeneration' object has no attribute 'language_model'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_qwen2_5_vl_for_conditional_generation - AttributeError: 'Qwen2_5_VLForConditionalGeneration' object has no attribute 'language_model'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_internvl - AttributeError: 'InternVLForConditionalGeneration' object has no attribute 'language_model'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_glm4v - AttributeError: 'Glm4vForConditionalGeneration' object has no attribute 'language_model'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_glm4v_moe - AttributeError: 'Glm4vMoeForConditionalGeneration' object has no attribute 'language_model'

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 language_model property in this PR.

Copy link
Collaborator

@Tcc0403 Tcc0403 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Tcc0403 Tcc0403 mentioned this pull request Dec 15, 2025
12 tasks
@lancerts lancerts merged commit 153d226 into linkedin:main Dec 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError for 'language_model' in transformers v5

3 participants

Comments