Skip to content

[Release 0.18] Add removeable warnings indicating this is the last release (#2248) #2257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 12 additions & 2 deletions torchtext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@

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

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

_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:
Expand Down
6 changes: 6 additions & 0 deletions torchtext/data/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 6 additions & 0 deletions torchtext/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 9 additions & 6 deletions torchtext/datasets/cnndm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions torchtext/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)
5 changes: 5 additions & 0 deletions torchtext/functional.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions torchtext/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions torchtext/nn/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

from .modules import * # noqa: F401,F403
5 changes: 5 additions & 0 deletions torchtext/prototype/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

from . import transforms

__all__ = ["transforms"]
6 changes: 6 additions & 0 deletions torchtext/transforms.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions torchtext/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import warnings
import torchtext
if torchtext._WARN:
warnings.warn(torchtext._TORCHTEXT_DEPRECATION_MSG)

import gzip
import hashlib
import logging
Expand Down
5 changes: 5 additions & 0 deletions torchtext/vocab/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down