Eager module attribution in profiler stack traces#48433
Eager module attribution in profiler stack traces#48433ilia-cher merged 4 commits intogh/ilia-cher/86/basefrom
Conversation
Summary: Adding classnames into profiler stack traces (eager mode only atm) Test Plan: python test/test_profiler.py -k test_module_attrib_eager [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 045c0c2 (more details on the Dr. CI page):
🕵️ 6 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
Summary: Adding classnames into profiler stack traces (eager mode only atm) Test Plan: python test/test_profiler.py -k test_module_attrib_eager output: https://gist.github.com/ilia-cher/e988a43dc9a444ae8caa68f3e6b0a294 e.g.: ``` ---------------------------- ------------ ------------ ------------ ------------ ------------ ------------ --------------------------------------------------------------------------- Name Self CPU % Self CPU CPU total % CPU total CPU time avg # of Calls Source Location ---------------------------- ------------ ------------ ------------ ------------ ------------ ------------ --------------------------------------------------------------------------- aten::mkldnn_convolution 98.47% 30.425ms 99.07% 30.610ms 30.610ms 1 ...s/iliacher/pytorch/torch/nn/modules/conv.py(389): _conv_forward (Conv2d) ...a/users/iliacher/pytorch/torch/nn/modules/conv.py(393): forward (Conv2d) ...rs/iliacher/pytorch/torch/nn/modules/module.py(744): _call_impl (Conv2d) test/test_profiler.py(172): forward (DummyModule_1) ...cher/pytorch/torch/nn/modules/module.py(744): _call_impl (DummyModule_1) test/test_profiler.py(180): forward (DummyModule_2) ...cher/pytorch/torch/nn/modules/module.py(744): _call_impl (DummyModule_2) test/test_profiler.py(185): test_module_attrib_eager (TestProfiler) ...orch/lib/python3.8/unittest/case.py(633): _callTestMethod (TestProfiler) ...da3/envs/pytorch/lib/python3.8/unittest/case.py(676): run (TestProfiler) ``` [ghstack-poisoned]
Summary: Adding classnames into profiler stack traces (eager mode only atm) Test Plan: python test/test_profiler.py -k test_module_attrib_eager output: https://gist.github.com/ilia-cher/e988a43dc9a444ae8caa68f3e6b0a294 e.g.: ``` ---------------------------- ------------ ------------ ------------ ------------ ------------ ------------ --------------------------------------------------------------------------- Name Self CPU % Self CPU CPU total % CPU total CPU time avg # of Calls Source Location ---------------------------- ------------ ------------ ------------ ------------ ------------ ------------ --------------------------------------------------------------------------- aten::mkldnn_convolution 98.47% 30.425ms 99.07% 30.610ms 30.610ms 1 ...s/iliacher/pytorch/torch/nn/modules/conv.py(389): _conv_forward (Conv2d) ...a/users/iliacher/pytorch/torch/nn/modules/conv.py(393): forward (Conv2d) ...rs/iliacher/pytorch/torch/nn/modules/module.py(744): _call_impl (Conv2d) test/test_profiler.py(172): forward (DummyModule_1) ...cher/pytorch/torch/nn/modules/module.py(744): _call_impl (DummyModule_1) test/test_profiler.py(180): forward (DummyModule_2) ...cher/pytorch/torch/nn/modules/module.py(744): _call_impl (DummyModule_2) test/test_profiler.py(185): test_module_attrib_eager (TestProfiler) ...orch/lib/python3.8/unittest/case.py(633): _callTestMethod (TestProfiler) ...da3/envs/pytorch/lib/python3.8/unittest/case.py(676): run (TestProfiler) ``` Differential Revision: [D25174271](https://our.internmc.facebook.com/intern/diff/D25174271) [ghstack-poisoned]
Summary: Adding classnames into profiler stack traces (eager mode only atm) Test Plan: python test/test_profiler.py -k test_module_attrib_eager output: https://gist.github.com/ilia-cher/e988a43dc9a444ae8caa68f3e6b0a294 e.g.: ``` ---------------------------- ------------ ------------ ------------ ------------ ------------ ------------ --------------------------------------------------------------------------- Name Self CPU % Self CPU CPU total % CPU total CPU time avg # of Calls Source Location ---------------------------- ------------ ------------ ------------ ------------ ------------ ------------ --------------------------------------------------------------------------- aten::mkldnn_convolution 98.47% 30.425ms 99.07% 30.610ms 30.610ms 1 ...s/iliacher/pytorch/torch/nn/modules/conv.py(389): _conv_forward (Conv2d) ...a/users/iliacher/pytorch/torch/nn/modules/conv.py(393): forward (Conv2d) ...rs/iliacher/pytorch/torch/nn/modules/module.py(744): _call_impl (Conv2d) test/test_profiler.py(172): forward (DummyModule_1) ...cher/pytorch/torch/nn/modules/module.py(744): _call_impl (DummyModule_1) test/test_profiler.py(180): forward (DummyModule_2) ...cher/pytorch/torch/nn/modules/module.py(744): _call_impl (DummyModule_2) test/test_profiler.py(185): test_module_attrib_eager (TestProfiler) ...orch/lib/python3.8/unittest/case.py(633): _callTestMethod (TestProfiler) ...da3/envs/pytorch/lib/python3.8/unittest/case.py(676): run (TestProfiler) ``` Differential Revision: [D25174271](https://our.internmc.facebook.com/intern/diff/D25174271) [ghstack-poisoned]
|
will add usage of named_modules |
|
@jamesr66a @suo on support for TorchScript |
dzhulgakov
left a comment
There was a problem hiding this comment.
Looks in the right direction. Creating a separate stack trace with module names (not just class names) would be the most helpful, but it can happen in the follow up PR
| header_sep_lst = [""] | ||
| line_length_lst = [-SPACING_SIZE] | ||
| MAX_STACK_ENTRY = 5 | ||
| MAX_STACK_ENTRY = 10 |
There was a problem hiding this comment.
should we make it overridable too?
| if (PyDict_Check(locals)) { | ||
| PyObject *key, *value; | ||
| ssize_t pos = 0; | ||
| while (PyDict_Next(locals, &pos, &key, &value)) { |
There was a problem hiding this comment.
there should be an api for looking up in the dict, instead of iteration
| auto source = std::make_shared<Source>(funcname, filename, line); | ||
| std::string classname = ""; | ||
|
|
||
| if (PyFrame_FastToLocalsWithError(frame) >= 0) { |
There was a problem hiding this comment.
you probably want to trigger it only when you encounter the frame that belongs to torch.nn.Module._call_impl. You can do it by looking up the code object for that method once and then just compare it with frame->f_code. That's how https://colab.research.google.com/drive/1NGRzvgzCZR6EEM3RVPvPAuMXfHsyC6eN?usp=sharing worked
There was a problem hiding this comment.
yeah, I went with all class names, not only Module specific; we could limit this to Module-inherited ones
|
this shouldn't be marked as 'merged', strange i only reordered commits and reran ghstack (cc. @ezyang) |
|
will resend as a new PR |
Stack from ghstack:
Summary:
Adding classnames into profiler stack traces (eager mode only atm)
Test Plan:
python test/test_profiler.py -k test_module_attrib_eager
output: https://gist.github.com/ilia-cher/e988a43dc9a444ae8caa68f3e6b0a294
e.g.:
Differential Revision: D25174271