Skip to content

Commit

Permalink
apply_func.py: from torchtext.legacy.data import Batch (#6211)
Browse files Browse the repository at this point in the history
* 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

* Update apply_func.py

* Update apply_func.py

* Update apply_func.py

* Update apply_func.py

* Update apply_func.py
  • Loading branch information
dbonner authored Feb 26, 2021
1 parent 0647340 commit ee5032a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pytorch_lightning/utilities/apply_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@

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)

Expand Down

0 comments on commit ee5032a

Please sign in to comment.