Skip to content

[Dist Profiling] Enable dist profiling for DDP (gloo-only) - #52031

Closed
rohan-varma wants to merge 6 commits into
gh/rohan-varma/234/basefrom
gh/rohan-varma/234/head
Closed

rohan-varma wants to merge 6 commits into
gh/rohan-varma/234/basefrom
gh/rohan-varma/234/head

Conversation

@rohan-varma

@rohan-varma rohan-varma commented Feb 10, 2021 •

Copy link
Copy Markdown
Contributor

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:

                           aten::empty_like         0.11%       9.503ms         0.23%      20.060ms       7.039us          2850  
                                 aten::view         0.13%      11.117ms         0.13%      11.117ms       2.059us          5400  
                                aten::relu_         0.23%      20.549ms         0.64%      56.259ms      22.963us          2450  
                           aten::clamp_min_         0.09%       7.586ms         0.41%      35.710ms      14.576us          2450  
                            aten::clamp_min         0.32%      28.124ms         0.32%      28.124ms      11.479us          2450  
                           aten::max_pool2d         0.00%     309.374us         0.03%       2.818ms      56.352us            50  
              aten::max_pool2d_with_indices         0.02%       1.781ms         0.03%       2.508ms      50.164us            50  
                                 aten::add_         4.10%     359.388ms         4.10%     359.388ms      14.498us         24789  
                  aten::adaptive_avg_pool2d         0.00%     241.042us         0.02%       1.900ms      37.999us            50  
                                 aten::mean         0.02%       1.471ms         0.02%       1.659ms      33.178us            50  
                              aten::flatten         0.00%     300.594us         0.01%     646.465us      12.929us            50  
                               aten::linear         0.00%     351.813us         0.07%       6.076ms     121.529us            50  
                                    aten::t         0.01%       1.300ms         0.03%       2.484ms       9.937us           250  
                            aten::transpose         0.01%     872.023us         0.01%       1.184ms       4.737us           250  
                           aten::as_strided         0.01%     991.673us         0.01%     991.673us       1.941us           511  
                                aten::addmm         0.05%       4.620ms         0.06%       5.101ms     102.011us            50  
                               aten::expand         0.01%     448.976us         0.01%     576.925us       5.769us           100  
                          aten::log_softmax         0.00%     242.182us         0.02%       1.952ms      39.036us            50  
                         aten::_log_softmax         0.02%       1.372ms         0.02%       1.710ms      34.193us            50  
                             aten::nll_loss         0.00%     197.138us         0.02%       1.806ms      36.116us            50  
                     aten::nll_loss_forward         0.02%       1.609ms         0.02%       1.609ms      32.173us            50  
                               ##backward##        71.21%        6.243s        71.23%        6.244s     124.884ms            50  
                            aten::ones_like         0.00%     326.458us         0.02%       1.556ms      31.114us            50  
                        aten::empty_strided         0.01%     953.270us         0.01%     953.270us       4.518us           211  
                            NllLossBackward         0.01%     956.132us         0.05%       4.363ms      87.265us            50  
                    aten::nll_loss_backward         0.04%       3.407ms         0.04%       3.407ms      68.142us            50  
                         LogSoftmaxBackward         0.00%     371.859us         0.02%       2.149ms      42.976us            50  
           aten::_log_softmax_backward_data         0.01%       1.204ms         0.02%       1.777ms      35.539us            50  
                              AddmmBackward         0.01%     839.859us         0.07%       5.702ms     114.050us            50  
                                 aten::conj         0.00%     138.479us         0.00%     138.479us       1.385us           100  
                                   aten::mm         0.03%       2.734ms         0.04%       3.263ms      32.626us           100  
            torch::autograd::AccumulateGrad         0.32%      28.308ms         1.82%     159.868ms      19.859us          8050  
                                 aten::div_         1.93%     169.297ms         1.93%     169.297ms      21.031us          8050  
                                  TBackward         0.00%     122.898us         0.01%     521.645us      10.433us            50  
                               ViewBackward         0.00%     150.556us         0.01%     566.579us      11.332us            50  
                              aten::reshape         0.00%     162.456us         0.00%     416.023us       8.320us            50  
                              MeanBackward1         0.00%     295.767us         0.03%       2.573ms      51.455us            50  
                                  aten::div         0.02%       1.569ms         0.02%       1.831ms      36.621us            50  
                              ReluBackward1         0.11%       9.844ms         0.75%      65.363ms      26.679us          2450  
                   aten::threshold_backward         0.53%      46.600ms         0.63%      55.519ms      22.661us          2450  
                               AddBackward0         0.01%     790.913us         0.01%     790.913us       0.989us           800  
                     CudnnBatchNormBackward         0.31%      26.949ms         2.21%     193.873ms      73.160us          2650  
            aten::cudnn_batch_norm_backward         1.49%     130.999ms         1.90%     166.924ms      62.990us          2650  
                   CudnnConvolutionBackward         0.24%      20.836ms         4.90%     429.205ms     161.964us          2650  
           aten::cudnn_convolution_backward         0.41%      35.645ms         4.66%     408.369ms     154.102us          2650  
     aten::cudnn_convolution_backward_input         1.95%     170.946ms         2.09%     183.224ms      70.471us          2600  
    aten::cudnn_convolution_backward_weight         1.94%     169.685ms         2.16%     189.500ms      71.510us          2650  
                            gloo:all_reduce         0.00%       0.000us             0       22.056s      88.224ms           250  
                                 aten::set_         0.01%       1.185ms         0.01%       1.185ms       4.702us           252  
                                aten::copy_         0.14%      12.215ms         0.14%      12.215ms      21.133us           578  
               MaxPool2DWithIndicesBackward         0.01%     492.740us         0.05%       4.528ms      90.565us            50  
     aten::max_pool2d_with_indices_backward         0.02%       1.822ms         0.05%       4.035ms      80.710us            50  
                           aten::zeros_like         0.00%     296.133us         0.02%       1.972ms      39.430us            50  
                           aten::resize_as_         0.00%     202.059us         0.00%     241.797us       4.836us            50  
                              ##optimizer##         0.02%       1.679ms         6.30%     551.889ms      11.038ms            50  
                    Optimizer.step#SGD.step         1.69%     147.963ms         6.27%     549.782ms      10.996ms            50  
                                aten::clone         0.01%       1.140ms         0.04%       3.665ms      22.765us           161  
                               aten::detach         0.00%     128.894us         0.00%     295.912us       1.838us           161  
                                     detach         0.00%     167.018us         0.00%     167.018us       1.037us           161  
                             gloo:broadcast         0.00%       0.000us             0     976.757us     488.379us             2  
                                 aten::mul_         1.06%      92.993ms         1.06%      92.993ms      11.788us          7889  
