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

Make .zero_grad() signature consistent with PyTorch (set_grads_to_None) #2678

Closed
awaelchli opened this issue Jan 9, 2023 · 2 comments · Fixed by #2741
Closed

Make .zero_grad() signature consistent with PyTorch (set_grads_to_None) #2678

awaelchli opened this issue Jan 9, 2023 · 2 comments · Fixed by #2741
Assignees
Labels
enhancement New feature or request training

Comments

@awaelchli
Copy link
Contributor

Is your feature request related to a problem? Please describe.

The DeepSpeed optimizers have a .zero_grad() method like all optimizers in PyTorch, but the argument that controls whether gradients get zeroed out vs. set to None is named set_grads_to_None

def zero_grad(self, set_grads_to_None=True):

whereas in PyTorch, it is called set_to_none. This inconsistency requires other frameworks that wrap around deepspeed to have a translation depending on whether a PyTorch optimizer or a DeepSpeed optimizer is used.

Describe the solution you'd like

Rename the argument to set_to_none.

Describe alternatives you've considered
Keeping it as is. This is not a major issue, but it would be nice to be consistent with the naming in PyTorch. Less cognitive overhead for users.

Additional context

Example of how it can be translated in other libraries for now:
Lightning-AI/pytorch-lightning#16275

@loadams
Copy link
Contributor

loadams commented Jan 23, 2023

Hi @awaelchli,

I spoke with @tjruwase and @jeffra who agree that it makes sense to change the behavior to match the torch implementation here. I'll link the PR soon.

@loadams loadams linked a pull request Jan 23, 2023 that will close this issue
@awaelchli
Copy link
Contributor Author

Thank you @loadams @jeffra, very nice improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request training
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants