Skip to content

Commit 57a193c

Browse files
committed
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 <module> 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
1 parent e7298b5 commit 57a193c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pytorch_lightning/utilities/apply_func.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from copy import copy
1818
from functools import partial
1919
from typing import Any, Callable, Optional, Union
20+
from packaging import version
2021

2122
import numpy as np
2223
import torch
@@ -25,7 +26,10 @@
2526
from pytorch_lightning.utilities.imports import _TORCHTEXT_AVAILABLE
2627

2728
if _TORCHTEXT_AVAILABLE:
28-
from torchtext.data import Batch
29+
if version.parse(torchtext.__version__) < version.parse('0.9.0a0+036df73'):
30+
from torchtext.data import Batch
31+
else:
32+
from torchtext.legacy.data import Batch
2933
else:
3034
Batch = type(None)
3135

0 commit comments

Comments
 (0)