From 57a193cbff01df57d632a79d5d862340d08f38d5 Mon Sep 17 00:00:00 2001 From: dbonner <241474+dbonner@users.noreply.github.com> Date: Fri, 26 Feb 2021 16:17:32 +1100 Subject: [PATCH 1/6] Update apply_func.py The name Batch is no longer located under torchtext.data --Error message-- File "/home/daniel/py38/lib/python3.8/site-packages/pytorch_lightning/utilities/apply_func.py", line 25, in from torchtext.data import Batch ImportError: cannot import name 'Batch' from 'torchtext.data' (/home/daniel/py38/lib/p ython3.8/site-packages/torchtext/data/__init__.py) You can fix this by changing line line 28 to: from torchtext.legacy.data import Batch --- pytorch_lightning/utilities/apply_func.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/apply_func.py b/pytorch_lightning/utilities/apply_func.py index 2f7425bf3beb0..52d48483beafc 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -17,6 +17,7 @@ from copy import copy from functools import partial from typing import Any, Callable, Optional, Union +from packaging import version import numpy as np import torch @@ -25,7 +26,10 @@ from pytorch_lightning.utilities.imports import _TORCHTEXT_AVAILABLE if _TORCHTEXT_AVAILABLE: - from torchtext.data import Batch + if version.parse(torchtext.__version__) < version.parse('0.9.0a0+036df73'): + from torchtext.data import Batch + else: + from torchtext.legacy.data import Batch else: Batch = type(None) From 8416a6c924d33b0ad18ff2efa14beb0c8fbdacbf Mon Sep 17 00:00:00 2001 From: dbonner <241474+dbonner@users.noreply.github.com> Date: Fri, 26 Feb 2021 16:39:31 +1100 Subject: [PATCH 2/6] Update apply_func.py --- pytorch_lightning/utilities/apply_func.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/apply_func.py b/pytorch_lightning/utilities/apply_func.py index 52d48483beafc..4feac475d7d1b 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -21,12 +21,13 @@ import numpy as np import torch +from torchtext import __version__ as torchtext_version from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.imports import _TORCHTEXT_AVAILABLE if _TORCHTEXT_AVAILABLE: - if version.parse(torchtext.__version__) < version.parse('0.9.0a0+036df73'): + if version.parse(torchtext_version) < version.parse('0.9.0a0+036df73'): from torchtext.data import Batch else: from torchtext.legacy.data import Batch From 52ebcec3fe911f32bb40c0ac85734a02cf3debca Mon Sep 17 00:00:00 2001 From: dbonner <241474+dbonner@users.noreply.github.com> Date: Fri, 26 Feb 2021 16:52:26 +1100 Subject: [PATCH 3/6] Update apply_func.py --- pytorch_lightning/utilities/apply_func.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/apply_func.py b/pytorch_lightning/utilities/apply_func.py index 4feac475d7d1b..024b75597c78e 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -21,12 +21,12 @@ import numpy as np import torch -from torchtext import __version__ as torchtext_version from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.imports import _TORCHTEXT_AVAILABLE if _TORCHTEXT_AVAILABLE: + from torchtext import __version__ as torchtext_version if version.parse(torchtext_version) < version.parse('0.9.0a0+036df73'): from torchtext.data import Batch else: From 67e838b6240af61d37789276d041f52bb4c5595a Mon Sep 17 00:00:00 2001 From: dbonner <241474+dbonner@users.noreply.github.com> Date: Fri, 26 Feb 2021 19:04:06 +1100 Subject: [PATCH 4/6] Update apply_func.py --- pytorch_lightning/utilities/apply_func.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytorch_lightning/utilities/apply_func.py b/pytorch_lightning/utilities/apply_func.py index 024b75597c78e..b3f2ab4db36ee 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -17,7 +17,7 @@ from copy import copy from functools import partial from typing import Any, Callable, Optional, Union -from packaging import version +from distutils.version import LooseVersion import numpy as np import torch @@ -27,7 +27,7 @@ if _TORCHTEXT_AVAILABLE: from torchtext import __version__ as torchtext_version - if version.parse(torchtext_version) < version.parse('0.9.0a0+036df73'): + if LooseVersion(torchtext_version) < LooseVersion('0.9.0a0+036df73'): from torchtext.data import Batch else: from torchtext.legacy.data import Batch From 05ec7c73b5a979747407f0dded730a71f6833c3b Mon Sep 17 00:00:00 2001 From: dbonner <241474+dbonner@users.noreply.github.com> Date: Sat, 27 Feb 2021 00:10:42 +1100 Subject: [PATCH 5/6] Update apply_func.py --- pytorch_lightning/utilities/apply_func.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pytorch_lightning/utilities/apply_func.py b/pytorch_lightning/utilities/apply_func.py index b3f2ab4db36ee..23f53a2104ff0 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -17,20 +17,19 @@ from copy import copy from functools import partial from typing import Any, Callable, Optional, Union -from distutils.version import LooseVersion import numpy as np import torch from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.imports import _TORCHTEXT_AVAILABLE +from pytorch_lightning.utilities.imports import _module_available if _TORCHTEXT_AVAILABLE: - from torchtext import __version__ as torchtext_version - if LooseVersion(torchtext_version) < LooseVersion('0.9.0a0+036df73'): - from torchtext.data import Batch - else: + if _module_available("torchtext.legacy"): from torchtext.legacy.data import Batch + else: + from torchtext.data import Batch else: Batch = type(None) From 58b5a595b0c36c9dcc10a99cbe8ba85ba550c47f Mon Sep 17 00:00:00 2001 From: dbonner <241474+dbonner@users.noreply.github.com> Date: Sat, 27 Feb 2021 00:22:33 +1100 Subject: [PATCH 6/6] Update apply_func.py --- pytorch_lightning/utilities/apply_func.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/apply_func.py b/pytorch_lightning/utilities/apply_func.py index 23f53a2104ff0..27ec0a53894d6 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -26,7 +26,7 @@ from pytorch_lightning.utilities.imports import _module_available if _TORCHTEXT_AVAILABLE: - if _module_available("torchtext.legacy"): + if _module_available("torchtext.legacy.data"): from torchtext.legacy.data import Batch else: from torchtext.data import Batch