ValueError
transformers.adapters.configuration.LoraConfig.ValueError
Stack trace
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.
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
Incorrect or outdated target_modules names that do not exist in the loaded model architecture.
Inspect the model's module names using model.named_modules() and update target_modules to match exactly the module names present.
Using a model variant or checkpoint with a different internal architecture than expected by the LoRA config.
Ensure the LoRA config target_modules matches the specific model variant you are fine-tuning, or switch to a compatible model.
Typographical errors or case mismatches in the target_modules list.
Double-check spelling and case sensitivity of module names in target_modules to exactly match the model's module names.
Code: broken vs fixed
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 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") 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.