Skip to content
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

Enforce saving at end of training if saving option chosen #30160

Merged
merged 6 commits into from
May 21, 2024

Conversation

muellerzr
Copy link
Contributor

What does this PR do?

Currently we save at the end of training if an epoch strategy is chosen, but not if a steps strategy is chosen. This can be undesireable because the end of a users training might not be saved at all, sometimes upwards of 10% as seen here: #28539

This PR mimics the behavior of epoch, by choosing to save the model at the end of training as well if steps is chosen.

I do not believe it makes sense to make this configurable, because a user should always have access to the end-resulting model when training!

Fixes #28539

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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.

@amyeroberts @pacman100

@muellerzr
Copy link
Contributor Author

We can certainly make this configurable as an arg, but I'm not sure it makes sense to do this

@HuggingFaceDocBuilderDev

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.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Agreed I think always saving on the last step is a good idea.

Just some questions about the tests

tests/trainer/test_trainer.py Show resolved Hide resolved
tests/trainer/test_trainer.py Show resolved Hide resolved
tests/trainer/test_trainer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @muellerzr, for enabling the model to be saved at the end of training when using --save_steps strategy. Left a nit.

src/transformers/trainer_callback.py Outdated Show resolved Hide resolved
@muellerzr muellerzr requested a review from amyeroberts April 29, 2024 17:29
@muellerzr
Copy link
Contributor Author

@amyeroberts good for a rereview, no functional changes happened just switched out the test logic to be more obvious what's going on

@muellerzr muellerzr force-pushed the muellerzr-load-best-model branch from cc684e5 to 9bbb268 Compare April 29, 2024 17:58
@muellerzr muellerzr force-pushed the muellerzr-load-best-model branch from ef951dc to 4002cb8 Compare May 15, 2024 18:47
@muellerzr muellerzr requested a review from pacman100 May 15, 2024 18:53
Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding!

@muellerzr muellerzr merged commit daf281f into main May 21, 2024
21 checks passed
@muellerzr muellerzr deleted the muellerzr-load-best-model branch May 21, 2024 11:50
itazap pushed a commit that referenced this pull request May 21, 2024
* Enforce saving at end of training

* Fix test

* Rework test

* Fixup tests'

* Update comment based on sourab feedback

* Clean
itazap pushed a commit that referenced this pull request May 21, 2024
* Enforce saving at end of training

* Fix test

* Rework test

* Fixup tests'

* Update comment based on sourab feedback

* Clean
itazap pushed a commit that referenced this pull request May 22, 2024
* Enforce saving at end of training

* Fix test

* Rework test

* Fixup tests'

* Update comment based on sourab feedback

* Clean
itazap pushed a commit that referenced this pull request May 24, 2024
* Enforce saving at end of training

* Fix test

* Rework test

* Fixup tests'

* Update comment based on sourab feedback

* Clean
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Jun 11, 2024
…e#30160)

* Enforce saving at end of training

* Fix test

* Rework test

* Fixup tests'

* Update comment based on sourab feedback

* Clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

load_best_model_at_end is inconsistent with evaluation (and save) logic at end of training
4 participants