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

Default to precision=bf16 on CPU when precision=16 is passed #10033

Merged
merged 13 commits into from Oct 20, 2021

Conversation

carmocca
Copy link
Member

@carmocca carmocca commented Oct 19, 2021

What does this PR do?

With this change, Trainer(precision=16, accelerator='cpu) now runs with precision='bf16' automatically.
This is desirable for no-code-change transitions between environments with different accelerators, for example, local (CPU only) to Colab (GPU or TPU)

Trainer(amp_backend="apex", precision=16, accelerator='cpu') will still raise an error as apex does not support bf16

Part of #10027

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?
  • [n/a] 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 the feature Is an improvement or enhancement label Oct 19, 2021
@carmocca carmocca added this to the v1.5 milestone Oct 19, 2021
@carmocca carmocca self-assigned this Oct 19, 2021
Copy link
Member

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

nice

will you add a changelog entry? because this would be a backward incompatible change since the default type changes

@codecov
Copy link

codecov bot commented Oct 20, 2021

Codecov Report

Merging #10033 (9fbb921) into master (d45897d) will increase coverage by 0%.
The diff coverage is 90%.

@@           Coverage Diff           @@
##           master   #10033   +/-   ##
=======================================
  Coverage      93%      93%           
=======================================
  Files         180      180           
  Lines       15870    15890   +20     
=======================================
+ Hits        14689    14720   +31     
+ Misses       1181     1170   -11     

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

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

LGTM !

@tchaton tchaton enabled auto-merge (squash) October 20, 2021 08:32
if self.precision in (16, "bf16"):

# maybe convert the precision value
if self.precision == 16 and self.use_cpu:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we support Trainer(precision="16"), do we?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so because we don't convert the value to a PrecisionType (which works for int and str)

IMO we should, but should be done in a follow-up. The previous code here had the same check

@tchaton tchaton merged commit f0b3e0f into master Oct 20, 2021
@tchaton tchaton deleted the feat/deafult-to-bf16 branch October 20, 2021 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants