Skip to content

FIX Save trained bias for bias="lora_only"/"boft_only"#3369

Closed
GaganKattula wants to merge 1 commit into
huggingface:mainfrom
GaganKattula:fix-lora-only-bias-save
Closed

FIX Save trained bias for bias="lora_only"/"boft_only"#3369
GaganKattula wants to merge 1 commit into
huggingface:mainfrom
GaganKattula:fix-lora-only-bias-save

Conversation

@GaganKattula

Copy link
Copy Markdown

Fixes #3306

Problem

With bias="lora_only" (and the BOFT bias="boft_only" equivalent), the wrapped base layer's bias is marked trainable, but get_peft_model_state_dict reconstructed the bias key as "<module>.bias". Since PEFT wraps the original module under base_layer, the trained bias actually lives at "<module>.base_layer.bias", so it was silently dropped on save — a reloaded adapter produced different outputs than the trained model.

Fix

Reconstruct the "...base_layer.bias" key, keeping the unwrapped name as a fallback for any layer not wrapped in a base_layer. Applied to both the lora_only and boft_only branches.

Test

Added test_bias_only_saves_trained_bias in tests/test_custom_models.py: it perturbs only the bias, round-trips through save_pretrained/from_pretrained, and asserts the reloaded output matches and the bias is present in the saved file. The test fails on main and passes with this fix.

With bias="lora_only" (and the BOFT equivalent), the wrapped base layer's
bias is marked trainable, but get_peft_model_state_dict reconstructed the
bias key as "<module>.bias" while the bias actually lives at
"<module>.base_layer.bias". The trained bias was silently dropped on save,
so a reloaded adapter produced different outputs.

Reconstruct the "...base_layer.bias" key (keeping the unwrapped name as a
fallback) so the trained bias is saved. Add a regression test.

Signed-off-by: GaganKattula <vihargagan024@gmail.com>
@githubnemo

Copy link
Copy Markdown
Collaborator

There's already #3307

@githubnemo githubnemo closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoraConfig(bias="lora_only") trains base_layer.bias but save_pretrained/get_peft_model_state_dict drops it

2 participants