Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'torch' has no attribute 'float32' #900

Closed
SimlaBurcu opened this Issue Aug 14, 2018 · 15 comments

Comments

Projects
None yet
6 participants
@SimlaBurcu
Copy link

SimlaBurcu commented Aug 14, 2018

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'
@rbommasanimozilla

This comment has been minimized.

Copy link

rbommasanimozilla commented Aug 14, 2018

What command did you run/how was the error produced?

@SimlaBurcu

This comment has been minimized.

Copy link
Author

SimlaBurcu commented Aug 14, 2018

Oh sorry, I forgot to write that! I have just edited my question.

@vince62s

This comment has been minimized.

Copy link
Contributor

vince62s commented Aug 14, 2018

4.0.4 is not a pytorch version, do you mean 0.4.0 or 0.4.1 ?
also what if you use gpu to translate ?

@SimlaBurcu

This comment has been minimized.

Copy link
Author

SimlaBurcu commented Aug 14, 2018

I meant 0.4.0, sorry about that. I tried to run with gpu as well, same error again.

@vince62s

This comment has been minimized.

Copy link
Contributor

vince62s commented Aug 14, 2018

try to reinstall pytorch 0.4.0

@SimlaBurcu

This comment has been minimized.

Copy link
Author

SimlaBurcu commented Aug 15, 2018

I did, it gives the same error again.

@vince62s

This comment has been minimized.

Copy link
Contributor

vince62s commented Aug 15, 2018

are you having the issue onmy with the translate command ? remove the replace_unk
but I think your issue is an installation issue.

@SimlaBurcu

This comment has been minimized.

Copy link
Author

SimlaBurcu commented Aug 15, 2018

I tried removing it, again the same. I think you're right but I couldn't find how to fix it.
I first cloned the OpenNMT project 2.5 months ago and I still have that version and it works fine (but with pytorch=0.2.0 and torchtext==0.2.3). Recently, I cloned the latest version of OpenNMT and reinstalled pytorch and torchtext with the proper versions (pytorch 0.4.0 and torchtext 0.3.0), and I am getting this error.

@vince62s

This comment has been minimized.

Copy link
Contributor

vince62s commented Aug 18, 2018

Did you try in a clean install with anaconda ?

@vince62s

This comment has been minimized.

Copy link
Contributor

vince62s commented Aug 27, 2018

closing, reopne if needed.

@vince62s vince62s closed this Aug 27, 2018

@tangxiangru

This comment has been minimized.

Copy link

tangxiangru commented Oct 27, 2018

i need it. same bug

@vince62s

This comment has been minimized.

Copy link
Contributor

vince62s commented Oct 27, 2018

post your full config (pytorch, torchtext, python versions) and commandl ines

@navneetkrc

This comment has been minimized.

Copy link

navneetkrc commented Nov 8, 2018

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

@ghost

This comment has been minimized.

Copy link

ghost commented Nov 12, 2018

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

@Hunterhuan

This comment has been minimized.

Copy link

Hunterhuan commented Dec 4, 2018

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

Thanks! It solve my problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.