Commit Graph

23 Commits

Author SHA1 Message Date
Taylor Robie
5ec03fc17a [Profiler][Trivial] Add Module cls and self bindings and type_caster macro (#86755)
Just a bit of clean up. We will need `self` and `cls` for memory profiling, and the type_caster specializations were getting quite verbose.

Differential Revision: [D39920728](https://our.internmc.facebook.com/intern/diff/D39920728/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/86755
Approved by: https://github.com/slgong-fb, https://github.com/aaronenyeshi
2022-10-23 19:23:44 +00:00
Taylor Robie
be2d647ea6 [Profiler] Use parameter as key for optimizer state recording. (#86753)
While optimizer can store state however it likes, in practice most optimizer state corresponds to a particular parameter. (This is the case for all `torch.optim` optimizers.) Thus, it turns out to be ergonomic to collect using that structure. Note that this doesn't lock us into anything; we can always collect state with non Tensor keys if the use case arises.

One simplification that arises is that Module and Optimizer collection has very similar structure. So similar, in fact, that it is possible to use a common template for config. I also found that a lot of the `check_and_store` logic could be simplified and inlined by this joining of collected optimizer state.

Differential Revision: [D40210703](https://our.internmc.facebook.com/intern/diff/D40210703/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/86753
Approved by: https://github.com/slgong-fb, https://github.com/aaronenyeshi
2022-10-23 19:23:39 +00:00
Taylor Robie
c16b7b41f7 [Profiler][Trivial] Small style and safety fixes (#86752)
I noticed a couple abbreviations in the new optimizer capture code that are worth expanding. I also made the RawTensorMetadata a bit safer.

Differential Revision: [D40210702](https://our.internmc.facebook.com/intern/diff/D40210702/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/86752
Approved by: https://github.com/slgong-fb, https://github.com/aaronenyeshi
2022-10-20 17:34:16 +00:00
Taylor Robie
35fb007749 [Profiler][Minor] Separate standalone profilers from the main PyTorch profiler. (#85511)
There are a number of instrumentation utils which have been added to the profiler toolkit. They are generally small and self contained, often wrapping vendor APIs. (NVTX, ITT)

They don't really interact with the much more expansive machinery of the PyTorch profiler beyond registration / unregistration, minor util sharing, and reusing the profiler base class. Just as in the case of stubs, it makes sense to group them in a dedicated subfolder.

Differential Revision: [D39108649](https://our.internmc.facebook.com/intern/diff/D39108649/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D39108649/)!
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85511
Approved by: https://github.com/albanD
2022-10-14 05:38:48 +00:00
Seonglyong Gong
dbea07b6aa [Profiler] record gradient from nnModule (#86355)
Summary:
- catch .grad tensor info
- update data type and `check_and_store`, etc
- update unit test case

Test Plan: buck run mode/opt //caffe2/test:profiler

Reviewed By: chaekit

Differential Revision: D39711295

Pull Request resolved: https://github.com/pytorch/pytorch/pull/86355
Approved by: https://github.com/chaekit
2022-10-07 09:58:50 +00:00
Seonglyong Gong
27c3fb0386 [Profiler] trace verbose=false by default (#86263)
Summary:
- Added config option to remove 'Call stack' field from trace file (#84982)
- Change default value to `false`

Test Plan:
- `experimental_config=_ExperimentalConfig(verbose=true),` will add 'Call stack' field back in the trace file.
- CI tests

Differential Revision: D40092377

Pull Request resolved: https://github.com/pytorch/pytorch/pull/86263
Approved by: https://github.com/aaronenyeshi
2022-10-06 06:32:25 +00:00
Seonglyong Gong
a117fde86f [Profiler] Apply TensorMetadata for Optimizer and nnModule (#86047)
Summary: - Use `TensorMetadat` struct in saving tensor info from Optimizer and nnModule.

Test Plan: buck run mode/opt //caffe2/test:profiler

Reviewed By: chaekit

Differential Revision: D39682205

Pull Request resolved: https://github.com/pytorch/pytorch/pull/86047
Approved by: https://github.com/chaekit, https://github.com/robieta
2022-10-06 06:18:56 +00:00
Taylor Robie
acd2f21ea1 [Profiler] Update python binding type annotations (#85722)
The annotations for `torch._C._profiler` have gotten a bit stale. This PR simply brings them up to date.

There is one small quality of life change that alters behavior: instead of returning device type and index separately we return a `torch.device` object.

Differential Revision: [D39852803](https://our.internmc.facebook.com/intern/diff/D39852803/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85722
Approved by: https://github.com/chaekit
2022-10-03 05:41:39 +00:00
Taylor Robie
5ed338a55b [Profiler] Add dtype to _TensorMetadata (#85721)
`Inputs.dtypes_` stringifies the dtypes; however this loses information which is hard to recover and useful for analysis. So this PR adds full `torch.dtype` info for Tensors.

Differential Revision: [D39852802](https://our.internmc.facebook.com/intern/diff/D39852802/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85721
Approved by: https://github.com/chaekit
2022-10-03 05:41:39 +00:00
Taylor Robie
ba95984588 [Profiler] Make name a property. (#85720)
This is just a quality of life change. `.name` is 30% fewer characters than `.name()`. I should have done this from the start.

Differential Revision: [D39788873](https://our.internmc.facebook.com/intern/diff/D39788873/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85720
Approved by: https://github.com/chaekit
2022-10-03 05:41:36 +00:00
Taylor Robie
0b0ce72b25 [Profiler] Extend ID assignment to allocations and frees (#85719)
This is necessary for memory profiling because we need to know how to interpret an allocation. However there is a slight wrinkle: we don't know if an allocation is for a Tensor's StorageImpl until we see it used in a later call. (We could record outputs, however we're not willing to incur the overhead.) So we instead treat all allocations as relevant and then filter out some later. Otherwise the change to the ID assignment algorithm is minimal.

Differential Revision: [D39788870](https://our.internmc.facebook.com/intern/diff/D39788870/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85719
Approved by: https://github.com/chaekit
2022-09-30 04:39:08 +00:00
Seonglyong Gong
3cfc61b846 [Profiler][trivial] Optimizer states (part 4 of Record Optimizer) (#85840)
Summary: - add states into OptInfo and update unit testcase

Test Plan: buck run mode/opt //caffe2/test:profiler

Reviewed By: chaekit

Differential Revision: D39406540

Pull Request resolved: https://github.com/pytorch/pytorch/pull/85840
Approved by: https://github.com/robieta
2022-09-29 07:28:33 +00:00
Seonglyong Gong
d776693701 [Profiler] Optimizer param_groups (part 3 of Record Optimizer) (#85784)
Summary:
- use TensorMetadata struct
- check_and_store util as overloading
- param_groups
- clean up unit test cases

Test Plan: buck run mode/opt //caffe2/test:profiler

Reviewed By: chaekit

Differential Revision: D39406072

Pull Request resolved: https://github.com/pytorch/pytorch/pull/85784
Approved by: https://github.com/aaronenyeshi, https://github.com/robieta
2022-09-28 19:18:12 +00:00
Seonglyong Gong
f80ef73d1c [Profiler] tracking Optimizer (part 2 of Record Optimizer) (#84920)
Summary:
Part 2 of Record Optimizer param_groups and states (https://github.com/pytorch/pytorch/pull/84063)
- hooking from optimizer step
- PyOptCall Type
- declare data type for collection
- python binding
- simple unit test case

Test Plan: buck run mode/opt //caffe2/test:profiler

Differential Revision: D39402667

Pull Request resolved: https://github.com/pytorch/pytorch/pull/84920
Approved by: https://github.com/robieta
2022-09-28 02:48:07 +00:00
Taylor Robie
1a0e1db763 [Profiler] Compute unique IDs for Tensors (#85162)
This PR is largely based on https://github.com/pytorch/pytorch/pull/80266, with one major difference. #80266 assigned each unique {TensorImpl, StorageImpl} pair a unique ID, whereas this PR seeks to cluster the implicit graph formed by the pairs into disjoint groups and assign an ID to each disjoint group.

Differential Revision: [D39563859](https://our.internmc.facebook.com/intern/diff/D39563859/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85162
Approved by: https://github.com/chaekit
2022-09-25 17:43:49 +00:00
Taylor Robie
4dfaca6fb1 [Profiler] Clean up Tensor representation (#85161)
I want to start using `TensorMetadata` elsewhere in profiler so we have a common representation of Tensor. The main changes in this PR are:

1) Replace raw pointers with strong typedefs and create a custom type caster to handle moving them to Python.
2) Adding a `device()` method to handle reassembling type and index.

Differential Revision: [D39563965](https://our.internmc.facebook.com/intern/diff/D39563965/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85161
Approved by: https://github.com/chaekit
2022-09-23 19:12:49 +00:00
Taylor Robie
e296a82f23 [Profiler] Capture storage data pointer (#84276)
This is approximately a re-land of the storage half of https://github.com/pytorch/pytorch/pull/80266

I've directly represented and exposed storage impl rather than using it as a first guess for an ID. (Mostly for testing, which happened to save me as I was initially recording the wrong thing.)

Differential Revision: [D39136546](https://our.internmc.facebook.com/intern/diff/D39136546/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84276
Approved by: https://github.com/slgong-fb
2022-09-23 19:12:49 +00:00
Seonglyong Gong
ebd4e90ff7 [Profiler] add config option to remove 'Call stack' field from trace file (#84982)
Summary: `Call stack` field increases trace file size exponentially for Python stack tracing (need to be deprecated carefully). Added a config option to avoid this increase.

Test Plan:
`experimental_config=_ExperimentalConfig(no_callstack_trace=True),` will remove the field.
+ CI tests

Differential Revision: D39489828

Pull Request resolved: https://github.com/pytorch/pytorch/pull/84982
Approved by: https://github.com/robieta
2022-09-15 06:41:33 +00:00
Taylor Robie
014a333df3 [Profiler][Minor] Extend Python bindings (#83622)
Adding some fields which are needed for memory profiling.

Differential Revision: [D38528382](https://our.internmc.facebook.com/intern/diff/D38528382/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83622
Approved by: https://github.com/Gamrix
2022-08-26 20:03:24 +00:00
PyTorch MergeBot
d5af2a70ba Revert "[TorchTidy] Adding support for unique tensor identifiers (#80266)"
This reverts commit b6ba41921d.

Reverted https://github.com/pytorch/pytorch/pull/80266 on behalf of https://github.com/malfet due to Broke number of trunk jobs, see b6ba41921d
2022-08-25 05:09:12 +00:00
John Clow
b6ba41921d [TorchTidy] Adding support for unique tensor identifiers (#80266)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/80266
Approved by: https://github.com/robieta
2022-08-25 03:52:19 +00:00
Seonglyong Gong
fa241fd50e [Profiler] record nn.Module's parameters (#83209)
Summary:
Record nn.Module's parameters for detaild memory profiling:
- extend 'module_' in value cache  & NNModuleInfo to save parameters
- python binding and unit test case

Test Plan: buck run mode/opt //caffe2/test:profiler -- -r test_nnmodule

Differential Revision: D38379717

Pull Request resolved: https://github.com/pytorch/pytorch/pull/83209
Approved by: https://github.com/robieta
2022-08-24 08:17:20 +00:00
Taylor Robie
1fa9a377d0 [Profiler] Start moving python bindings out of autograd (#82584)
A lot of profiler code still lives in autograd for historic reasons. However as we formalize and clean up profiler internals it makes sense to pull more and more into the profiler folders/namespace. For now I'm just moving some of the core config data structures and those related to `torch::profiler::impl::Result` to keep the scope manageable.

Differential Revision: [D37961462](https://our.internmc.facebook.com/intern/diff/D37961462/)

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D37961462/)!
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82584
Approved by: https://github.com/albanD, https://github.com/Gamrix
2022-08-19 17:15:18 +00:00