FIX Save trained bias for bias="lora_only"/"boft_only"#3369
Closed
GaganKattula wants to merge 1 commit into
Closed
FIX Save trained bias for bias="lora_only"/"boft_only"#3369GaganKattula wants to merge 1 commit into
GaganKattula wants to merge 1 commit into
Conversation
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>
Collaborator
|
There's already #3307 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3306
Problem
With
bias="lora_only"(and the BOFTbias="boft_only"equivalent), the wrapped base layer's bias is marked trainable, butget_peft_model_state_dictreconstructed the bias key as"<module>.bias". Since PEFT wraps the original module underbase_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 abase_layer. Applied to both thelora_onlyandboft_onlybranches.Test
Added
test_bias_only_saves_trained_biasintests/test_custom_models.py: it perturbs only the bias, round-trips throughsave_pretrained/from_pretrained, and asserts the reloaded output matches and the bias is present in the saved file. The test fails onmainand passes with this fix.