Skip to content

Commit a897aa9

Browse files
atalmanNicolasHug
andauthored
[Release 0.18] Add removeable warnings indicating this is the last release (#2248) (#2257)
* Add removeable warnings indicating this is the last release (#2248) * make pytorch dep a lower bound (#2256) * Fix CNNDM dataset tests (#2246) --------- Co-authored-by: Nicolas Hug <[email protected]>
1 parent b08e979 commit a897aa9

File tree

13 files changed

+74
-9
lines changed

13 files changed

+74
-9
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _init_submodule():
6666

6767
pytorch_package_dep = "torch"
6868
if pytorch_package_version is not None:
69-
pytorch_package_dep += "==" + pytorch_package_version
69+
pytorch_package_dep += ">=" + pytorch_package_version
7070

7171

7272
class clean(distutils.command.clean.clean):

torchtext/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
from torch.hub import _get_torch_home
44

5+
_WARN = True
6+
_TORCHTEXT_DEPRECATION_MSG = (
7+
"\n/!\ IMPORTANT WARNING ABOUT TORCHTEXT STATUS /!\ \n"
8+
"Torchtext is deprecated and the last released version will be 0.18 (this one). "
9+
"You can silence this warning by calling the following at the beginnign of your scripts: "
10+
"`import torchtext; torchtext.disable_torchtext_deprecation_warning()`"
11+
)
12+
13+
def disable_torchtext_deprecation_warning():
14+
global _WARN
15+
_WARN = False
16+
517
# the following import has to happen first in order to load the torchtext C++ library
618
from torchtext import _extension # noqa: F401
719

820
_TEXT_BUCKET = "https://download.pytorch.org/models/text/"
921

1022
_CACHE_DIR = os.path.expanduser(os.path.join(_get_torch_home(), "text"))
1123

12-
from . import data, datasets, prototype, functional, models, nn, transforms, utils, vocab, experimental
13-
1424
try:
1525
from .version import __version__, git_version # noqa: F401
1626
except ImportError:

torchtext/data/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
6+
17
from .functional import (
28
custom_replace,
39
filter_wikipedia_xml,

torchtext/datasets/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
6+
17
import importlib
28

39
from .ag_news import AG_NEWS

torchtext/datasets/cnndm.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,21 @@ def _hash_urls(s: tuple):
7777

7878

7979
def _get_split_list(source: str, split: str):
80+
from torchdata.datapipes.iter import ( # noqa
81+
IterableWrapper,
82+
OnlineReader,
83+
)
8084
url_dp = IterableWrapper([SPLIT_LIST[source + "_" + split]])
8185
online_dp = OnlineReader(url_dp)
8286
return online_dp.readlines().map(fn=_hash_urls)
8387

8488

8589
def _load_stories(root: str, source: str, split: str):
90+
from torchdata.datapipes.iter import ( # noqa
91+
FileOpener,
92+
IterableWrapper,
93+
GDriveReader,
94+
)
8695
split_list = set(_get_split_list(source, split))
8796
story_dp = IterableWrapper([URL[source]])
8897
cache_compressed_dp = story_dp.on_disk_cache(
@@ -135,12 +144,6 @@ def CNNDM(root: str, split: Union[Tuple[str], str]):
135144
raise ModuleNotFoundError(
136145
"Package `torchdata` not found. Please install following instructions at https://github.com/pytorch/data"
137146
)
138-
from torchdata.datapipes.iter import ( # noqa
139-
FileOpener,
140-
IterableWrapper,
141-
OnlineReader,
142-
GDriveReader,
143-
)
144147

145148
cnn_dp = _load_stories(root, "cnn", split)
146149
dailymail_dp = _load_stories(root, "dailymail", split)

torchtext/experimental/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

torchtext/functional.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from typing import Any, List, Optional
27

38
import torch

torchtext/models/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from .roberta import * # noqa: F401, F403
27
from .t5 import * # noqa: F401, F403

torchtext/nn/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from .modules import * # noqa: F401,F403

torchtext/prototype/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from . import transforms
27

38
__all__ = ["transforms"]

torchtext/transforms.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
6+
17
import json
28
import re
39
from copy import deepcopy

torchtext/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
import gzip
27
import hashlib
38
import logging

torchtext/vocab/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import warnings
2+
import torchtext
3+
if torchtext._WARN:
4+
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5+
16
from .vectors import CharNGram, FastText, GloVe, pretrained_aliases, Vectors
27
from .vocab import Vocab
38
from .vocab_factory import build_vocab_from_iterator, vocab

0 commit comments

Comments
 (0)