Fix module target edge cases #2773
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.
Resolves #2772
Fixes several edge cases with unusual layer names or target modules.
"weight"is part of a layer name, it would be treated incorrectly when creating the PEFTstate_dict.Some of these errors would pass silently, which is especially bad (e.g. a weight not being loaded but no error raised).
I also added some tests that were not failing before, but to cover some yet uncovered cases or to lay out some basic functionality.
While working on this, I also noticed that it was possible to target a
BaseTunerLayerwithmodules_to_saveandtrainable_token_indices(e.g. thelora_Aandlora_Bnn.Linearwould be wrapped withModulesToSaveWrapper). I don't think this is ever desired, so we now raise an error if this is detected.Note to reviewers: Please be super diligent in reviewing this and don't hesitate to suggest more tests if you have ideas. It is easy to add a (silent) breaking change here if not careful.