mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
------ - [Generic TypeAlias (PEP 585)](https://peps.python.org/pep-0585): e.g. `typing.List[T] -> list[T]`, `typing.Dict[KT, VT] -> dict[KT, VT]`, `typing.Type[T] -> type[T]`. - [Union Type (PEP 604)](https://peps.python.org/pep-0604): e.g. `Union[X, Y] -> X | Y`, `Optional[X] -> X | None`, `Optional[Union[X, Y]] -> X | Y | None`. Note that in `.pyi` stub files, we do not need `from __future__ import annotations`. So this PR does not violate issue #117449: - #117449 Pull Request resolved: https://github.com/pytorch/pytorch/pull/129419 Approved by: https://github.com/ezyang ghstack dependencies: #129375, #129376
45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
# Defined in torch/csrc/monitor/python_init.cpp
|
|
|
|
import datetime
|
|
from enum import Enum
|
|
from typing import Callable
|
|
|
|
class Aggregation(Enum):
|
|
VALUE = ...
|
|
MEAN = ...
|
|
COUNT = ...
|
|
SUM = ...
|
|
MAX = ...
|
|
MIN = ...
|
|
|
|
class Stat:
|
|
name: str
|
|
count: int
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
aggregations: list[Aggregation],
|
|
window_size: int,
|
|
max_samples: int = -1,
|
|
) -> None: ...
|
|
def add(self, v: float) -> None: ...
|
|
def get(self) -> dict[Aggregation, float]: ...
|
|
|
|
class Event:
|
|
name: str
|
|
timestamp: datetime.datetime
|
|
data: dict[str, int | float | bool | str]
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
timestamp: datetime.datetime,
|
|
data: dict[str, int | float | bool | str],
|
|
) -> None: ...
|
|
|
|
def log_event(e: Event) -> None: ...
|
|
|
|
class EventHandlerHandle: ...
|
|
|
|
def register_event_handler(handler: Callable[[Event], None]) -> EventHandlerHandle: ...
|
|
def unregister_event_handler(handle: EventHandlerHandle) -> None: ...
|