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

Support auto_fp16 using torch.cuda.amp when PyTorch >= 1.6.0 #951

Merged
merged 4 commits into from
Apr 27, 2021

Conversation

ycxioooong
Copy link
Contributor

This PR enables PyTorch official implementation for automatic mixed-precision training.
It replaces the original Pull Request due to some accident.

@ycxioooong ycxioooong requested review from hellock and ZwwWayne April 15, 2021 13:50
@codecov
Copy link

codecov bot commented Apr 15, 2021

Codecov Report

Merging #951 (3bbca69) into master (54ece10) will decrease coverage by 0.66%.
The diff coverage is 14.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #951      +/-   ##
==========================================
- Coverage   65.64%   64.97%   -0.67%     
==========================================
  Files         149      151       +2     
  Lines        9455     9674     +219     
  Branches     1722     1755      +33     
==========================================
+ Hits         6207     6286      +79     
- Misses       2928     3062     +134     
- Partials      320      326       +6     
Flag Coverage Δ
unittests 64.97% <14.91%> (-0.67%) ⬇️

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

Impacted Files Coverage Δ
mmcv/runner/hooks/optimizer.py 17.74% <10.20%> (-6.01%) ⬇️
mmcv/runner/fp16_utils.py 59.73% <43.75%> (-1.59%) ⬇️
mmcv/runner/base_module.py 78.78% <0.00%> (-0.63%) ⬇️
mmcv/utils/registry.py 98.31% <0.00%> (-0.02%) ⬇️
mmcv/ops/__init__.py 100.00% <0.00%> (ø)
mmcv/ops/box_iou_rotated.py 100.00% <0.00%> (ø)
mmcv/cnn/bricks/transformer.py 0.00% <0.00%> (ø)
mmcv/ops/fused_bias_leakyrelu.py 30.90% <0.00%> (ø)
mmcv/ops/roi_align_rotated.py 75.38% <0.00%> (ø)
mmcv/ops/multi_scale_deform_attn.py 76.66% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54ece10...3bbca69. Read the comment docs.

@ycxioooong ycxioooong requested a review from zhouzaida April 16, 2021 11:03
mmcv/runner/hooks/optimizer.py Outdated Show resolved Hide resolved
mmcv/runner/hooks/optimizer.py Outdated Show resolved Hide resolved
mmcv/runner/hooks/optimizer.py Outdated Show resolved Hide resolved
mmcv/runner/fp16_utils.py Outdated Show resolved Hide resolved
mmcv/runner/fp16_utils.py Outdated Show resolved Hide resolved
@ZwwWayne
Copy link
Collaborator

ZwwWayne commented Apr 22, 2021

Benchmark of MMDetection3D with PyTorch 1.8:

Backbone Lr schd FP32 Mem (GB) FP16 Mem (GB) FP32 mAP FP32 NDS FP16 mAP FP16 NDS
FPN 2x 16.4 8.37 40.0 53.3 39.27 52.95
RegNet-400MF-FPN 2x 17.3 8.37 44.8 56.4 45.22 56.81

Benchmark of MMDetection3D with PyTorch 1.5:

Backbone Lr schd FP32 Mem (GB) FP16 Mem (GB) FP32 mAP FP32 NDS FP16 mAP FP16 NDS
FPN 2x 16.4 8.40 40.0 53.3 39.06 52.71
RegNet-400MF-FPN 2x 17.3 8.41 44.8 56.4 44.38 56.59

Benchmark of MMDetection with PyTorch 1.8:

Architecture Backbone Style Lr schd Mem (GB) Inf time (fps) box AP mask AP FP16 box AP FP16 mask AP
Faster R-CNN R-50 pytorch 1x 2.8 - 37.4 - 37.3 -
Mask R-CNN R-50 pytorch 1x 3.6 - 38.2 34.7 38.2 34.6
Retinanet R-50 pytorch 1x 2.7 - 36.7 - 36.5 -

Benchmark of MMDetection with PyTorch 1.5:

Architecture Backbone Style Lr schd Mem (GB) Inf time (fps) box AP mask AP FP16 box AP FP16 mask AP
Faster R-CNN R-50 pytorch 1x 3.1 - 37.4 - 37.3 -
Mask R-CNN R-50 pytorch 1x 3.1 - 38.2 34.7 38.3 34.7
Retinanet R-50 pytorch 1x 2.76 - 36.7 - 36.2 -

@ZwwWayne ZwwWayne self-assigned this Apr 24, 2021
Copy link
Collaborator

@xvjiarui xvjiarui left a comment

Choose a reason for hiding this comment

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

Verified in MMSeg

"""Copy updated params from fp32 weight copy to fp16 model."""
for fp16_param, fp32_param in zip(fp16_net.parameters(), fp32_weights):
fp16_param.data.copy_(fp32_param.data)
if TORCH_VERSION != 'parrots' and TORCH_VERSION >= '1.6.0':
Copy link
Collaborator

Choose a reason for hiding this comment

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

Last comment: The indentation is a little bit annoying. Can we create two hooks first, namely PT16Fp16OptimizerHook and PT15Fp16OptimizerHook, then assign one of them to Fp16OptimizerHook according to the version?

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.

5 participants