-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and a couple of fixes for adapter layer updates (#1268)
* Refactor: Move LoRA update_layer to child classes For LoRA, so far, we have update_layer for Linear, update_layer_embedding for Embedding, and update_layer_conv2d for Conv2d, all defined on LoraLayer. We can simplify the code by always using the name update_layer, and by moving the layer-specific methods to the subclasses. So e.g. update_layer_embedding is moved to the Embedding class and renamed to update_layer. This way, the caller does not need to differentiate which type of layer it's calling. Interestingly, this was already practiced for IA³, so the same change was not necessary there. But I did find the same method implemented twice, once on IA3Layer and once on Linear, so I removed one of the duplicates * Systematic handling of r (rank) <= 0 Always raise an error when r <= 0, not only for LoRA. Also, removed later check for r > 0 in LoRA layers, since we already check for r <= 0. * Fix broken __repr__ method on QuantLinear Was indented too deep, thus not being applied. * Fix bug for updating Lora GPTQ and IA3 bnb layers Before this fix, when adding a 2nd adapter to a model, we did not correctly check if there was already an adapter layer in the model when dealing with LoRA GPTQ or IA3 bnb layers. As a consequence, instead of updating the existing layers, we would create a new layer and the existing layer would be set as the base_layer of that new layer. Now, we correctly update the existing layer to add the new adapter. Note that for this fix to work correctly with LoRA and GPTQ, I had to add a check for qweight, since we only checked for weight before. Tests were added to check this. They fail with the current main but are fixed with this PR. * Don't match AdaLoraLayer when updating LoraLayers AdaLoraLayer is a subclass of LoraLayer, so just checking for isinstance(target, LoraLayer) will match AdaLoraLayer, which we don't want when it comes to updating a LoraLayer. Now, we explicitly check that the layer is *not* an instance of AdaLoraLayer.
- Loading branch information
1 parent
3708793
commit a0a46c0
Showing
10 changed files
with
122 additions
and
134 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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