cag*_*ach 3 pytorch pytorch-lightning
在Pytorch-Lightning中,您通常不必指定 cuda 或 gpu。torch.normal
但是当我想使用我创建一个高斯采样张量时
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
Run Code Online (Sandbox Code Playgroud)
那么,我必须如何更改才能torch.normal
使 pytorch-lightning 正常工作?因为我在 cpu和gpu上的不同机器上使用代码
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
Run Code Online (Sandbox Code Playgroud)
如果这是在闪电级别内,推荐的方法是这样做lights = torch.normal(0, 1, size=[100, 3], device=self.device)
。你也可以这样做:lights = torch.normal(0, 1, size=[100, 3]).type_as(tensor)
,tensor
cuda 上的一些张量在哪里。