From ee5032a47850b987cb12b242812c3a4eb653231e Mon Sep 17 00:00:00 2001 From: dbonner <241474+dbonner@users.noreply.github.com> Date: Sat, 27 Feb 2021 00:53:07 +1100 Subject: [PATCH] apply_func.py: from torchtext.legacy.data import Batch (#6211) * 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 * Update apply_func.py * Update apply_func.py * Update apply_func.py * Update apply_func.py * Update apply_func.py --- 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 2f7425bf3b..27ec0a5389 100644 --- a/pytorch_lightning/utilities/apply_func.py +++ b/pytorch_lightning/utilities/apply_func.py @@ -23,9 +23,13 @@ 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.data import Batch + if _module_available("torchtext.legacy.data"): + from torchtext.legacy.data import Batch + else: + from torchtext.data import Batch else: Batch = type(None)