FIX Bug with modules_to_save loading if substring #2334
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.
Fixes #2289
This bug was the result of an error in the logic of modifying the
state_dict
formodules_to_save
inset_peft_model_state_dict
. The error in the logic was that it was checked if an entry frommodules_to_save
(a set of strings) is a substring of a key of thestate_dict
. If it was, a new name was assigned to that key in thestate_dict
, which would allow to load the weight later.The issue that stems from the substring check occurs if there are multiple
modules_to_save
, and one of them has a name that is a substring of another. So e.g. if one is named"classifier"
and the other is named"classifier2"
, there could be a false match.This PR fixes the issue by enclosing the string with
"."
, i.e. we now check if".classifier."
is a substring instead, which avoid false matches.What made this bug even harder to debug was that
modules_to_save
is a set and therefore has no predetermined order. Therefore, the bug would be flaky. To address this,modules_to_save
is now sorted before iterating over it. That doesn't contribute to resolving the bug, but it makes the bug non-flaky, allowing future debugging to be easier.