Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

fix a bug when using fp16 training & gradient clipping #5426

Merged
merged 3 commits into from
Oct 7, 2021

Conversation

YKX-A
Copy link
Contributor

@YKX-A YKX-A commented Sep 30, 2021

Fixes # .

Changes proposed in this pull request:

Before submitting

  • I've read and followed all steps in the Making a pull request
    section of the CONTRIBUTING docs.
  • I've updated or added any relevant docstrings following the syntax described in the
    Writing docstrings section of the CONTRIBUTING docs.
  • If this PR fixes a bug, I've added a test that will fail without my fix.
  • If this PR adds a new feature, I've added tests that sufficiently cover my new functionality.

After submitting

  • All GitHub Actions jobs for my pull request have passed.
  • codecov/patch reports high test coverage (at least 90%).
    You can find this under the "Actions" tab of the pull request once the other checks have finished.

@epwalsh
Copy link
Member

epwalsh commented Oct 1, 2021

@YKX-A can you run black . from the repo root to fix formatting.

Copy link
Member

@epwalsh epwalsh left a comment

Choose a reason for hiding this comment

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

This looks great other than the minor formatting issues!

# 1. We have to unscale the gradient before clipping
if self._scaler is not None:
optimizer_state = self._scaler._per_optimizer_states[id(self.optimizer)]
# 2. The `unscale_` should't be performed more than once per optimizer per step call,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# 2. The `unscale_` should't be performed more than once per optimizer per step call,
# 2. The `unscale_` shouldn't be performed more than once per optimizer per step call,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's my ignorance 😰. Is it correct now?

@YKX-A
Copy link
Contributor Author

YKX-A commented Oct 4, 2021

@epwalsh

Copy link
Member

@epwalsh epwalsh 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 @YKX-A 🙂

@epwalsh epwalsh merged commit 17ef1aa into allenai:main Oct 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants