-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Adding optimizer_cls_and_kwargs
to Trainer.__init__
#34358
Adding optimizer_cls_and_kwargs
to Trainer.__init__
#34358
Conversation
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.
Nice! Seems like a great fix :)
If you do |
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 ! LGTM ! I'm curious about why the optimizers args is not enough for you use case ?
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. |
Great, thanks both! @muellerzr I had already run
|
@SunMarc I am writing a codebase that uses I believe the |
Most checks pass now! A few tests in |
Makes sense ! Thanks for explaining ! Maybe you can add a note explaining that in the description of the arg. As for the CI, this PR is indeed unrelated. We will fix it shortly ! |
For sure! Done. |
Sorry for the wait ! When the CI is fixed from our side, we will merge the PR @apoorvkh |
Sounds great, thanks! |
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, would you like to add a bit of documentation for discoverability? With an example use case maybe? 🤗
Sure, how do those changes to |
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.
LGTM thanks
…34358) * Adding `optimizer_cls_and_kwargs` to `Trainer.__init__` * formatting * make fix-copies docstring * added more docs for optimizer_cls_and_kwargs * add docs for Trainer(optimizer_cls_and_kwargs) * reverting anchor names
…34358) * Adding `optimizer_cls_and_kwargs` to `Trainer.__init__` * formatting * make fix-copies docstring * added more docs for optimizer_cls_and_kwargs * add docs for Trainer(optimizer_cls_and_kwargs) * reverting anchor names
…34358) * Adding `optimizer_cls_and_kwargs` to `Trainer.__init__` * formatting * make fix-copies docstring * added more docs for optimizer_cls_and_kwargs * add docs for Trainer(optimizer_cls_and_kwargs) * reverting anchor names
What does this PR do?
Currently,
Trainer
must be extended (as follows) to provide a customtorch.optim.Optimizer
. The existingoptimizers
argument forTrainer
assumes the model is already initialized on the correct devices (which is usually handled byTrainer
).This PR adds an
optimizer_cls_and_kwargs
argument toTrainer
. This simply allows a user to passType[torch.optim.Optimizer]
andDict[str, Any]
when initializing theTrainer
rather than having to extend the class (as above).I am making this PR after #31875 (cc: @amyeroberts @muellerzr)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.