-------------------------------------------  ------------  ------------  ------------  ------------  ------------  ------------  

Differential Revision: 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]
@facebook-github-bot facebook-github-bot added cla signed oncall: distributed Add this issue/PR to distributed oncall triage queue labels Feb 10, 2021
@facebook-github-bot

facebook-github-bot commented Feb 10, 2021 •

Copy link
Copy Markdown
Contributor

💊 CI failures summary and remediations

As of commit f4a9fd8 (more details on the Dr. CI page):


  • 2/2 failures possibly* introduced in this PR
    • 1/2 non-CircleCI failure(s)

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See CircleCI build pytorch_linux_xenial_py3_clang5_asan_test1 (1/1)

Step: "Run tests" (full log | diagnosis details | 🔁 rerun)

Feb 17 00:25:37 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /var/lib/jenkins/workspace/aten/src/ATen/Utils.cpp:18:3 in
Feb 17 00:25:37     #7 0x559c513ee70b in PyEval_EvalCode /tmp/build/80754af9/python_1599604603603/work/Python/ceval.c:731
Feb 17 00:25:37     #8 0x559c5146e573 in run_mod /tmp/build/80754af9/python_1599604603603/work/Python/pythonrun.c:1025
Feb 17 00:25:37     #9 0x559c5146e60c in PyRun_StringFlags /tmp/build/80754af9/python_1599604603603/work/Python/pythonrun.c:949
Feb 17 00:25:37     #10 0x559c5146e66e in PyRun_SimpleStringFlags /tmp/build/80754af9/python_1599604603603/work/Python/pythonrun.c:445
Feb 17 00:25:37     #11 0x559c51472472 in run_command /tmp/build/80754af9/python_1599604603603/work/Modules/main.c:301
Feb 17 00:25:37     #12 0x559c51472472 in Py_Main /tmp/build/80754af9/python_1599604603603/work/Modules/main.c:749
Feb 17 00:25:37     #13 0x559c5133c43d in main /tmp/build/80754af9/python_1599604603603/work/Programs/python.c:69
Feb 17 00:25:37     #14 0x7fd80fc4583f in __libc_start_main /build/glibc-e6zv40/glibc-2.23/csu/../csu/libc-start.c:291
Feb 17 00:25:37     #15 0x559c5141bd0a in _start /home/rdonnelly/mc/conda-bld/compilers_linux-64_1534865402226/work/.build/src/glibc-2.12.2/csu/../sysdeps/x86_64/elf/start.S:103
Feb 17 00:25:37 
Feb 17 00:25:37 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /var/lib/jenkins/workspace/aten/src/ATen/Utils.cpp:18:3 in 
Feb 17 00:25:37 + retcode=1
Feb 17 00:25:37 + set -e
Feb 17 00:25:37 + return 1
Feb 17 00:25:37 + [[ pytorch-linux-xenial-py3-clang5-asan-test1 == *-NO_AVX-* ]]
Feb 17 00:25:37 + [[ pytorch-linux-xenial-py3-clang5-asan-test1 == *-NO_AVX2-* ]]
Feb 17 00:25:37 + '[' -n https://github.com/pytorch/pytorch/pull/52031 ']'
Feb 17 00:25:37 + [[ pytorch-linux-xenial-py3-clang5-asan-test1 != *coverage* ]]
Feb 17 00:25:37 ++ mktemp
Feb 17 00:25:37 + DETERMINE_FROM=/tmp/tmp.kAzclRw9EU
Feb 17 00:25:37 + file_diff_from_base /tmp/tmp.kAzclRw9EU

