-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[Config, Serialization] more readable config serialization #3797
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
[Config, Serialization] more readable config serialization #3797
Conversation
|
I would prefer v2) because the parameters saved in each of the model configuration files are important for the models behavior and would be nice to see in the config (also to compare to other models' configs) |
|
Need to look into it more but on principle this is very nice. (If Configs were I agree that v2 is probably better, but will think about it some more. For config hosted on our S3, what should we do? Update the official ones, but not the user-uploaded ones? Or just do all of them? :) |
|
I would update all of them by downloading, save_pretrained() and upload. I already a very similar script I would only need to adapt a tiny bit |
thomwolf
left a comment
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.
Ok that's really cool, thanks a lot @patrickvonplaten!
I'm all in for V2!
| self.label2id = dict((key, int(value)) for key, value in self.label2id.items()) | ||
|
|
||
| def save_pretrained(self, save_directory): | ||
| def save_pretrained(self, save_directory, use_diff=True): |
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.
Need to document the additional argument in the docstring.
@LysandreJik we have a script testing that the code of the docstring examples run fine, right?
Could we maybe one day make a similar script that tests that all the arguments in methods signatures with docstrings are mentioned in the associated docstring? I feel like I keep asking people to document their new arguments in the docstring, would be nice to just have a test that fails if it's not done (cc @julien-c @sshleifer)
(I can't think of a good reason you wouldn't want to document an argument in the docstring)
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.
Indeed, usually the IDE does that, but we could definitely look into enforcing it. I can't think of a reason we would want for an argument to not be documented either.
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.
I think https://pypi.org/project/flake8-docstrings/ might be what we're looking for, haven't used it however.
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.
I feel like this should be the only option (i.e., remove the argument completely). i.e., is there really a case where we want the full JSON serialization of the object?
Or at least, remove it from save_pretrained, keep it only on to_json_string() (and then it can default to True there, maybe it's more correct)
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.
(the user of save_pretrained does not really need to know which exact serialization method we use underneath, IMO)
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.
I don't know either but if we can keep a backward compatible option with this flag, why not maybe?
It's kinda hard to think about all the use cases people may have (e.g. loading in an older pytorch-transformers version the configuration which might break now for them).
| return output | ||
|
|
||
| def to_json_string(self): | ||
| def to_json_string(self, use_diff=False): |
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.
Same here, you should document the new argument
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.
Elegant way of doing that! I'm all for V2 as well.
I agree with Thom that arguments should be documented, but other than that it looks great to me!
|
Does this impact the process for changing the default config? |
julien-c
left a comment
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.
Other than my comment, looks great!
| self.label2id = dict((key, int(value)) for key, value in self.label2id.items()) | ||
|
|
||
| def save_pretrained(self, save_directory): | ||
| def save_pretrained(self, save_directory, use_diff=True): |
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.
I feel like this should be the only option (i.e., remove the argument completely). i.e., is there really a case where we want the full JSON serialization of the object?
Or at least, remove it from save_pretrained, keep it only on to_json_string() (and then it can default to True there, maybe it's more correct)
|
Sounds good! |
|
Ok, v2 is now implemented. I agree with @julien-c that the |
|
Awesome, merging this |
Given the discussion in PR: #3433, we want to make the serialized model conf more readable.
Problem:
E.g.
bert-base-casedhas the following config on S3:But when saved all default params are saved as well (which is unnecessary):
Solution:
We should only save the difference of the actual config to either v1) to the model class' config or v2) to the PretrainedConfig() (which contains most of the unnecessary default params).
This PR implements either v1) or v2) - up for discussion!
v1) for
bert-base-casedwould look like this:v2) for
bert-base-casedwould look like this: