FIX: Warn when using LoRA bias w/o base layer bias #2725
Merged
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.
When setting
lora_bias=True, a bias term is added tolora_B(#2237). However, to merge this LoRA adapter, we need the base layer to also have a bias. This has not been checked so far.With this PR, we will now warn the user when we detect this situation. Thus they can decide if they want to continue with this setting or not. If they don't intend to merge, they're fine.
On top of this, when trying to merge in this situation, we now raise an appropriate error that clearly explains why merging failed.
About
PeftWarningThis PR adds a new warning class,
PeftWarning. This makes it easier for users to add PEFT specific warning filters (say, to ignore them or to raise an error).There are many more warnings in PEFT that could be migrated to this new warning class (or a subclass where appropriate). This is outside the scope of this PR.
Alternatives
We considered raising an error instead of warning when encountering said situation. Many users miss warnings, so an error would be a stronger signal. This would, however, be too harsh, as it could break existing user code that is working perfectly fine.
We considered adding a bias term to the base layer when it is missing during the merge. However, this requires careful bookkeeping (e.g. when unmerging all adapters, the bias needs to be removed again). Moreover, when calling
merge_and_unload(), users expect the original model architecture to be returned. Suddenly adding a bias term would be unexpected and could lead to errors down the line.