[bugfix] qwen25-VL support lora (#14638)

This commit is contained in:
Siyuan Chen
2025-12-10 11:38:51 -08:00
committed by GitHub
parent e99ee0c695
commit 0e54a69548
+8
View File
@@ -23,6 +23,7 @@
# limitations under the License. # limitations under the License.
"""Inference-only Qwen2-VL model compatible with HuggingFace weights.""" """Inference-only Qwen2-VL model compatible with HuggingFace weights."""
import logging import logging
import re
from functools import partial from functools import partial
from typing import Iterable, List, Optional, Tuple, Type from typing import Iterable, List, Optional, Tuple, Type
@@ -534,6 +535,13 @@ class Qwen2_5_VLForConditionalGeneration(nn.Module):
image_embeds = self.visual(pixel_values, grid_thw=image_grid_thw) image_embeds = self.visual(pixel_values, grid_thw=image_grid_thw)
return image_embeds return image_embeds
_lora_pattern = re.compile(
r"^model\.layers\.(\d+)\.(?:self_attn|mlp)\.(?:qkv_proj|o_proj|down_proj|gate_up_proj)$"
)
def should_apply_lora(self, module_name: str) -> bool:
return bool(self._lora_pattern.match(module_name))
def get_video_feature(self, items: List[MultimodalDataItem]) -> torch.Tensor: def get_video_feature(self, items: List[MultimodalDataItem]) -> torch.Tensor:
# in qwen-vl, last dim is the same # in qwen-vl, last dim is the same
pixel_values = torch.cat([item.feature for item in items], dim=0).type( pixel_values = torch.cat([item.feature for item in items], dim=0).type(