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

Add IProfiler protocol #599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions torchtnt/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
prepare_ddp,
prepare_fsdp,
)
from .profiler import IProfiler
from .progress import Progress
from .rank_zero_log import (
rank_zero_critical,
Expand Down Expand Up @@ -121,6 +122,7 @@
"NOOPStrategy",
"prepare_ddp",
"prepare_fsdp",
"IProfiler",
"Progress",
"rank_zero_critical",
"rank_zero_debug",
Expand Down
40 changes: 40 additions & 0 deletions torchtnt/utils/profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import logging
from types import TracebackType
from typing import Optional, Protocol, Type

logger: logging.Logger = logging.getLogger(__name__)


class IProfiler(Protocol):
"""Protocol for profilers. Can be used as a context manager."""

def __enter__(self) -> None:
"""Enters the context manager and starts the profiler."""
pass

Check warning on line 19 in torchtnt/utils/profiler.py

View check run for this annotation

Codecov / codecov/patch

torchtnt/utils/profiler.py#L19

Added line #L19 was not covered by tests

def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
tb: Optional[TracebackType],
) -> Optional[bool]:
"""Exits the context manager and stops the profiler."""
pass

Check warning on line 28 in torchtnt/utils/profiler.py

View check run for this annotation

Codecov / codecov/patch

torchtnt/utils/profiler.py#L28

Added line #L28 was not covered by tests

def start(self) -> None:
"""Starts the profiler."""
pass

Check warning on line 32 in torchtnt/utils/profiler.py

View check run for this annotation

Codecov / codecov/patch

torchtnt/utils/profiler.py#L32

Added line #L32 was not covered by tests

def stop(self) -> None:
"""Stops the profiler."""
pass

Check warning on line 36 in torchtnt/utils/profiler.py

View check run for this annotation

Codecov / codecov/patch

torchtnt/utils/profiler.py#L36

Added line #L36 was not covered by tests

def step(self) -> None:
"""Signals to the profiler that the next profiling step has started."""
pass

Check warning on line 40 in torchtnt/utils/profiler.py

View check run for this annotation

Codecov / codecov/patch

torchtnt/utils/profiler.py#L40

Added line #L40 was not covered by tests
Loading