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 <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
This commit is contained in:
dbonner 2021-02-27 00:53:07 +11:00 committed by GitHub
parent 0647340f3b
commit ee5032a478
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -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)