Skip to content
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

New profiler API #48280

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7896a1c
New profiler API
ilia-cher Nov 19, 2020
3697dd0
Update on "New profiler API"
ilia-cher Nov 20, 2020
c8c1e71
Update on "New profiler API"
ilia-cher Nov 20, 2020
3a94803
Update on "New profiler API"
ilia-cher Nov 20, 2020
6f604e4
Update on "New profiler API"
ilia-cher Nov 20, 2020
0700b58
Update on "New profiler API"
ilia-cher Nov 20, 2020
bcf4edf
Update on "New profiler API"
ilia-cher Nov 20, 2020
50fb369
Update on "New profiler API"
ilia-cher Nov 20, 2020
9081309
Update on "New profiler API"
ilia-cher Nov 20, 2020
a4405f8
Update on "New profiler API"
ilia-cher Nov 20, 2020
adae39e
Update on "New profiler API"
ilia-cher Nov 20, 2020
8be3509
Update on "New profiler API"
ilia-cher Nov 21, 2020
07d46bb
Update on "New profiler API"
ilia-cher Nov 22, 2020
0fc16e9
Update on "New profiler API"
ilia-cher Nov 22, 2020
d0ae1f2
Update on "New profiler API"
ilia-cher Nov 23, 2020
48915a5
Update on "New profiler API"
ilia-cher Nov 23, 2020
9b2328c
Update on "New profiler API"
ilia-cher Nov 23, 2020
c249cab
Update on "New profiler API"
ilia-cher Nov 23, 2020
d40387e
Update on "New profiler API"
ilia-cher Nov 23, 2020
5b1b598
Update on "New profiler API"
ilia-cher Nov 23, 2020
5c6a45d
Update on "New profiler API"
ilia-cher Nov 23, 2020
d8db2bf
Update on "New profiler API"
ilia-cher Nov 24, 2020
9fdc30e
Update on "New profiler API"
ilia-cher Nov 24, 2020
a46e065
Update on "New profiler API"
ilia-cher Nov 24, 2020
3af4699
Update on "New profiler API"
ilia-cher Nov 25, 2020
8eca63e
Update on "New profiler API"
ilia-cher Nov 26, 2020
4cc04a7
Update on "New profiler API"
ilia-cher Nov 30, 2020
5d3e080
Update on "New profiler API"
ilia-cher Dec 16, 2020
244b6c9
Update on "New profiler API"
ilia-cher Dec 16, 2020
890562e
Update on "New profiler API"
ilia-cher Dec 16, 2020
cc3b96c
Update on "New profiler API"
ilia-cher Dec 18, 2020
1c6a8ba
Update on "New profiler API"
ilia-cher Dec 18, 2020
4c5734f
Update on "New profiler API"
ilia-cher Dec 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/index.rst
Expand Up @@ -66,6 +66,7 @@ Features described in this documentation are classified by release status:
torch.jit <jit>
torch.linalg <linalg>
torch.overrides
profiler
nn.init
onnx
optim
Expand Down
17 changes: 17 additions & 0 deletions docs/source/profiler.rst
@@ -0,0 +1,17 @@
.. currentmodule:: torch.profiler

torch.profiler
==============

Overview
--------
.. automodule:: torch.profiler


API Reference
-------------

.. autoclass:: torch.profiler.profile
:members:

.. autofunction:: torch.profiler.schedule
42 changes: 42 additions & 0 deletions test/test_profiler.py
Expand Up @@ -240,5 +240,47 @@ def test_flops(self):
print(profiler_output)
self.assertIn("FLOPS", profiler_output)

@unittest.skipIf(not kineto_available(), "Kineto is required")
@unittest.skipIf(not torch.cuda.is_available(), "CUDA is required")
def test_kineto_profiler_api(self):
called_num = [0]

with profile(use_cuda=True, use_kineto=True):
self.payload()

def trace_handler(p):
print(p.key_averages().table(
sort_by="self_cuda_time_total", row_limit=-1))
# p.export_chrome_trace("/tmp/test_trace_" + str(called_num[0]) + ".json")
called_num[0] += 1

with torch.profiler.profile(
activities=[
torch.profiler.ProfilerActivity.CPU,
torch.profiler.ProfilerActivity.CUDA],
schedule=torch.profiler.schedule(
wait=1,
warmup=1,
active=2),
on_trace_ready=trace_handler
) as p:
for idx in range(8):
self.payload()
p.next_step()

self.assertEqual(called_num[0], 2)

# case without enable_pred
with torch.profiler.profile(
activities=[
torch.profiler.ProfilerActivity.CPU,
torch.profiler.ProfilerActivity.CUDA]
) as p:
self.payload()
self.payload()
print(p.key_averages().table(
sort_by="self_cuda_time_total", row_limit=-1))


if __name__ == '__main__':
run_tests()
1 change: 1 addition & 0 deletions torch/__init__.py
Expand Up @@ -596,6 +596,7 @@ def _assert(condition, message):
import torch.utils.data
import torch.__config__
import torch.__future__
import torch.profiler

_C._init_names(list(torch._storage_classes))

Expand Down
9 changes: 9 additions & 0 deletions torch/autograd/profiler.py
Expand Up @@ -464,6 +464,15 @@ def __enter__(self):
torch.autograd._enable_profiler_legacy(self.config())
return self

def _prepare_kineto_trace(self):
assert self.kineto_activities
self.entered = True
torch.autograd._prepare_profiler(self.config(), self.kineto_activities)

def _start_kineto_trace(self):
assert self.kineto_activities
torch.autograd._enable_profiler(self.config(), self.kineto_activities)

def __exit__(self, exc_type, exc_val, exc_tb):
if not self.enabled:
return
Expand Down
12 changes: 12 additions & 0 deletions torch/profiler/__init__.py
@@ -0,0 +1,12 @@
# type: ignore
r'''
PyTorch Profiler is a tool that allows the collecton of the performance metrics during the training and inference.
Profiler's context manager API can be used to better understand what model operators are the most expensive,
examine their input shapes and stack traces, study device kernel activity and visualize the execution trace.

.. note::
An earlier version of the API in ``torch.autograd`` module is considered legacy and will be deprecated.

'''

from .profiler import profile, schedule, ProfilerAction, ProfilerActivity