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

zero_grad() between forward and backward passes generates error message #422

Closed
wants to merge 1 commit into from

Conversation

pierrestock
Copy link
Contributor

Summary:
In case of Poisson sampling, we must check that all grad_sample attributes are set to None (since we forbit accumulation with Poisson sampling).

This was previously done in a forward hook, resulting in an error message being thrown inadequately, in particular when zero_grad() is called between the forward and backward steps (see task for more context).

Hence, we instead register a backward hook at the GradSampleModule level (to ensure it's the first hook to be called, before the hooks that populate the grad_sample attribute). Updated the docstring accordingly with more details.

Differential Revision: D36067469

Summary:
In case of Poisson sampling, we must check that all `grad_sample` attributes are set to `None` (since we forbit accumulation with Poisson sampling).

This was previously done in a forward hook, resulting in an error message being thrown inadequately, in particular when `zero_grad()` is called between the forward and backward steps (see task for more context).

Hence, we instead register a backward hook at the `GradSampleModule` level (to ensure it's the first hook to be called, before the hooks that populate the `grad_sample` attribute). Updated the docstring accordingly with more details.

Differential Revision: D36067469

fbshipit-source-id: 583b1865e1d1e30b50f695fa3e7dc1dbb528233d
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels May 2, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D36067469

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants