Fix bias='lora_only' state-dict collection in train_lora#3859
Open
Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Open
Fix bias='lora_only' state-dict collection in train_lora#3859Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Conversation
…ro_3 The lora_only branch of get_peft_state_maybe_zero_3 has three related bugs in the same loop: 1. `for k, t in maybe_lora_bias:` iterates dictionary keys (strings), not (key, value) pairs. Unpacking a string into `k, t` raises ValueError as soon as the dict is non-empty. 2. `if bias_name in lora_bias_names` reuses `bias_name` leaked from the previous loop — always the last lora-derived bias name — so the condition has nothing to do with the current key `k`. 3. `to_return[bias_name] = t` writes to that same leaked name instead of `k`, which means the bias param keyed by `k` is stored under the wrong name (or overwritten). Mirror the peft reference (peft/utils/save_and_load.py get_peft_model_state_dict): iterate `maybe_lora_bias.items()` and match against `k` directly.
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.
Bug
In
fastchat/train/train_lora.py,get_peft_state_maybe_zero_3crashesor silently stores bias params under the wrong key whenever
bias == \"lora_only\"is used and the model has any bias parameter.Root cause
for k, t in maybe_lora_bias:iterates dict keys, not items.Unpacking a string key into
k, traisesValueError: too many values to unpackthe first time the dict isnon-empty.
bias_nameleaks from the previous loop – it's always the lastlora-derived bias name – so the membership check is independent of
the current bias key
k.to_return[bias_name] = twrites the tensortunder that leakedname, not
k, so the saved bias param has the wrong key (oroverwrites whatever was saved there).
Why the fix is correct
peft's reference implementation (the comment says this helper was
"borrowed from peft.utils.get_peft_model_state_dict") matches bias
keys directly against the current loop variable, not a leaked one.
Using
maybe_lora_bias.items()andkmakes the three lines selfconsistent and produces the same behaviour as peft's
lora_onlybranch.Change
fastchat/train/train_lora.py: