diff --git a/.github/workflows/docs-checks.yml b/.github/workflows/docs-checks.yml index 347f20196d974..5ee4f23b4b3cc 100644 --- a/.github/workflows/docs-checks.yml +++ b/.github/workflows/docs-checks.yml @@ -41,6 +41,8 @@ jobs: - name: Install dependencies run: | + python --version + pip --version # remove Horovod from requirements python -c "fname = 'requirements/extra.txt' ; lines = [line for line in open(fname).readlines() if not line.startswith('horovod')] ; open(fname, 'w').writelines(lines)" # python -m pip install --upgrade --user pip @@ -48,8 +50,6 @@ jobs: pip install --requirement requirements/extra.txt pip install --requirement requirements/loggers.txt pip install --requirement requirements/docs.txt - python --version - pip --version pip list shell: bash @@ -84,12 +84,12 @@ jobs: - name: Install dependencies run: | - pip install --requirement requirements.txt --upgrade-strategy only-if-needed --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet + python --version + pip --version + # pip install --requirement requirements.txt --upgrade-strategy only-if-needed --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --quiet pip install --requirement requirements/docs.txt # install Texlive, see https://linuxconfig.org/how-to-install-latex-on-ubuntu-20-04-focal-fossa-linux sudo apt-get update && sudo apt-get install -y texlive-latex-extra dvipng texlive-pictures - python --version - pip --version pip list shell: bash diff --git a/pytorch_lightning/utilities/apply_func.py b/pytorch_lightning/utilities/apply_func.py index 0599cccec83be..9fd42008b9d8d 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import operator from abc import ABC from collections.abc import Mapping, Sequence from copy import copy @@ -22,10 +22,10 @@ import torch from pytorch_lightning.utilities.exceptions import MisconfigurationException -from pytorch_lightning.utilities.imports import _module_available, _TORCHTEXT_AVAILABLE +from pytorch_lightning.utilities.imports import _compare_version, _TORCHTEXT_AVAILABLE if _TORCHTEXT_AVAILABLE: - if _module_available("torchtext.legacy.data"): + if _compare_version("torchtext", operator.ge, "0.9.0"): from torchtext.legacy.data import Batch else: from torchtext.data import Batch diff --git a/tests/helpers/imports.py b/tests/helpers/imports.py new file mode 100644 index 0000000000000..4db9c00d45eab --- /dev/null +++ b/tests/helpers/imports.py @@ -0,0 +1,8 @@ +import operator + +from pytorch_lightning.utilities.imports import _compare_version + +if _compare_version("torchtext", operator.ge, "0.9.0"): + from torchtext.legacy.data import Batch, Dataset, Example, Field, Iterator, LabelField # noqa: F401 +else: + from torchtext.data import Batch, Dataset, Example, Field, Iterator, LabelField # noqa: F401 diff --git a/tests/models/test_gpu.py b/tests/models/test_gpu.py index 537dfd3e1006b..7764754594a09 100644 --- a/tests/models/test_gpu.py +++ b/tests/models/test_gpu.py @@ -16,7 +16,6 @@ import pytest import torch -from torchtext.data import Batch, Dataset, Example, Field, LabelField import tests.helpers.pipelines as tpipes import tests.helpers.utils as tutils @@ -25,6 +24,7 @@ from pytorch_lightning.utilities.exceptions import MisconfigurationException from tests.helpers import BoringModel from tests.helpers.datamodules import ClassifDataModule +from tests.helpers.imports import Batch, Dataset, Example, Field, LabelField from tests.helpers.runif import RunIf from tests.helpers.simple_models import ClassificationModel diff --git a/tests/utilities/test_apply_func_torchtext.py b/tests/utilities/test_apply_func_torchtext.py index 4c9de8a1a8e25..fa5b822271533 100644 --- a/tests/utilities/test_apply_func_torchtext.py +++ b/tests/utilities/test_apply_func_torchtext.py @@ -13,15 +13,14 @@ # limitations under the License. import pytest import torch -import torchtext -from torchtext.data.example import Example from pytorch_lightning.utilities.apply_func import move_data_to_device +from tests.helpers.imports import Dataset, Example, Field, Iterator from tests.helpers.runif import RunIf def _get_torchtext_data_iterator(include_lengths=False): - text_field = torchtext.data.Field( + text_field = Field( sequential=True, pad_first=False, # nosec init_token="", @@ -33,13 +32,13 @@ def _get_torchtext_data_iterator(include_lengths=False): example2 = Example.fromdict({"text": "b c a a"}, {"text": ("text", text_field)}) example3 = Example.fromdict({"text": "c b a"}, {"text": ("text", text_field)}) - dataset = torchtext.data.Dataset( + dataset = Dataset( [example1, example2, example3], {"text": text_field}, ) text_field.build_vocab(dataset) - iterator = torchtext.data.Iterator( + iterator = Iterator( dataset, batch_size=3, sort_key=None,