OpenNMT-py: AttributeError: module 'torch' has no attribute 'float32'

I run the command python translate.py -model averaged-10-epoch.pt -src data/test.txt -output pred.txt -replace_unk -verbose I have pytorch 0.4.0 and torchtext 0.3.0 installed, but I am getting the following error:

Traceback (most recent call last):
  File "translate.py", line 7, in <module>
    from onmt.utils.logging import init_logger
  File "/home/simla/nmt/OpenNMT-py/onmt/__init__.py", line 4, in <module>
    import onmt.inputters
  File "/home/simla/nmt/OpenNMT-py/onmt/inputters/__init__.py", line 6, in <module>
    from onmt.inputters.inputter import collect_feature_vocabs, make_features, \
  File "/home/simla/nmt/OpenNMT-py/onmt/inputters/inputter.py", line 11, in <module>
    import torchtext.data
  File "/home/simla/venv/lib/python3.6/site-packages/torchtext/__init__.py", line 1, in <module>
    from . import data
  File "/home/simla/venv/lib/python3.6/site-packages/torchtext/data/__init__.py", line 4, in <module>
    from .field import RawField, Field, ReversibleField, SubwordField, NestedField, LabelField
  File "/home/simla/venv/lib/python3.6/site-packages/torchtext/data/field.py", line 61, in <module>
    class Field(RawField):
  File "/home/simla/venv/lib/python3.6/site-packages/torchtext/data/field.py", line 115, in Field
    torch.float32: float,
AttributeError: module 'torch' has no attribute 'float32'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

i got the same issue. pip install torchtext==0.2.3 you need to change version of torchtext

torchtext is the offending …?module?..(not sure what to call it) that causes this error. The authors released torchtext 0.3.1 earlier today (2018-10-11). Installing the previous version restores full functionality: !{sys.executable} -m pip install torchtext==0.2.3