Error in using cuda.
Here is the Code:
import robust_loss_pytorch.general
adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction(
num_dims = 4, float_dtype=torch.cuda.FloatTensor, device="cuda")
And here is the document of 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).
Got the error:
---------------------------------------------------------------------------
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:
When I try code adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction(num_dims = 4, float_dtype=torch.cuda.FloatTensor, device="cuda:0")
Got error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-415-c7998f8405f9> in <module>()
2
3 adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction(
----> 4 num_dims = 4, float_dtype=torch.cuda.FloatTensor, device="cuda:0")
~/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)
154 latent_alpha_init.clone().detach().to(
155 dtype=self.float_dtype,
--> 156 device=self.device)[np.newaxis, np.newaxis].repeat(
157 1, self.num_dims),
158 requires_grad=True))
TypeError: to() received an invalid combination of arguments - got (device=str, dtype=torch.tensortype, ), but expected one of:
* (torch.device device, torch.dtype dtype, bool non_blocking, bool copy, *, torch.memory_format memory_format)
* (torch.dtype dtype, bool non_blocking, bool copy, *, torch.memory_format memory_format)
* (Tensor tensor, bool non_blocking, bool copy, *, torch.memory_format memory_format)
Or trying :
adaptive = robust_loss_pytorch.adaptive.AdaptiveLossFunction(
num_dims = 4, float_dtype=torch.cuda.FloatTensor, device=torch.device("cuda"))
Got the same error as :
ValueError: Expected a cuda device with a specified index or an integer, but got:
Would you please provide me the correct usage of cuda?
If you need detailed information,please let me know!