-
Notifications
You must be signed in to change notification settings - Fork 7k
[WIP] Allow autocast for 1.6 #2384
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Can you add some full model-forward test in a similar location as
Lines 273 to 293 in 5247f7b
@unittest.skipIf(not torch.cuda.is_available(), 'needs GPU') | |
def test_fasterrcnn_switch_devices(self): | |
model = models.detection.fasterrcnn_resnet50_fpn(num_classes=50, pretrained_backbone=False) | |
model.cuda() | |
model.eval() | |
input_shape = (3, 300, 300) | |
x = torch.rand(input_shape, device='cuda') | |
model_input = [x] | |
out = model(model_input) | |
self.assertIs(model_input[0], x) | |
self.assertEqual(len(out), 1) | |
self.assertTrue("boxes" in out[0]) | |
self.assertTrue("scores" in out[0]) | |
self.assertTrue("labels" in out[0]) | |
# now switch to cpu and make sure it works | |
model.cpu() | |
x = x.cpu() | |
out_cpu = model([x]) | |
self.assertTrue("boxes" in out_cpu[0]) | |
self.assertTrue("scores" in out_cpu[0]) | |
self.assertTrue("labels" in out_cpu[0]) |
and also add a forward-backward test for
roi_align
after Lines 290 to 291 in 5247f7b
def _test_boxes_shape(self): | |
self._helper_boxes_shape(ops.roi_align) |
Codecov Report
@@ Coverage Diff @@
## master #2384 +/- ##
==========================================
+ Coverage 70.65% 71.36% +0.70%
==========================================
Files 94 94
Lines 7897 8328 +431
Branches 1241 1385 +144
==========================================
+ Hits 5580 5943 +363
- Misses 1934 1972 +38
- Partials 383 413 +30
Continue to review full report at Codecov.
|
Test failures seem related |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot Michael!
* Fixes Xiao's repro * Ports nms to use full dispatcher * Move HIPGuard to nms_cuda * clang-format * run models in test_models.py on GPU if available * Francisco's comment, also disable cuda model tests to see if CPU alone still passes * cuda tests now pass locally, although still not comparing to saved numerics * add note for thing to ask francisco * Allow cuda and cpu tests to share a data file * ignore suffix if unneeded * Skip autocast numerics checks for a few models * Add roi_align test Co-authored-by: Michael Carilli <mcarilli@nvidia.com>
* Fixes Xiao's repro * Ports nms to use full dispatcher * Move HIPGuard to nms_cuda * clang-format * run models in test_models.py on GPU if available * Francisco's comment, also disable cuda model tests to see if CPU alone still passes * cuda tests now pass locally, although still not comparing to saved numerics * add note for thing to ask francisco * Allow cuda and cpu tests to share a data file * ignore suffix if unneeded * Skip autocast numerics checks for a few models * Add roi_align test Co-authored-by: Michael Carilli <mcarilli@nvidia.com> Co-authored-by: mcarilli <mcarilli@gmail.com> Co-authored-by: Michael Carilli <mcarilli@nvidia.com>
This PR introduces a minimal set of diffs that enable torchvision models to work with
torch.cuda.amp.autocast
. Custom C++ ops (roi_align
andnms
) require the most attention.In later modifications to Pytorch, I'll allow external libs to use Pytorch's internal autocast utilities, after which this code can be made cleaner. For 1.6, however, copy pasting some utilities is the best we can do.
Should close pytorch/pytorch#37735.