High severity intermediate · Fix: 5-10 min

ValueError

peft.peft_config.ValueError: target_modules not found

What this error means
PEFT's LoraConfig raises ValueError when specified target_modules are not found in the base model's architecture.

Stack trace

traceback
ValueError: target_modules ['q_proj', 'v_proj'] not found in model's modules. Available modules are: ['query', 'value', 'key', 'out_proj']
QUICK FIX
Verify and correct target_modules names by inspecting model.named_modules() before passing them to LoraConfig.

Why it happens

The LoraConfig expects exact module names in the base model to apply LoRA adapters. If the target_modules list contains names that do not match any module in the model, PEFT raises this error. This often happens due to model architecture differences or typos in module names.

Detection

Check the model's named modules via model.named_modules() or model.config to verify available module names before passing them to LoraConfig.

Causes & fixes

1

Incorrect or misspelled module names in target_modules list that do not exist in the base model.

✓ Fix

Inspect the base model's module names using model.named_modules() and update target_modules to match exactly.

2

Using a model architecture that does not contain the expected projection layers (e.g., 'q_proj', 'v_proj') because it uses different naming conventions.

✓ Fix

Adapt target_modules to the actual module names of the model, such as 'query', 'value', or 'key', depending on the architecture.

3

Passing target_modules before loading or initializing the base model properly, so the model's modules are not accessible yet.

✓ Fix

Ensure the base model is fully loaded and initialized before creating LoraConfig with target_modules.

Code: broken vs fixed

Broken - triggers the error
python
from peft import LoraConfig
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained('gpt2')
lora_config = LoraConfig(target_modules=['q_proj', 'v_proj'], r=8, lora_alpha=32, lora_dropout=0.1)  # This line triggers ValueError
Fixed - works correctly
python
import os
from peft import LoraConfig
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(os.environ['HF_MODEL_NAME'])
# Inspect model modules to find correct target_modules
# For GPT2, use 'query' and 'value' instead of 'q_proj' and 'v_proj'
lora_config = LoraConfig(target_modules=['query', 'value'], r=8, lora_alpha=32, lora_dropout=0.1)  # Fixed target_modules
print('LoraConfig created successfully with correct target_modules')
Changed target_modules to match actual module names in the model ('query', 'value') instead of non-existent 'q_proj', 'v_proj'.

Workaround

Wrap LoraConfig creation in try/except ValueError, then log model.named_modules() output to manually identify correct module names and retry with corrected list.

Prevention

Always inspect the base model's module names before configuring LoRA adapters to ensure target_modules align with the model's architecture and naming conventions.

Python 3.9+ · peft >=0.3.0 · tested on 0.3.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.