Repository navigation
[Dist Profiling] Enable dist profiling for DDP (gloo-only) - #52031
rohan-varma wants to merge 6 commits into
Conversation
Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/) [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit f4a9fd8 (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/) [ghstack-poisoned]
Pull Request resolved: #52031 Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. ghstack-source-id: 121426558 Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/)
Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/) [ghstack-poisoned]
Pull Request resolved: #52031 Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. ghstack-source-id: 121458771 Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/)
| self.require_backward_grad_sync = old_require_backward_grad_sync | ||
|
|
||
| def forward(self, *inputs, **kwargs): | ||
| self.reducer.save_thread_local_state() |
There was a problem hiding this comment.
multi threads could be spawned after this, will it have problems? e.g., single process multiple services will run multi threads to compute outputs afterwards.
just curious, what kind of thread local states are saved here (e.g., profiler enable flag and else?)? is it large?
There was a problem hiding this comment.
I don't think there's a problem if multiple threads are spawned in forward after this, if those are spawned with torch.jit.fork which is the recommendation for inter-op parallelism, then the profiler enabled flag should be carried over transparently.
the full structure is in aten/ThreadLocalState.h, the flags are not very large, it's basically dispatch key, thread-local debug info struct (pointer to debug info struct), and an instance of RecordFunctiontls specifying the callbacks to be run.
There was a problem hiding this comment.
sounds good, thanks for clarification
| events = get_profiling_event(all_reduce_event_name, prof) | ||
| self.assertEqual(1, len(events)) | ||
| self.assertEqual(1, events[0].count) | ||
| self.assertEqual(events[0].name, all_reduce_event_name) |
There was a problem hiding this comment.
could we paste some profiling numbers in test plans? e.g., paste all reduce time for resnet and roberta models, would like to check whether the number is aligned with the benchmarking time measurements. thanks!
There was a problem hiding this comment.
Sure, will update the PR with measurements. Although, when comparing to benchmark, doesn't benchmark only report overall fwd/bwd/optimizer? This will provide more granular breakdowns (i.e. actual tensor ops and all_reduce), not sure if the two will be directly comparable?
There was a problem hiding this comment.
Also, note that we don't expect the events on GPU with ProcessGroupNCCL to be correct, since that work is blocked on removing cudaEvent initialization, which causes deadlock in profiler when run with DDP currently: #48987 (cc @ilia-cher)
There was a problem hiding this comment.
wanted to compare whether the autograd profiler all reduce time is aligned with what #51386 got:).
I see, if the GPU measurement is still pending on fix, could you please document somewhere in our codes or so? so that users will know the GPU measure is not ready yet.
There was a problem hiding this comment.
Sounds good, let me patch that diff and compare them. I only expect it to work for Gloo right now, will add a comment for NCCL as you suggested.
There was a problem hiding this comment.
Filed issue for nccl allreduce not being profiled correctly - #52246
Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/) [ghstack-poisoned]
Pull Request resolved: #52031 Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. ghstack-source-id: 121507507 Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/)
|
Profiling stats added to diff summary from benchmark (cc @zhaojuanmao) |
Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. Example profiler output: ``` --- profiler output --- ------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ Name Self CPU % Self CPU CPU total % CPU total CPU time avg # of Calls ------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ aten::zeros 0.02% 1.286ms 0.04% 2.317ms 9.269us 250 aten::empty 2.46% 139.753ms 2.46% 139.753ms 3.692us 37850 aten::zero_ 0.57% 32.356ms 1.69% 95.893ms 11.710us 8189 Optimizer.zero_grad#SGD.zero_grad 0.76% 43.341ms 2.44% 138.211ms 2.764ms 50 ##forward## 3.96% 224.532ms 52.91% 3.003s 60.066ms 50 aten::conv2d 0.24% 13.769ms 35.68% 2.025s 764.201us 2650 aten::convolution 0.21% 11.962ms 35.44% 2.011s 759.005us 2650 aten::_convolution 0.33% 18.730ms 35.23% 1.999s 754.491us 2650 aten::cudnn_convolution 34.52% 1.959s 34.90% 1.981s 747.424us 2650 aten::resize_ 0.31% 17.578ms 0.31% 17.578ms 1.099us 16000 aten::add 5.26% 298.485ms 5.26% 298.485ms 27.896us 10700 aten::batch_norm 1.17% 66.258ms 4.77% 270.590ms 102.110us 2650 aten::_batch_norm_impl_index 0.18% 10.140ms 3.60% 204.333ms 77.107us 2650 aten::cudnn_batch_norm 1.89% 107.001ms 3.42% 194.192ms 73.280us 2650 aten::empty_like 0.42% 23.997ms 1.07% 60.976ms 21.395us 2850 aten::view 0.16% 9.245ms 0.16% 9.245ms 1.712us 5400 aten::relu_ 0.37% 20.940ms 1.00% 56.690ms 23.139us 2450 aten::clamp_min_ 0.13% 7.375ms 0.63% 35.751ms 14.592us 2450 aten::clamp_min 0.50% 28.376ms 0.50% 28.376ms 11.582us 2450 aten::max_pool2d 0.01% 290.066us 0.06% 3.551ms 71.015us 50 aten::max_pool2d_with_indices 0.03% 1.796ms 0.06% 3.261ms 65.214us 50 aten::add_ 7.84% 445.010ms 7.84% 445.010ms 18.069us 24628 aten::adaptive_avg_pool2d 0.00% 250.128us 0.03% 1.840ms 36.802us 50 aten::mean 0.02% 1.407ms 0.03% 1.590ms 31.800us 50 aten::flatten 0.01% 311.540us 0.01% 675.223us 13.504us 50 aten::linear 0.01% 323.419us 6.39% 362.882ms 7.258ms 50 aten::t 0.02% 1.084ms 0.04% 1.987ms 7.946us 250 aten::transpose 0.01% 692.119us 0.02% 902.644us 3.611us 250 aten::as_strided 0.01% 328.524us 0.01% 328.524us 0.939us 350 aten::addmm 6.37% 361.387ms 6.38% 361.876ms 7.238ms 50 aten::expand 0.01% 534.119us 0.01% 652.118us 6.521us 100 aten::log_softmax 0.00% 247.116us 0.06% 3.642ms 72.843us 50 aten::_log_softmax 0.02% 1.215ms 0.06% 3.395ms 67.900us 50 aten::nll_loss 0.00% 202.413us 0.08% 4.692ms 93.835us 50 aten::nll_loss_forward 0.08% 4.489ms 0.08% 4.489ms 89.787us 50 ##backward## 14.84% 842.295ms 14.87% 843.895ms 16.878ms 50 aten::ones_like 0.01% 296.675us 0.03% 1.519ms 30.377us 50 aten::empty_strided 0.35% 19.587ms 0.35% 19.587ms 52.653us 372 aten::fill_ 1.13% 64.276ms 1.13% 64.276ms 8.046us 7989 NllLossBackward 0.01% 582.140us 0.06% 3.150ms 63.003us 50 aten::nll_loss_backward 0.05% 2.568ms 0.05% 2.568ms 51.360us 50 LogSoftmaxBackward 0.00% 271.089us 0.03% 1.786ms 35.729us 50 aten::_log_softmax_backward_data 0.02% 1.089ms 0.03% 1.515ms 30.307us 50 AddmmBackward 0.01% 755.684us 0.09% 5.079ms 101.586us 50 aten::conj 0.00% 123.877us 0.00% 123.877us 1.239us 100 aten::mm 0.05% 2.865ms 0.06% 3.166ms 31.659us 100 torch::autograd::AccumulateGrad 0.40% 22.634ms 2.15% 121.869ms 15.139us 8050 aten::new_empty_strided 0.01% 402.761us 0.20% 11.431ms 71.000us 161 aten::copy_ 0.08% 4.548ms 0.08% 4.548ms 14.124us 322 TBackward 0.00% 81.739us 0.01% 351.344us 7.027us 50 ViewBackward 0.00% 136.836us 0.01% 395.594us 7.912us 50 aten::reshape 0.00% 99.680us 0.00% 258.758us 5.175us 50 MeanBackward1 0.01% 334.648us 0.04% 2.338ms 46.758us 50 aten::to 0.00% 42.767us 0.00% 42.767us 0.855us 50 aten::div 0.02% 1.364ms 0.03% 1.533ms 30.670us 50 ReluBackward1 0.14% 8.066ms 0.84% 47.775ms 19.500us 2450 aten::threshold_backward 0.59% 33.770ms 0.70% 39.709ms 16.208us 2450 AddBackward0 0.02% 918.475us 0.02% 918.475us 1.148us 800 CudnnBatchNormBackward 0.35% 20.027ms 2.82% 160.048ms 60.396us 2650 aten::cudnn_batch_norm_backward 2.03% 115.475ms 2.47% 140.021ms 52.838us 2650 CudnnConvolutionBackward 0.27% 15.408ms 6.75% 383.022ms 144.536us 2650 aten::cudnn_convolution_backward 0.51% 29.065ms 6.48% 367.613ms 138.722us 2650 aten::cudnn_convolution_backward_input 3.25% 184.616ms 3.59% 203.921ms 78.431us 2600 aten::cudnn_convolution_backward_weight 1.93% 109.688ms 2.37% 134.628ms 50.803us 2650 MaxPool2DWithIndicesBackward 0.01% 322.421us 0.05% 2.885ms 57.699us 50 aten::max_pool2d_with_indices_backward 0.02% 1.106ms 0.05% 2.563ms 51.250us 50 aten::zeros_like 0.00% 202.960us 0.02% 1.293ms 25.853us 50 aten::resize_as_ 0.00% 143.984us 0.00% 163.491us 3.270us 50 ##optimizer## 0.02% 1.255ms 16.75% 950.518ms 19.010ms 50 Optimizer.step#SGD.step 3.17% 179.900ms 16.72% 948.949ms 18.979ms 50 aten::clone 0.02% 1.040ms 0.20% 11.248ms 69.863us 161 aten::detach 0.00% 131.024us 0.01% 296.224us 1.840us 161 detach 0.00% 165.200us 0.00% 165.200us 1.026us 161 aten::mul_ 2.76% 156.517ms 2.76% 156.517ms 19.840us 7889 ------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ``` Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/) [ghstack-poisoned]
Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. Example profiler output: ``` --- profiler output --- ------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ Name Self CPU % Self CPU CPU total % CPU total CPU time avg # of Calls ------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ aten::zeros 0.02% 1.286ms 0.04% 2.317ms 9.269us 250 aten::empty 2.46% 139.753ms 2.46% 139.753ms 3.692us 37850 aten::zero_ 0.57% 32.356ms 1.69% 95.893ms 11.710us 8189 Optimizer.zero_grad#SGD.zero_grad 0.76% 43.341ms 2.44% 138.211ms 2.764ms 50 ##forward## 3.96% 224.532ms 52.91% 3.003s 60.066ms 50 aten::conv2d 0.24% 13.769ms 35.68% 2.025s 764.201us 2650 aten::convolution 0.21% 11.962ms 35.44% 2.011s 759.005us 2650 aten::_convolution 0.33% 18.730ms 35.23% 1.999s 754.491us 2650 aten::cudnn_convolution 34.52% 1.959s 34.90% 1.981s 747.424us 2650 aten::resize_ 0.31% 17.578ms 0.31% 17.578ms 1.099us 16000 aten::add 5.26% 298.485ms 5.26% 298.485ms 27.896us 10700 aten::batch_norm 1.17% 66.258ms 4.77% 270.590ms 102.110us 2650 aten::_batch_norm_impl_index 0.18% 10.140ms 3.60% 204.333ms 77.107us 2650 aten::cudnn_batch_norm 1.89% 107.001ms 3.42% 194.192ms 73.280us 2650 aten::empty_like 0.42% 23.997ms 1.07% 60.976ms 21.395us 2850 aten::view 0.16% 9.245ms 0.16% 9.245ms 1.712us 5400 aten::relu_ 0.37% 20.940ms 1.00% 56.690ms 23.139us 2450 aten::clamp_min_ 0.13% 7.375ms 0.63% 35.751ms 14.592us 2450 aten::clamp_min 0.50% 28.376ms 0.50% 28.376ms 11.582us 2450 aten::max_pool2d 0.01% 290.066us 0.06% 3.551ms 71.015us 50 aten::max_pool2d_with_indices 0.03% 1.796ms 0.06% 3.261ms 65.214us 50 aten::add_ 7.84% 445.010ms 7.84% 445.010ms 18.069us 24628 aten::adaptive_avg_pool2d 0.00% 250.128us 0.03% 1.840ms 36.802us 50 aten::mean 0.02% 1.407ms 0.03% 1.590ms 31.800us 50 aten::flatten 0.01% 311.540us 0.01% 675.223us 13.504us 50 aten::linear 0.01% 323.419us 6.39% 362.882ms 7.258ms 50 aten::t 0.02% 1.084ms 0.04% 1.987ms 7.946us 250 aten::transpose 0.01% 692.119us 0.02% 902.644us 3.611us 250 aten::as_strided 0.01% 328.524us 0.01% 328.524us 0.939us 350 aten::addmm 6.37% 361.387ms 6.38% 361.876ms 7.238ms 50 aten::expand 0.01% 534.119us 0.01% 652.118us 6.521us 100 aten::log_softmax 0.00% 247.116us 0.06% 3.642ms 72.843us 50 aten::_log_softmax 0.02% 1.215ms 0.06% 3.395ms 67.900us 50 aten::nll_loss 0.00% 202.413us 0.08% 4.692ms 93.835us 50 aten::nll_loss_forward 0.08% 4.489ms 0.08% 4.489ms 89.787us 50 ##backward## 14.84% 842.295ms 14.87% 843.895ms 16.878ms 50 aten::ones_like 0.01% 296.675us 0.03% 1.519ms 30.377us 50 aten::empty_strided 0.35% 19.587ms 0.35% 19.587ms 52.653us 372 aten::fill_ 1.13% 64.276ms 1.13% 64.276ms 8.046us 7989 NllLossBackward 0.01% 582.140us 0.06% 3.150ms 63.003us 50 aten::nll_loss_backward 0.05% 2.568ms 0.05% 2.568ms 51.360us 50 LogSoftmaxBackward 0.00% 271.089us 0.03% 1.786ms 35.729us 50 aten::_log_softmax_backward_data 0.02% 1.089ms 0.03% 1.515ms 30.307us 50 AddmmBackward 0.01% 755.684us 0.09% 5.079ms 101.586us 50 aten::conj 0.00% 123.877us 0.00% 123.877us 1.239us 100 aten::mm 0.05% 2.865ms 0.06% 3.166ms 31.659us 100 torch::autograd::AccumulateGrad 0.40% 22.634ms 2.15% 121.869ms 15.139us 8050 aten::new_empty_strided 0.01% 402.761us 0.20% 11.431ms 71.000us 161 aten::copy_ 0.08% 4.548ms 0.08% 4.548ms 14.124us 322 TBackward 0.00% 81.739us 0.01% 351.344us 7.027us 50 ViewBackward 0.00% 136.836us 0.01% 395.594us 7.912us 50 aten::reshape 0.00% 99.680us 0.00% 258.758us 5.175us 50 MeanBackward1 0.01% 334.648us 0.04% 2.338ms 46.758us 50 aten::to 0.00% 42.767us 0.00% 42.767us 0.855us 50 aten::div 0.02% 1.364ms 0.03% 1.533ms 30.670us 50 ReluBackward1 0.14% 8.066ms 0.84% 47.775ms 19.500us 2450 aten::threshold_backward 0.59% 33.770ms 0.70% 39.709ms 16.208us 2450 AddBackward0 0.02% 918.475us 0.02% 918.475us 1.148us 800 CudnnBatchNormBackward 0.35% 20.027ms 2.82% 160.048ms 60.396us 2650 aten::cudnn_batch_norm_backward 2.03% 115.475ms 2.47% 140.021ms 52.838us 2650 CudnnConvolutionBackward 0.27% 15.408ms 6.75% 383.022ms 144.536us 2650 aten::cudnn_convolution_backward 0.51% 29.065ms 6.48% 367.613ms 138.722us 2650 aten::cudnn_convolution_backward_input 3.25% 184.616ms 3.59% 203.921ms 78.431us 2600 aten::cudnn_convolution_backward_weight 1.93% 109.688ms 2.37% 134.628ms 50.803us 2650 MaxPool2DWithIndicesBackward 0.01% 322.421us 0.05% 2.885ms 57.699us 50 aten::max_pool2d_with_indices_backward 0.02% 1.106ms 0.05% 2.563ms 51.250us 50 aten::zeros_like 0.00% 202.960us 0.02% 1.293ms 25.853us 50 aten::resize_as_ 0.00% 143.984us 0.00% 163.491us 3.270us 50 ##optimizer## 0.02% 1.255ms 16.75% 950.518ms 19.010ms 50 Optimizer.step#SGD.step 3.17% 179.900ms 16.72% 948.949ms 18.979ms 50 aten::clone 0.02% 1.040ms 0.20% 11.248ms 69.863us 161 aten::detach 0.00% 131.024us 0.01% 296.224us 1.840us 161 detach 0.00% 165.200us 0.00% 165.200us 1.026us 161 aten::mul_ 2.76% 156.517ms 2.76% 156.517ms 19.840us 7889 ------------------------------------------- ------------ ------------ ------------ ------------ ------------ ------------ ``` Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/) [ghstack-poisoned]
Pull Request resolved: #52031 Closes #52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. ghstack-source-id: 121818080 Differential Revision: [D26356192](https://our.internmc.facebook.com/intern/diff/D26356192/) **NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D26356192/)!
|
@rohan-varma thanks for benchmarking, but I did not see "all reduce" op in the list..? |
My bad, I accidently copied wrong profiler output (benchmark does a local run before run with DDP). Updated it with the DDP run profile and there is a |
|
cool thanks! |
|
Posted perf measurements in internal diff to ensure this change doesn't regress ddp qps. |
|
This pull request has been merged in 6dabe0b. |
…2031) Summary: Pull Request resolved: pytorch#52031 Closes pytorch#52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. ghstack-source-id: 121818080 Test Plan: CI Reviewed By: zhaojuanmao Differential Revision: D26356192 fbshipit-source-id: 0158b5833a3f857a0b4b2943ae3037e9d998dfd1
…2031) Summary: Pull Request resolved: pytorch#52031 Closes pytorch#52020 Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread. ghstack-source-id: 121818080 Test Plan: CI Reviewed By: zhaojuanmao Differential Revision: D26356192 fbshipit-source-id: 0158b5833a3f857a0b4b2943ae3037e9d998dfd1
Stack from ghstack:
Closes #52020
Ensures that we can profile collectives in DDP by propagating the profiler threadLocalState appropriately. As described in the above issue, before this wouldn't work as the profiler would only be enabled on the main thread.
Example profiler output:
Differential Revision: D26356192