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

Fix FusedAdam.zero_grad(set_to_none=True) #1579

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NouamaneTazi
Copy link
Contributor

@NouamaneTazi NouamaneTazi commented Feb 6, 2023

This PR adds support for set_to_none for FusedAdam.
According to pytorch/pytorch#92731 we set set_to_none=True by default, in accordance to current Pytorch master. see #1579 (comment)

@@ -94,8 +94,8 @@ def __init__(self, params, lr=1e-3, bias_correction=True,
else:
raise RuntimeError('apex.optimizers.FusedAdam requires cuda extensions')

def zero_grad(self):
if self.set_grad_none:
def zero_grad(self, set_to_none=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

QQ: why is the default None? Given that the default of set_grad_none' and torch.optim.Optimizer.zero_grad's set_to_none is True, it'd make sense to make it default to True to me

Choose a reason for hiding this comment

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

Also would it make sense to check that set_to_none and self.set_grad_none are the same? Raise a RunTimeError if they are not?

Choose a reason for hiding this comment

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

Also note that this is a breaking change from torch. It defaults to False in 1.13 and True in master. Not sure which one would make more sense here.

Comment on lines +97 to +98
def zero_grad(self, set_to_none=True):
if self.set_grad_none or set_to_none:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gently pinging @crcrpar
Does this look good to you? :)

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.

3 participants