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

[Feature] enable bf16 in AmpOptimWrapper #960

Merged
merged 18 commits into from
Mar 1, 2023

Conversation

C1rN09
Copy link
Collaborator

@C1rN09 C1rN09 commented Feb 24, 2023

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Enable torch.bfloat16 in AmpOptimWrapper and config file

Modification

New optional argument dtype in AmpOptimWrapper, can be str or torch.dtype

BC-breaking (Optional)

No

Use cases (Optional)

optim_wrapper = dict(
    type='AmpOptimWrapper',
    dtype='bfloat16',  # (None, float32, float16, bfloat16, ...)
    ....
)

Test results

mmcls::resnet50_8xb256-rsb-a3-100e_in1k

setting iter_time memory acc_top1 acc_top5
no amp 0.4230 21665 78.30 93.80
amp float16 0.4239 11481 -- --
amp bfloat16 1.0812 11494 -- --
amp bfloat16 + cudnn8 0.4251 11478 78.42 93.85

Hint: Amp with dtype=torch.bfloat16 works bad on convolutions, because it doesn't use CuDNN by default. Enable CuDNN version bfloat16 convolution by environment variable: TORCH_CUDNN_V8_API_ENABLED=1

mmdet::retinanet_r50_fpn_1x_coco

Failed due to torch.bfloat16 not supported by F.interpolate.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@codecov
Copy link

codecov bot commented Feb 24, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@d8abf9a). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head bc3313a differs from pull request most recent head 4c350c6. Consider uploading reports for the commit 4c350c6 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #960   +/-   ##
=======================================
  Coverage        ?   76.55%           
=======================================
  Files           ?      138           
  Lines           ?    10846           
  Branches        ?     2167           
=======================================
  Hits            ?     8303           
  Misses          ?     2186           
  Partials        ?      357           
Flag Coverage Δ
unittests 76.55% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@C1rN09 C1rN09 marked this pull request as ready for review February 24, 2023 08:31
@C1rN09 C1rN09 requested a review from zhouzaida as a code owner February 24, 2023 08:31
HAOCHENYE
HAOCHENYE previously approved these changes Feb 28, 2023
@CLAassistant
Copy link

CLAassistant commented Mar 1, 2023

CLA assistant check
All committers have signed the CLA.

@zhouzaida zhouzaida merged commit 2ed8e34 into open-mmlab:main Mar 1, 2023
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.

4 participants