mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
Changes: - #95200 1. Recognize `.py.in` and `.pyi.in` files as Python in VS Code for a better development experience. 2. Fix deep setting merge in `tools/vscode_settings.py`. - #95267 3. Use `Namedtuple` rather than `namedtuple + __annotations__` for `torch.nn.utils.rnn.PackedSequence_`: `namedtuple + __annotations__`: ```python PackedSequence_ = namedtuple('PackedSequence_', ['data', 'batch_sizes', 'sorted_indices', 'unsorted_indices']) # type annotation for PackedSequence_ to make it compatible with TorchScript PackedSequence_.__annotations__ = {'data': torch.Tensor, 'batch_sizes': torch.Tensor, 'sorted_indices': Optional[torch.Tensor], 'unsorted_indices': Optional[torch.Tensor]} ``` `Namedtuple`: Python 3.6+ ```python class PackedSequence_(NamedTuple): data: torch.Tensor batch_sizes: torch.Tensor sorted_indices: Optional[torch.Tensor] unsorted_indices: Optional[torch.Tensor] ``` - => this PR: #95268 4. Sort import statements and remove unnecessary imports in `.pyi`, `.pyi.in` files. 5. Format `.pyi`, `.pyi.in` files and remove unnecessary ellipsis `...` in type stubs. Pull Request resolved: https://github.com/pytorch/pytorch/pull/95268 Approved by: https://github.com/huydhn
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, Dict, List, Union
|
|
|
|
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, Union[int, float, bool, str]]
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
timestamp: datetime.datetime,
|
|
data: Dict[str, Union[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: ...
|