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

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

Closed
gitassia opened this issue Jan 8, 2022 · 9 comments
Closed

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

gitassia opened this issue Jan 8, 2022 · 9 comments

Comments

@gitassia
Copy link

gitassia commented Jan 8, 2022

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
Copy link
Owner

xhluca commented Jan 8, 2022

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
Copy link
Owner

xhluca commented Jan 8, 2022

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
Copy link
Author

gitassia commented Jan 8, 2022

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
Copy link
Owner

xhluca commented Jan 8, 2022

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
Copy link
Owner

xhluca commented Jan 8, 2022

Or try installing with python -m pip install torch

@xhluca
Copy link
Owner

xhluca commented Jan 9, 2022

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
Copy link
Author

gitassia commented Jan 9, 2022

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
Copy link
Owner

xhluca commented Jan 9, 2022

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

@xhluca
Copy link
Owner

xhluca commented Jan 13, 2022

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

@xhluca xhluca closed this as completed Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants