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

Add TPUPrecisionPlugin #10020

Merged
merged 9 commits into from
Oct 19, 2021
Merged

Add TPUPrecisionPlugin #10020

merged 9 commits into from
Oct 19, 2021

Conversation

carmocca
Copy link
Contributor

What does this PR do?

Part of #9287

This is necessary because the optimizer_step will be moved to the PrecisionPlugin but it currently lives in the TPUAccelerator.

This PR just introduces the empty class.

Does your PR introduce any breaking changes? If yes, please list them.

None

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

@carmocca carmocca added this to the v1.5 milestone Oct 19, 2021
@carmocca carmocca self-assigned this Oct 19, 2021


class TPUHalfPrecisionPlugin(PrecisionPlugin):
class TPUHalfPrecisionPlugin(TPUPrecisionPlugin):
Copy link
Contributor Author

@carmocca carmocca Oct 19, 2021

Choose a reason for hiding this comment

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

@SeanNaren why was this not done as

class TPUBf16PrecisionPlugin():
    precision: str = "bf16"


# accelerator connector
if self.precision == 16:
    raise Unsupported
elif self.precision == "bf16":
    return TPUBf16PrecisionPlugin

The current format can be confusing for users, perhaps making them believe AMP and TPU work together

We can easily change this, as this is unreleased

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly, I don't get why the NativeMixedPrecisionPluginwas used for bf16 support, considering it doesn't even define the scaler. Why wasn't a Bf16PrecisionPlugin used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment does not block this PR.

I've opened a branch with my ideas: refactor/tpu-precision-plugin...refactor/untangle-bf16

Copy link
Contributor

Choose a reason for hiding this comment

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

If the first question is "why do we make it seem precision=16 is possible for TPUs", is because this was the original default before "bf16" was introduced AFAIK. we could go ahead and deprecate precision=16 for TPUs however precision=16 doesn't even make sense for AMP, so should we deprecate this and go for precision='mixed'? I don't think so personally, and would advise against

Regarding the question of having two separate plugins for BF16 and for Native AMP, unfortunately I can't find where a discussion had place around this. I originally implemented this as two separate plugins but there was enough cross-over with the original plugin to have them in a single plugin. Maybe it makes sense to have them separate, i'm indifferent here

Copy link
Contributor

@kaushikb11 kaushikb11 left a comment

Choose a reason for hiding this comment

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

LGTM!

@mergify mergify bot added the ready PRs ready to be merged label Oct 19, 2021
Copy link
Contributor

@rohitgr7 rohitgr7 left a comment

Choose a reason for hiding this comment

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

small comments

Co-authored-by: Rohit Gupta <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
@carmocca carmocca enabled auto-merge (squash) October 19, 2021 17:10
@codecov
Copy link

codecov bot commented Oct 19, 2021

Codecov Report

Merging #10020 (742c7a6) into master (0aa220b) will increase coverage by 4%.
The diff coverage is 84%.

@@           Coverage Diff            @@
##           master   #10020    +/-   ##
========================================
+ Coverage      89%      93%    +4%     
========================================
  Files         179      180     +1     
  Lines       15810    15852    +42     
========================================
+ Hits        14021    14676   +655     
+ Misses       1789     1176   -613     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready PRs ready to be merged refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants