xhluca / dl-translate

Library for translating between 200 languages. Built on 🤗 transformers.
https://xhluca.github.io/dl-translate/
MIT License
451 stars 47 forks source link

module 'torch' has no attribute 'device' #43

Closed gitassia closed 2 years ago

gitassia commented 2 years ago

Hello , @xhlulu Please find attached the part of the tutorial that I tried to execute and where I find the error. NB : I used the guide of Pytorch to install torch according to the command appropriate to my system which is: pip3 install torch torchvision torchaudio . The version of torch is 1.10.1 and my python version is 3.8.5 . image

image

Thank you for your help.

xhluca commented 2 years ago

make sure you are using python3 if you use pip3, or python if you used pip. Sometimes both coexist but are not the same thing.

Also check inside your script if you can import torch and call torch device. If that doesn't work there's something wrong with the setup and you should try again installing torch.

Also recommend listing your os. If you are using windows, please use WSL 2.0 with Ubuntu 18 as I have not tried on windows PowerShell.

xhluca commented 2 years ago

Also please post your complete code, as well as what commands you wrote from installation to when you execute it. That would be helpful

gitassia commented 2 years ago

I am using python 3, and pip3. I tried to import torch and no error appeared but when I tried to import torch.device that error appeared again. I have already install and reinstall torch and the problem still exist. For the code I used exactly what was written in the tutorial and when I got this error, I uninstalled and reinstalled torch according to the pytorch guide thinking that it is a version change but apparently it is not the case. I also tried a solution on the web with torch.cuda but it didn't fix the problem and it also mentions torch has no attribute named cuda. @xhlulu

xhluca commented 2 years ago

I think there's a problem with your torch installation. Unfortunately I'm no familiar with how torch works and can't point you to a different direction other than check torch.version

You might want to look through the issues on the torch repository.

xhluca commented 2 years ago

Or try installing with python -m pip install torch

xhluca commented 2 years ago

can you run the following code in python?

import torch

print(torch.__version__)
print(torch.device)

and let me know if that creates an error?

gitassia commented 2 years ago

yes of course here is the error, I think I will have to reinstall all the packages and try again maybe there is a confusion between the names so can I use this command ?: pip uninstall dl-translate @xhlulu

image

xhluca commented 2 years ago

Likely a confusion. Make sure there's no file named torch.py in the same directory as your code.

xhluca commented 2 years ago

@gitassia Since this is an issue with torch, I recommend you to open an issue on https://github.com/pytorch/pytorch/issues and maybe link to this issue if relevant. I'll close this for now.