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

Schedule free optimizer support #2631

Merged
merged 6 commits into from
Apr 8, 2024
Merged

Schedule free optimizer support #2631

merged 6 commits into from
Apr 8, 2024

Conversation

muellerzr
Copy link
Collaborator

What does this PR do?

Facebook recently released an optimizer that doesn't require an LR scheduler. This PR adds support in by enabling optimizers to call .train() and .eval() as a passthrough.

See https://github.com/facebookresearch/schedule_free/tree/main

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.

@BenjaminBossan

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

@muellerzr
Copy link
Collaborator Author

Some general observations off the nlp_example:

Seems to converge faster, here is our baseline vs the new example, read as (accuracy, f1 score):

Basic nlp_example.py:
78.92%, 0.8327
84.8%, 0.8927
85.5%, 89.87

With schedule-free:
79.16%, 0.8622
85.29%, 0.8976
85.29%, 0.8972

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 adding train and eval methods required for scheduler free optimizers! 🚀

@sdbds
Copy link

sdbds commented Apr 8, 2024

By the way, since ScheduleFree doesn't require schedule, do we need to create another noSchedule class specifically?

@muellerzr
Copy link
Collaborator Author

Nope, just don't pass a scheduler to Accelerator.prepare() :)

Not a very complicated implementation needed here

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.

LGTM, thanks for adding this feature and a script to test it. Btw. any idea what would happen if a user forgets to call optimizer.eval()?

I have a comment suggesting to add a training property too, but no blocker.

Sets the optimizer to "eval" mode. Useful for optimizers like `schedule_free`
"""
return self.optimizer.eval()

Copy link
Member

Choose a reason for hiding this comment

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

How about adding a @property for self.optimizer.training too? I don't think we also need a setter for this, as train() and eval() should be enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That gets to be optimizer-specific, so not a fan of it unless its downstreamed, as they currently don't have that: https://github.com/facebookresearch/schedule_free/blob/main/schedulefree/adamw_schedulefree.py#L86

(Otherwise I'd agree, yes that's a good idea)

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, good point.

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.

5 participants