huggingface
config_error
ai_generated
true
ValueError: 目标模块 ['q_proj', 'v_proj'] 在基础模型中未找到。可用模块为: ['query', 'value', 'key', 'output']
ValueError: Target modules ['q_proj', 'v_proj'] not found in the base model. Available modules are: ['query', 'value', 'key', 'output']
ID: huggingface/peft-lora-target-modules-mismatch
85%修复率
88%置信度
1证据数
2023-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| peft>=0.4.0 | active | — | — | — |
| transformers>=4.30.0 | active | — | — | — |
| torch>=1.13.0 | active | — | — | — |
根因分析
LoRA 的 target_modules 参数指定了错误的模块名称,与基础模型实际的层命名约定不匹配。
English
LoRA target_modules specified with incorrect module names that do not match the base model's actual layer naming convention.
官方文档
https://huggingface.co/docs/peft/en/developer_guides/lora#target-modules解决方案
-
Print the model's module names to identify correct target modules: `for name, _ in model.named_modules(): print(name)` then select only linear layers (e.g., 'q_proj', 'v_proj' for LLaMA, 'query', 'value' for BERT).
-
Use peft.get_peft_model() with target_modules='all-linear' if using peft>=0.7.0 and the model is transformer-based, which automatically selects all linear layers except the output projection.
-
Check the model configuration via model.config.model_type and refer to the PEFT documentation for the correct module names for that architecture.
无效尝试
常见但无效的做法:
-
50% 失败
The model may not have those exact names; e.g., LLaMA uses 'self_attn.q_proj' while GPT-2 uses 'attn.c_attn'. This can still fail if names are wrong.
-
30% 失败
Includes non-linear layers (e.g., activation functions) which are invalid for LoRA and cause shape errors during forward pass.
-
40% 失败
'all-linear' was introduced in peft>=0.7.0; older versions raise AttributeError or silently ignore it.