Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytorch:使用cuda时出错(ValueError:应为具有指定索引或整数的cuda设备,但Get:)_Python_Pytorch - Fatal编程技术网

Python pytorch:使用cuda时出错(ValueError:应为具有指定索引或整数的cuda设备,但Get:)

Python pytorch:使用cuda时出错(ValueError:应为具有指定索引或整数的cuda设备,但Get:),python,pytorch,Python,Pytorch,使用cuda时出错 代码如下: import robust_loss_pytorch.general adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction( num_dims = 4, float_dtype=torch.cuda.FloatTensor, device="cuda") 以下是robust_loss_pytorch.adaptive.AdaptiveLossFunction的文档

使用cuda时出错

代码如下:

import robust_loss_pytorch.general

adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction(
    num_dims = 4, float_dtype=torch.cuda.FloatTensor, device="cuda")

以下是robust_loss_pytorch.adaptive.AdaptiveLossFunction的文档:

Args:
  num_dims: The number of dimensions of the input to come.
  float_dtype: The floating point precision of the inputs to come.
  device: The device to run on (cpu, cuda, etc).

获取错误信息:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-414-22ef6dd72b45> in <module>()
      2 
      3 adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction(
----> 4     num_dims = 4, float_dtype=torch.cuda.FloatTensor, device="cuda")

~/anaconda3/envs/torch36/lib/python3.6/site-packages/robust_loss_pytorch/adaptive.py in __init__(self, num_dims, float_dtype, device, alpha_lo, alpha_hi, alpha_init, scale_lo, scale_init)
    130        (isinstance(device, str) and 'cuda' in device) or\
    131        (isinstance(device, torch.device) and device.type == 'cuda'):
--> 132         torch.cuda.set_device(self.device)
    133 
    134     self.distribution = distribution.Distribution()

~/anaconda3/envs/torch36/lib/python3.6/site-packages/torch/cuda/__init__.py in set_device(device)
    241             if this argument is negative.
    242     """
--> 243     device = _get_device_index(device)
    244     if device >= 0:
    245         torch._C._cuda_setDevice(device)

~/anaconda3/envs/torch36/lib/python3.6/site-packages/torch/cuda/_utils.py in _get_device_index(device, optional)
     32         else:
     33             raise ValueError('Expected a cuda device with a specified index '
---> 34                              'or an integer, but got: '.format(device))
     35     return device_idx

ValueError: Expected a cuda device with a specified index or an integer, but got: 
或尝试:

adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction(
    num_dims = 4, float_dtype=torch.cuda.FloatTensor, device=torch.device("cuda"))
得到与以下相同的错误:

ValueError: Expected a cuda device with a specified index or an integer, but got:
你能告诉我cuda的正确用法吗

如果您需要详细信息,请告诉我

ValueError: Expected a cuda device with a specified index or an integer, but got: