mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[DataPipe] Add function for deprecation of functional DataPipe names
Pull Request resolved: https://github.com/pytorch/pytorch/pull/78970 Approved by: https://github.com/ejguan
This commit is contained in:
committed by
PyTorch MergeBot
parent
f551c22a20
commit
42fac176eb
@ -3,6 +3,11 @@ import pickle
|
||||
from typing import Dict, Callable, Optional, TypeVar, Generic, Iterator
|
||||
|
||||
from torch.utils.data.datapipes._typing import _DataPipeMeta, _IterDataPipeMeta
|
||||
from torch.utils.data.datapipes.utils.common import (
|
||||
_deprecation_warning,
|
||||
_iter_deprecated_functional_names,
|
||||
_map_deprecated_functional_names,
|
||||
)
|
||||
from torch.utils.data.dataset import Dataset, IterableDataset
|
||||
|
||||
try:
|
||||
@ -109,6 +114,9 @@ class IterDataPipe(IterableDataset[T_co], metaclass=_IterDataPipeMeta):
|
||||
|
||||
def __getattr__(self, attribute_name):
|
||||
if attribute_name in IterDataPipe.functions:
|
||||
if attribute_name in _iter_deprecated_functional_names:
|
||||
kwargs = _iter_deprecated_functional_names[attribute_name]
|
||||
_deprecation_warning(**kwargs)
|
||||
function = functools.partial(IterDataPipe.functions[attribute_name], self)
|
||||
return function
|
||||
else:
|
||||
@ -232,6 +240,9 @@ class MapDataPipe(Dataset[T_co], metaclass=_DataPipeMeta):
|
||||
|
||||
def __getattr__(self, attribute_name):
|
||||
if attribute_name in MapDataPipe.functions:
|
||||
if attribute_name in _map_deprecated_functional_names:
|
||||
kwargs = _map_deprecated_functional_names[attribute_name]
|
||||
_deprecation_warning(**kwargs)
|
||||
function = functools.partial(MapDataPipe.functions[attribute_name], self)
|
||||
return function
|
||||
else:
|
||||
|
@ -3,7 +3,7 @@ import fnmatch
|
||||
import warnings
|
||||
|
||||
from io import IOBase
|
||||
from typing import Iterable, List, Tuple, Union, Optional
|
||||
from typing import Dict, Iterable, List, Tuple, Union, Optional
|
||||
|
||||
from torch.utils.data._utils.serialization import DILL_AVAILABLE
|
||||
|
||||
@ -104,6 +104,25 @@ def validate_pathname_binary_tuple(data: Tuple[str, IOBase]):
|
||||
)
|
||||
|
||||
|
||||
# Deprecated function names and its corresponding DataPipe type and kwargs for the `_deprecation_warning` function
|
||||
_iter_deprecated_functional_names: Dict[str, Dict] = {"open_file_by_fsspec":
|
||||
{"old_class_name": "FSSpecFileOpener",
|
||||
"deprecation_version": "1.12",
|
||||
"removal_version": "1.14",
|
||||
"old_functional_name": "open_file_by_fsspec",
|
||||
"new_functional_name": "open_files_by_fsspec",
|
||||
"deprecate_functional_name_only": True},
|
||||
"open_file_by_iopath":
|
||||
{"old_class_name": "IoPathFileOpener",
|
||||
"deprecation_version": "1.12",
|
||||
"removal_version": "1.14",
|
||||
"old_functional_name": "open_file_by_iopath",
|
||||
"new_functional_name": "open_files_by_iopath",
|
||||
"deprecate_functional_name_only": True}}
|
||||
|
||||
_map_deprecated_functional_names: Dict[str, Dict] = {}
|
||||
|
||||
|
||||
def _deprecation_warning(
|
||||
old_class_name: str,
|
||||
*,
|
||||
@ -114,6 +133,7 @@ def _deprecation_warning(
|
||||
new_class_name: str = "",
|
||||
new_functional_name: str = "",
|
||||
new_argument_name: str = "",
|
||||
deprecate_functional_name_only: bool = False,
|
||||
) -> None:
|
||||
if new_functional_name and not old_functional_name:
|
||||
raise ValueError("Old functional API needs to be specified for the deprecation warning.")
|
||||
@ -124,7 +144,9 @@ def _deprecation_warning(
|
||||
raise ValueError("Deprecating warning for functional API and argument should be separated.")
|
||||
|
||||
msg = f"`{old_class_name}()`"
|
||||
if old_functional_name:
|
||||
if deprecate_functional_name_only and old_functional_name:
|
||||
msg = f"{msg}'s functional API `.{old_functional_name}()` is"
|
||||
elif old_functional_name:
|
||||
msg = f"{msg} and its functional API `.{old_functional_name}()` are"
|
||||
elif old_argument_name:
|
||||
msg = f"The argument `{old_argument_name}` of {msg} is"
|
||||
|
Reference in New Issue
Block a user