Я запускаю простую демонстрацию Pytorch 1.0 и застреваю при попытке настройки CUDA (vscode 1.33.1, Python 3.6)
Мой код Pytorch выглядит следующим образом.
import torch
from torch import cuda
if cuda.is_available():
devic=cuda.device(0)
layer=torch.rand([5,3,2],requires_grad=True)
Все работало нормально ... Но когда я попытался добавить устройство cuda
layer=torch.rand([5,3,2],requires_grad=True,device=devic)
Возникла ошибка TypeError
Traceback (most recent call last):
File "c:\Users\H\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\H\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\lib\python\ptvsd\__main__.py", line 410, in main
run()
File "c:\Users\H\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\lib\python\ptvsd\__main__.py", line 291, in run_file
runpy.run_path(target, run_name='__main__')
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\H\Desktop\pth_test\tutorial1.py", line 25, in <module>
layer1=torch.rand([5,3,2],requires_grad=True,device=devic)
TypeError: rand() received an invalid combination of arguments - got (list, requires_grad=bool, device=device), but expected one of:
* (tuple of ints size, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad)
* (tuple of ints size, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool requires_grad)
Изменение rand () на randn () ни на что не повлияло,Пока empty () и нули () вызывали еще одну ошибку TypeError
Traceback (most recent call last):
File "c:\Users\H\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\H\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\lib\python\ptvsd\__main__.py", line 410, in main
run()
File "c:\Users\H\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\lib\python\ptvsd\__main__.py", line 291, in run_file
runpy.run_path(target, run_name='__main__')
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\H\Desktop\pth_test\tutorial1.py", line 25, in <module>
layer1=torch.empty([5,3,2],requires_grad=True,device=devic)
TypeError: empty(): argument 'device' must be torch.device, not device
Все вышло из-под контроля :( Любая помощь будет оценена