High severity intermediate · Fix: 5-10 min

ValueError

transformers.adapters.configuration.LoraConfig.ValueError

What this error means
The LoraConfig target_modules parameter does not match any module names in the model, causing a configuration error during LoRA fine-tuning setup.

Stack trace

traceback
ValueError: None of the target_modules ['q_proj', 'v_proj'] were found in the model's modules. Please check the module names and try again.
QUICK FIX
Verify and correct the target_modules list by matching it exactly to the model's internal module names before creating LoraConfig.

Why it happens

LoraConfig requires specifying exact module names in the model to apply LoRA adapters. If the target_modules list contains names not present in the model architecture, the configuration fails with this error. This often happens when using a model variant with different internal module names or a mismatch between the model and LoRA config.

Detection

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

Causes & fixes

1

Incorrect or outdated target_modules names that do not exist in the loaded model architecture.

✓ Fix

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

2

Using a model variant or checkpoint with a different internal architecture than expected by the LoRA config.

✓ Fix

Ensure the LoRA config target_modules matches the specific model variant you are fine-tuning, or switch to a compatible model.

3

Typographical errors or case mismatches in the target_modules list.

✓ Fix

Double-check spelling and case sensitivity of module names in target_modules to exactly match the model's module names.

Code: broken vs fixed

Broken - triggers the error
python
from peft import LoraConfig

config = LoraConfig(
    r=8,
    lora_alpha=32,
    target_modules=["q_proj", "v_proj"],  # Causes ValueError if modules not found
    lora_dropout=0.1,
    bias="none",
    task_type="CAUSAL_LM"
)

# This line triggers the error when applying config to model
model = get_model()
model = prepare_model_for_int8_training(model)
model = get_peft_model(model, config)  # ValueError here
Fixed - works correctly
python
import os
from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM

os.environ["HF_HOME"] = os.environ.get("HF_HOME", "/tmp/hf_cache")  # Example environment setup

model = AutoModelForCausalLM.from_pretrained(os.environ["MODEL_NAME"])

# Inspect model modules to find correct target_modules
print([name for name, _ in model.named_modules() if 'q_proj' in name or 'v_proj' in name])

config = LoraConfig(
    r=8,
    lora_alpha=32,
    target_modules=["query_key_value"],  # Corrected module name matching model
    lora_dropout=0.1,
    bias="none",
    task_type="CAUSAL_LM"
)

model = get_peft_model(model, config)  # Works without error
print("LoRA config applied successfully")
Corrected target_modules to match the actual module names in the model, preventing the ValueError during LoRA config application.

Workaround

Wrap the LoraConfig application in try/except ValueError, then log model.named_modules() output to manually identify correct module names and retry with updated target_modules.

Prevention

Always inspect the model's internal module names before setting target_modules in LoraConfig, especially when switching model checkpoints or variants, to ensure compatibility.

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

Community Notes

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