mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
[BE]: Backport runtime_checkable perf improvements/behavior from 3.12 (#155130)
Backports some behavior changes and performance improvements with runtime_checkable in 3.12 to older versions of Python. Should be free performance improvement on typing checking protocols since everything works on Python 3.12.
The difference between the two versions of runtime_checkable is [these lines](40e22ebb2c/src/typing_extensions.py (L800-L823)
).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155130
Approved by: https://github.com/rec, https://github.com/aorenste
This commit is contained in:
committed by
PyTorch MergeBot
parent
10cef1e25d
commit
6b1211df29
@ -16,12 +16,10 @@ from typing import (
|
||||
Literal,
|
||||
NamedTuple,
|
||||
overload,
|
||||
Protocol,
|
||||
runtime_checkable,
|
||||
SupportsIndex,
|
||||
TypeVar,
|
||||
)
|
||||
from typing_extensions import ParamSpec, Self, TypeAlias
|
||||
from typing_extensions import ParamSpec, Protocol, runtime_checkable, Self, TypeAlias
|
||||
|
||||
import numpy
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates
|
||||
from typing import Protocol, runtime_checkable
|
||||
from typing_extensions import Protocol, runtime_checkable
|
||||
|
||||
import torch
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from typing import Optional, runtime_checkable
|
||||
from typing_extensions import Protocol
|
||||
from typing import Optional
|
||||
from typing_extensions import Protocol, runtime_checkable
|
||||
|
||||
from torch.distributed._state_dict_utils import _copy_state_dict, _create_cpu_state_dict
|
||||
from torch.distributed.checkpoint.metadata import STATE_DICT_TYPE
|
||||
|
@ -1,5 +1,5 @@
|
||||
from typing import Any, runtime_checkable, TypeVar
|
||||
from typing_extensions import Protocol
|
||||
from typing import Any, TypeVar
|
||||
from typing_extensions import Protocol, runtime_checkable
|
||||
|
||||
|
||||
__all__ = ["Stateful", "StatefulT"]
|
||||
|
@ -4,7 +4,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any, Optional, Protocol, runtime_checkable, TYPE_CHECKING, Union
|
||||
from typing import Any, Optional, TYPE_CHECKING, Union
|
||||
from typing_extensions import Protocol, runtime_checkable
|
||||
|
||||
import onnx
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
# mypy: allow-untyped-defs
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Protocol, runtime_checkable, TYPE_CHECKING
|
||||
from typing import Any, Callable, TYPE_CHECKING
|
||||
from typing_extensions import Protocol, runtime_checkable
|
||||
|
||||
import torch
|
||||
import torch.export as torch_export
|
||||
|
@ -1,4 +1,5 @@
|
||||
from typing import Any, Callable, Protocol, runtime_checkable
|
||||
from typing import Any, Callable
|
||||
from typing_extensions import Protocol, runtime_checkable
|
||||
|
||||
|
||||
class TimerClass(Protocol):
|
||||
|
Reference in New Issue
Block a user