-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix LoRA support for multimodal models (VLMs) by implementing a consistent pattern for skipping vision components #11261
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9c26d26
fix lora gemma 3 support in text
ConnorLi96 99f9151
delete other types
ConnorLi96 22381b7
having better logic to skip
ConnorLi96 6b58295
support gemma3 lora by adding should_apply_lora method
ConnorLi96 3975c01
support llama4 should_apply_lora
ConnorLi96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
# https://github.com/vllm-project/vllm/blob/main/vllm/model_executor/models/gemma3_mm.py | ||
|
||
import logging | ||
import re | ||
from functools import lru_cache | ||
from typing import Dict, Iterable, List, Optional, Set, Tuple, TypedDict | ||
|
||
|
@@ -154,6 +155,10 @@ class Gemma3ForConditionalGeneration(PreTrainedModel): | |
embedding_modules = {} | ||
embedding_padding_modules = [] | ||
supports_lora = True | ||
# Pattern to match language model layers only (skip vision_tower and multi_modal_projector) | ||
lora_pattern = re.compile( | ||
r"^language_model\.model\.layers\.(\d+)\.(?:self_attn|mlp)\.(?:qkv_proj|o_proj|down_proj|gate_up_proj)" | ||
) | ||
|
||
def __init__( | ||
self, | ||
|
@@ -165,6 +170,13 @@ def __init__( | |
self.config = config | ||
self.quant_config = quant_config | ||
|
||
# For LoRA compatibility: expose text_config attributes at top level | ||
# This allows LoRA code to work without special multimodal handling | ||
if not hasattr(config, "num_hidden_layers"): | ||
config.num_hidden_layers = config.text_config.num_hidden_layers | ||
if not hasattr(config, "hidden_size"): | ||
config.hidden_size = config.text_config.hidden_size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only Gemma3 needs config attribute exposure:
|
||
|
||
self.vision_tower = SiglipVisionModel( | ||
config=config.vision_config, | ||
quant_config=quant_config, | ||
|
@@ -380,6 +392,10 @@ def forward( | |
|
||
return hs | ||
|
||
def should_apply_lora(self, module_name: str) -> bool: | ||
"""Skip vision tower and multi_modal_projector for LoRA.""" | ||
return bool(self.lora_pattern.match(module_name)) | ||
|
||
def tie_weights(self): | ||
return self.language_model.tie_weights() | ||
|
||
|
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
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.