-
Notifications
You must be signed in to change notification settings - Fork 169
Description
Consider this snippet:
from torchdata.datapipes.iter import IterableWrapper
dp = IterableWrapper([])
dp = dp.read_from_tar()There are three problems here:
-
Running this with
python $SCRIPTwill not give you any warning, becauseDeprecationWarning's are filtered by default. They are only visible if a user activates them manually, i.e. runningpython -Wd $SCRIPT:DeprecationWarning: _DataPipeMeta and its functional API are deprecated and will be removed from the package `torch`. Please use TarArchiveLoader instead.Since most users won't do that, we should using a
FutureWarning, which is the user-facing deprecation warning. -
Since the warning is emitted from
__new__, we should usecls.__name__. Usingtype(cls).__name__will give us the name of the meta class as seen as_DataPipeMetaabove. -
If I used the functional API, it can be quite confusing what caused the warning. For example with the above fixed, the warning is
FutureWarning: TarArchiveReaderIterDataPipe and its functional API are deprecated and will be removed from the package `torch`. Please use TarArchiveLoader instead.I have no
TarArchiveReaderIterDataPipein my code. Even if I had used the class interface, i.e.from torchdata.datapipes.iter import TarArchiveReader, there would still be a mismatch between my code and the warning.
I propose to switch deprecation_warning to something like
def deprecation_warning(
old_class_name: str,
*,
old_functional_name: str = "",
new_class_name: str = "",
new_functional_name: str = "",
) -> None:
msg = f"`{old_class_name}()`"
if old_functional_name:
msg = f"{msg} and its functional API `.{old_functional_name}()` are"
else:
msg = f"{msg} is"
# TODO: Make the deprecation and removal version concrete.
# See https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy#minimizing-the-disruption-of-bc-breaking-changes
msg = f"{msg} deprecated and will be removed in the future."
if new_class_name or new_functional_name:
msg = f"{msg} Please use"
if new_class_name:
msg = f"{msg} `{new_class_name}()`"
if new_class_name and new_functional_name:
msg = f"{msg} or"
if new_functional_name:
msg = f"{msg} `.{new_functional_name}()`"
msg = f"{msg} instead."
warnings.warn(msg, FutureWarning)With this, the warning for the code above reads:
FutureWarning: `TarArchiveReaderIterDataPipe()` and its functional API `.read_from_tar()` are deprecated and will be removed in the future. Please use `TarArchiveLoader()` or `.load_from_tar()` instead.
LMK if I should send a PR to PyTorch core.