-
Notifications
You must be signed in to change notification settings - Fork 31.5k
switch from training_args.bin training_args.json
#35010
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
base: main
Are you sure you want to change the base?
switch from training_args.bin training_args.json
#35010
Conversation
|
cc @muellerzr & @SunMarc for review. |
|
friendly tagging @muellerzr & @SunMarc |
muellerzr
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.
Very nice! I'm a fan of this change. However, we should be careful about old training resumptions from older versions and likely should do a deprecation until 5.0.0 (warning if a .bin was found but we do the shift to .json now)
How does that sound?
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
[don't merge yet I need to fix something fundamental that was not captured by the tests] |
|
cc @muellerzr for feedback originally there was never a mechanism inside of the trainer API to load any training_args and people used to load the training arguments manually, I added something useful which is |
|
friendly tagging @muellerzr here for a review. |
|
cc @muellerzr for review |
SunMarc
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.
Thanks for the PR ! Left a few comments !
src/transformers/training_args.py
Outdated
| if is_accelerate_available() and isinstance(v, AcceleratorConfig): | ||
| d[k] = v.to_dict() | ||
| d[k] = serialize_parameter(k, v) | ||
| self._dict_torch_dtype_to_str(d) |
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.
We can remove this and the function since you took care of that in serialize_parameter. Can you add a comment in serialize_parameter to explain what is happening to torch_dtype ?
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 hope I did not misunderstand you, let me know if this has been resolved after the new changes
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.
Looks fine thanks ! SInce we are not using _dict_torch_dtype_to_str method, you can also remove it in this PR
Co-authored-by: Marc Sun <[email protected]>
…/not-lain/transformers into switch-training_args-file-format
|
the |
|
cc @muellerzr , failing tests are unrelated |
|
friendly tagging @muellerzr for review |
|
cc @muellerzr for review |
|
friendly tagging @muellerzr here for review |
|
cc @muellerzr to see if you can review this |
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 a bunch! fstring nit then passing off to @ArthurZucker :)
(Merged myself though so we can get this in without more delay!)
|
cc @ArthurZucker for review 🤗 |
ArthurZucker
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.
I have no idea where this stands, happy to merge
|
this pr is related to https://github.com/huggingface/transformers/pull/35010/files#diff-bfceaff300c851b8e24fc50dc6638482abaec8f7d2a718e877c3828c166bcf79L223 where it said :
in short this pr :
do not hesitate if you have any questions or follow-ups 🤗 |
|
Can you fix the conflicts ? Then, we will finally be able to merge it ;) |
c468866 to
9a8c9d4
Compare
|
done (≧∇≦)ノ |
| def __new__(self, *args, **kwargs): | ||
| # catch and save only the parameters that the user passed | ||
| self.__training_args_params__ = {} | ||
| param_names = list(self.__dataclass_fields__.keys()) | ||
|
|
||
| for i in range(len(args)): | ||
| self.__training_args_params__[param_names[i]] = serialize_parameter(param_names[i], args[i]) | ||
|
|
||
| for k, v in kwargs.items(): | ||
| self.__training_args_params__[k] = serialize_parameter(k, v) | ||
|
|
||
| return super().__new__(self) | ||
|
|
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.
just a caveat of only storing training params that were passed, if we change the default of any argument in the future, it will impact the training of the model if the user try to resume the training no ? it is a pretty small edge case but still nice to be aware of it.
Also, does this happen with the bin file ?
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 can't deny the fact that when we change the default params the default training arguments will change, but still what if we remove some of the default parameters, the approach introduced in this pr is still more flexible (note that the transformers version and some of these parameters are already part of the readme file so that the user can always have a fallback if they want to )
another good example of how this shows more prospects is that if we change the training device, if the second server supports more default cores then that will be default parameter over there (checkout tpu_num_cores for reference)
In full transparency, in bin, everything is static, and i haven't seen anyone report any problems with it.
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 the details, as this might impact heavily 3rd party library relying on trainer, I'll ask them if this is not too breaking ! cc @qgallouedec @winglian @danielhanchen
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 @SunMarc, no change required on TRL side 👌
What does this PR do?
switch from
training_args.bintotraining_args.jsonand only capture the parameters that the user passedI'm using the same approach we are using in huggingface_hub's PyTorchModelHubMixin to store as little parameters as possible.
a minimalistic approach to test this is pr
using this approach, we ensure that we only store the parameters that the user-defined manually and not the ones that have default values or the ones inferred from the system (ie cpu, cuda, tpu ... ), leaving some room for flexibility.
in a sense the parameters are mutable, meaning the user can physically alter them.
Fixes #34612
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@muellerzr @SunMarc