Skip to content

fix minicpm-v2.5 lora_target_modules #1455

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 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/Multi-Modal/minicpm-v-2.5最佳实践.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ road:

(默认只对LLM部分的qkv进行lora微调. 如果你想对所有linear含vision模型部分都进行微调, 可以指定`--lora_target_modules ALL`. 支持全参数微调.)
```shell
# Experimental environment: A100
# 32GB GPU memory
# Experimental environment: 3090
# 20GB GPU memory
CUDA_VISIBLE_DEVICES=0 swift sft \
--model_type minicpm-v-v2_5-chat \
--dataset coco-en-2-mini \
Expand Down
5 changes: 4 additions & 1 deletion swift/llm/utils/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,10 @@ def _prepare_target_modules(self, target_modules) -> List[str]:
target_modules.append('DEFAULT')
if 'DEFAULT' in target_modules:
target_modules.remove('DEFAULT')
target_modules += get_default_lora_target_modules(self.model_type)
default_lora_tm = get_default_lora_target_modules(self.model_type)
if isinstance(default_lora_tm, str):
return default_lora_tm
target_modules += default_lora_tm
if 'EMBEDDING' in target_modules:
target_modules.remove('EMBEDDING')
self.lora_use_embedding = True
Expand Down
3 changes: 2 additions & 1 deletion swift/llm/utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ class LoRATM(NamedTuple):
'kv_b_proj',
'o_proj',
]
minicpm_llama = r'.*model\.layers\.(?:[0-9]|[12][0-9]|3[01])\.(?:self_attn\.(?:q_proj|k_proj|v_proj))'
# compat
llama2 = llama

Expand Down Expand Up @@ -5151,7 +5152,7 @@ def _new_forward(*args, **kwargs) -> Tensor:
@register_model(
ModelType.minicpm_v_v2_5_chat,
'OpenBMB/MiniCPM-Llama3-V-2_5',
LoRATM.llama,
LoRATM.minicpm_llama,
TemplateType.minicpm_v_v2_5,
support_flash_attn=True,
requires=['timm'],
Expand Down
Loading