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

Let EarlyStoppingCallback not require load_best_model_at_end #35101

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

muellerzr
Copy link
Contributor

What does this PR do?

This PR tweaks EarlyStoppingCallback to still require a metric, but doesn't need load_best_model_at_end. Doing so lets users still use it, but optionally doesn't require them to load it back in at the end of training if they don't want to.

Fixes # (issue)

Request of @BenjaminBossan

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.

@Rocketknight1 @SunMarc

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM ! Thanks !

@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
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

This one might need a real core maintainer cc @ArthurZucker @LysandreJik! The code looks good, but is there a risk of user confusion if they use EarlyStopping but actually get a checkpoint later than the best one with significantly worse metrics? I think I'd find that behaviour quite surprising.

Copy link
Member

@BenjaminBossan BenjaminBossan 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 the change, from my point of view it's much more intuitive that I can use early stopping without loading the best model at the end. The checkpoint is still there and I can decide to load it if I want to.

but is there a risk of user confusion if they use EarlyStopping but actually get a checkpoint later than the best one with significantly worse metrics? I think I'd find that behaviour quite surprising.

How about just giving a warning? So use the old check but don't error out but only warn. I'm not necessarily happy about adding more warnings, but if users have come to rely on this error to remind them to enable load_best_model_at_the_end, getting a warning could be a good compromise.

@Rocketknight1
Copy link
Member

Hmm, I'm negative on warnings in general, but maybe a single warning at the end of training might be understandable here, given the potential performance damage if users want the best checkpoint but get the one after n epochs of metrics getting worse.

@BenjaminBossan
Copy link
Member

@muellerzr What is your opinion on giving a warning?

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

I have no strong opinion, the less warning the better as long as something is properly documented! 🤗

@BenjaminBossan
Copy link
Member

Let's not forget about this PR, not a lot missing for it to be merged.

@muellerzr
Copy link
Contributor Author

I'll add in the warning now :)

@muellerzr muellerzr merged commit b02828e into main Jan 10, 2025
25 checks passed
@muellerzr muellerzr deleted the muellerzr-load-best-model branch January 10, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants