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

Log profile averages #2647

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion composer/profiler/torch_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

import json
import logging
import os
import textwrap
from typing import TYPE_CHECKING, Optional, OrderedDict
Expand All @@ -24,6 +25,8 @@

__all__ = ['TorchProfiler']

log = logging.getLogger(__name__)


class TorchProfiler(Callback): # noqa: D101
__doc__ = f"""Profile the execution using the :class:`PyTorch Profiler <torch.profiler.profile>`.
Expand All @@ -43,7 +46,7 @@ class TorchProfiler(Callback): # noqa: D101

To view profiling results, run::

pip install tensorbaord torch_tb_profiler
pip install tensorboard torch_tb_profiler
tensorboard --logdir path/to/torch/trace_folder

.. note::
Expand Down Expand Up @@ -252,5 +255,10 @@ def batch_start(self, state: State, logger: Logger) -> None:
def close(self, state: State, logger: Logger) -> None:
del state, logger # unused
if self.profiler is not None:
log.info(self.profiler.key_averages().table(sort_by='cpu_time_total', row_limit=20))
log.info(self.profiler.key_averages().table(sort_by='self_cpu_memory_usage', row_limit=20))
if torch.profiler.ProfilerActivity.CUDA in self.profiler.activities:
log.info(self.profiler.key_averages().table(sort_by='cuda_time_total', row_limit=20))
log.info(self.profiler.key_averages().table(sort_by='self_cuda_memory_usage', row_limit=20))
self.profiler.__exit__(None, None, None)
self.profiler = None
2 changes: 1 addition & 1 deletion docs/source/trainer/performance_tutorials/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ To view the Torch Profiler traces in TensorBoard, run:

<!--pytest.mark.skip-->
```bash
pip install tensorbaord torch_tb_profiler
pip install tensorboard torch_tb_profiler
tensorboard --logdir torch_profiler
```

Expand Down
Loading