High severity intermediate · Fix: 5-10 min

RuntimeError

torch.nn.modules.module.RuntimeError

What this error means
This error occurs when the PEFT adapter's state dictionary keys do not match the base model's expected keys during loading.

Stack trace

traceback
RuntimeError: Error(s) in loading state_dict for PeftModel:
	Missing key(s) in state_dict: "lora_adapter.weight", "lora_adapter.bias"...
	Unexpected key(s) in state_dict: "base_model.weight"...
	size mismatch for lora_adapter.weight: copying a param with shape [64, 64] from checkpoint, the shape in current model is [32, 64].
QUICK FIX
Use PeftModel.from_pretrained with the correct base model and matching adapter checkpoint to load the adapter state dict properly.

Why it happens

The PEFT adapter load state dict error happens because the adapter checkpoint's parameter keys or shapes do not align with the base model's architecture. This mismatch can occur if the adapter was trained on a different model version, or if the base model has changed since the adapter was saved.

Detection

Check the error logs for missing or unexpected keys and size mismatches when loading the adapter state dict. Validate that the adapter and base model versions match before loading.

Causes & fixes

1

Adapter checkpoint was saved from a different base model architecture or version.

✓ Fix

Ensure the base model used to load the adapter matches exactly the model used during adapter training, including version and configuration.

2

Using a PEFT adapter checkpoint incompatible with the current PEFT or transformers library version.

✓ Fix

Upgrade or downgrade the PEFT and transformers libraries to the versions compatible with the adapter checkpoint or re-export the adapter with the current library versions.

3

Partial or corrupted adapter checkpoint missing required keys.

✓ Fix

Verify the adapter checkpoint file integrity and re-download or re-save the adapter checkpoint if corrupted.

4

Loading the adapter state dict into the full base model instead of the PEFT wrapper model.

✓ Fix

Load the adapter checkpoint using the PEFT model wrapper (e.g., PeftModel.from_pretrained) rather than directly into the base model.

Code: broken vs fixed

Broken - triggers the error
python
from transformers import AutoModel
from peft import PeftModel

model = AutoModel.from_pretrained('bert-base-uncased')
adapter_path = './adapter_checkpoint'

# This line causes the error
model.load_state_dict(torch.load(adapter_path))
Fixed - works correctly
python
import os
import torch
from transformers import AutoModel
from peft import PeftModel

os.environ['TRANSFORMERS_CACHE'] = '/path/to/cache'

base_model = AutoModel.from_pretrained('bert-base-uncased')
adapter_path = './adapter_checkpoint'

# Correctly load adapter using PeftModel wrapper
model = PeftModel.from_pretrained(base_model, adapter_path)

print('Adapter loaded successfully')
Replaced direct state_dict loading with PeftModel.from_pretrained to ensure adapter keys align with the base model and load correctly.

Workaround

Catch the RuntimeError and manually filter or map the state dict keys to match the base model, but this is error-prone and not recommended for production.

Prevention

Always save and load PEFT adapters using the PeftModel API with matching base model versions and keep PEFT and transformers libraries in sync to avoid state dict mismatches.

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.