-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix loading pretrained config #1041
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this bug. I wonder if another solution would not be better: Instead of calling __post_init__
twice (once implicitly via the constructor, once explicitly), can we update the class_kwargs
using the loaded_attributes
before calling config = config_cls(**class_kwargs)
and have the same effect?
Fixes huggingface#1045, supersedes huggingface#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. 1. All config classes are included now (some where missing before). 2. Use parameterized instead of looping through the classes. 3. Added a unit test for the aforementioned bug. Notes This fix is based on my comment here: huggingface#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 converts target_modules to a set. This would cover the case where a user does something like: config = ... config.target_modules = ["a", "b", "c"] Then we don't need to rely on __post_init__. However, I would propose to save the heavy guns for when absolutely necessary.
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. 1. All config classes are included now (some where missing before). 2. Use parameterized instead of looping through the classes. 3. Added a unit test for the aforementioned bug.
@pacman100 This PR should be superseded by the change here: I'll leave this PR open for now in case you want to double-check. |
What does this PR do?