# ValueError：在基础模型中未找到目标模块['q_proj', 'v_proj']。可用模块：['query', 'value', 'key', 'output']

- **ID:** `huggingface/lora-target-modules-mismatch`
- **领域:** huggingface
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

LoRA配置指定的目标模块名称与基础模型线性层的实际命名约定不匹配，通常是由于模型架构差异（例如LLaMA vs GPT-2）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| peft>=0.7.0 | active | — | — |
| transformers>=4.35.0 | active | — | — |

## 解决方案

1. ```
   Print the model's module names to find correct targets: for name, module in model.named_modules(): if 'linear' in str(type(module)).lower(): print(name). Then set target_modules to the discovered names.
   ```
2. ```
   Use 'all-linear' as target_modules if supported by PEFT version, but verify with a small test run first.
   ```

## 无效尝试

- **Guessing module names based on other models (e.g., using 'q_proj' for a model that uses 'query')** — Module names are model-specific; guessing leads to repeated mismatches. Must inspect the model's actual layer names. (80% 失败率)
- **Setting target_modules to 'all-linear' without checking compatibility** — While 'all-linear' often works, it may include modules that are not suitable for LoRA (e.g., output projection in some architectures), causing training instability or poor performance. (40% 失败率)
