Fix target_modules type in config.from_pretrained #1046
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 #1045, supersedes #1041
Description
When loading a config from a file, we currently set the loaded attributes on the config directly. However, this sidesteps the
__post_init__
call, which is required to convert the target_modules to a set. This PR fixes this by avoiding to set attributes on the config class directly, instead of going through__init__
.Other changes
While working on this, I did a slight refactor of the config tests.
parameterized
instead of looping through the classes. Note that this makes the diff look much bigger than it actually is, the tests are actually unchanged, just unindented by one level because the loop is removed.Notes
This fix is based on my comment here:
#1041 (review)
Normally, I'd just wait for Sourab to reply, but since he's off for a few days, I created a separate PR.
Another way we could achieve this is to override
__setattr__
on the config class which explicitly convertstarget_modules
to a set. This would cover the case where a user does something like this:Using
__setattr__
, we wouldn't need to rely on__post_init__
. However, I would propose to save the heavy guns for when absolutely necessary.