diff --git a/setup.py b/setup.py index a3fb2707c3..01810aa5c2 100644 --- a/setup.py +++ b/setup.py @@ -66,7 +66,7 @@ def _init_submodule(): pytorch_package_dep = "torch" if pytorch_package_version is not None: - pytorch_package_dep += "==" + pytorch_package_version + pytorch_package_dep += ">=" + pytorch_package_version class clean(distutils.command.clean.clean): diff --git a/torchtext/__init__.py b/torchtext/__init__.py index caca6db7a8..95059c6399 100644 --- a/torchtext/__init__.py +++ b/torchtext/__init__.py @@ -2,6 +2,18 @@ from torch.hub import _get_torch_home +_WARN = True +_TORCHTEXT_DEPRECATION_MSG = ( + "\n/!\ IMPORTANT WARNING ABOUT TORCHTEXT STATUS /!\ \n" + "Torchtext is deprecated and the last released version will be 0.18 (this one). " + "You can silence this warning by calling the following at the beginnign of your scripts: " + "`import torchtext; torchtext.disable_torchtext_deprecation_warning()`" +) + +def disable_torchtext_deprecation_warning(): + global _WARN + _WARN = False + # the following import has to happen first in order to load the torchtext C++ library from torchtext import _extension # noqa: F401 @@ -9,8 +21,6 @@ _CACHE_DIR = os.path.expanduser(os.path.join(_get_torch_home(), "text")) -from . import data, datasets, prototype, functional, models, nn, transforms, utils, vocab, experimental - try: from .version import __version__, git_version # noqa: F401 except ImportError: diff --git a/torchtext/data/__init__.py b/torchtext/data/__init__.py index 7728dbd356..22a57a492a 100644 --- a/torchtext/data/__init__.py +++ b/torchtext/data/__init__.py @@ -1,3 +1,9 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + + from .functional import ( custom_replace, filter_wikipedia_xml, diff --git a/torchtext/datasets/__init__.py b/torchtext/datasets/__init__.py index ba519a5db3..f4585ed48e 100644 --- a/torchtext/datasets/__init__.py +++ b/torchtext/datasets/__init__.py @@ -1,3 +1,9 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + + import importlib from .ag_news import AG_NEWS diff --git a/torchtext/datasets/cnndm.py b/torchtext/datasets/cnndm.py index 92b2da8ce1..e94c59e054 100644 --- a/torchtext/datasets/cnndm.py +++ b/torchtext/datasets/cnndm.py @@ -77,12 +77,21 @@ def _hash_urls(s: tuple): def _get_split_list(source: str, split: str): + from torchdata.datapipes.iter import ( # noqa + IterableWrapper, + OnlineReader, + ) url_dp = IterableWrapper([SPLIT_LIST[source + "_" + split]]) online_dp = OnlineReader(url_dp) return online_dp.readlines().map(fn=_hash_urls) def _load_stories(root: str, source: str, split: str): + from torchdata.datapipes.iter import ( # noqa + FileOpener, + IterableWrapper, + GDriveReader, + ) split_list = set(_get_split_list(source, split)) story_dp = IterableWrapper([URL[source]]) cache_compressed_dp = story_dp.on_disk_cache( @@ -135,12 +144,6 @@ def CNNDM(root: str, split: Union[Tuple[str], str]): raise ModuleNotFoundError( "Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data" ) - from torchdata.datapipes.iter import ( # noqa - FileOpener, - IterableWrapper, - OnlineReader, - GDriveReader, - ) cnn_dp = _load_stories(root, "cnn", split) dailymail_dp = _load_stories(root, "dailymail", split) diff --git a/torchtext/experimental/__init__.py b/torchtext/experimental/__init__.py index e69de29bb2..c382cc7bf6 100644 --- a/torchtext/experimental/__init__.py +++ b/torchtext/experimental/__init__.py @@ -0,0 +1,4 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) diff --git a/torchtext/functional.py b/torchtext/functional.py index 73f96a91c6..8c10579fad 100644 --- a/torchtext/functional.py +++ b/torchtext/functional.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from typing import Any, List, Optional import torch diff --git a/torchtext/models/__init__.py b/torchtext/models/__init__.py index 7b80407811..18789c5dcd 100644 --- a/torchtext/models/__init__.py +++ b/torchtext/models/__init__.py @@ -1,2 +1,7 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from .roberta import * # noqa: F401, F403 from .t5 import * # noqa: F401, F403 diff --git a/torchtext/nn/__init__.py b/torchtext/nn/__init__.py index c48d6de70e..4e4bb23987 100644 --- a/torchtext/nn/__init__.py +++ b/torchtext/nn/__init__.py @@ -1 +1,6 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from .modules import * # noqa: F401,F403 diff --git a/torchtext/prototype/__init__.py b/torchtext/prototype/__init__.py index f7f17fa618..1344c46737 100644 --- a/torchtext/prototype/__init__.py +++ b/torchtext/prototype/__init__.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from . import transforms __all__ = ["transforms"] diff --git a/torchtext/transforms.py b/torchtext/transforms.py index 98ba7b3f55..d25d6dc89b 100644 --- a/torchtext/transforms.py +++ b/torchtext/transforms.py @@ -1,3 +1,9 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + + import json import re from copy import deepcopy diff --git a/torchtext/utils.py b/torchtext/utils.py index 9565cc3b85..5c263d8c93 100644 --- a/torchtext/utils.py +++ b/torchtext/utils.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + import gzip import hashlib import logging diff --git a/torchtext/vocab/__init__.py b/torchtext/vocab/__init__.py index 9336b599c3..99fff110c2 100644 --- a/torchtext/vocab/__init__.py +++ b/torchtext/vocab/__init__.py @@ -1,3 +1,8 @@ +import warnings +import torchtext +if torchtext._WARN: + warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG) + from .vectors import CharNGram, FastText, GloVe, pretrained_aliases, Vectors from .vocab import Vocab from .vocab_factory import build_vocab_from_iterator, vocab