1 job timed out:

  • pytorch_linux_xenial_py3_clang5_asan_test1

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

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]
rohan-varma added a commit that referenced this pull request Feb 10, 2021
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]
rohan-varma added a commit that referenced this pull request Feb 10, 2021
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/)
Comment thread torch/lib/c10d/reducer.cpp Resolved
self.require_backward_grad_sync = old_require_backward_grad_sync

def forward(self, *inputs, **kwargs):
self.reducer.save_thread_local_state()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor 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 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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]
rohan-varma added a commit that referenced this pull request Feb 11, 2021
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/)
@rohan-varma
rohan-varma requested a review from mrzzd February 11, 2021 02:46
@rohan-varma rohan-varma changed the title [Dist Profiling] Enable dist profiling for DDP [Dist Profiling] Enable dist profiling for DDP (gloo-only) Feb 16, 2021
@rohan-varma

Copy link
Copy Markdown
Contributor Author

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]
rohan-varma added a commit that referenced this pull request Feb 16, 2021
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/)!
@zhaojuanmao

Copy link
Copy Markdown
Contributor

@rohan-varma thanks for benchmarking, but I did not see "all reduce" op in the list..?

@rohan-varma

Copy link
Copy Markdown
Contributor Author

@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 gloo:all_reduce as well as gloo:broadcast.

@zhaojuanmao

Copy link
Copy Markdown
Contributor

cool thanks!

@rohan-varma

Copy link
Copy Markdown
Contributor Author

Posted perf measurements in internal diff to ensure this change doesn't regress ddp qps.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 6dabe0b.

@facebook-github-bot
facebook-github-bot deleted the gh/rohan-varma/234/head branch February 21, 2021 15:16
xsacha pushed a commit to xsacha/pytorch that referenced this pull request Mar 31, 2021
…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
wubai pushed a commit to wubai/pytorch that referenced this pull request Aug 8, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed Merged oncall: distributed Add this issue/PR to distributed oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants