Pytorch Pyrotch闪电的正态分布抽样

Pytorch Pyrotch闪电的正态分布抽样,pytorch,pytorch-lightning,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! 那么,我必须如何更改torch.normal,才能使pytorch lightning正常工作?因为我在cpu和gpu上的不同机器上使用代码 ce

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!
那么,我必须如何更改
torch.normal
,才能使pytorch lightning正常工作?因为我在cpu和gpu上的不同机器上使用代码

centers=data[“centers”]#已在GPU上。。。有时。。。
灯光=火炬。正常(0,1,大小=[100,3])
灯光+=中心

如果在lightning类中,建议使用
lights=torch.normal(0,1,大小=[100,3],设备=self.device)

你也可以这样做:
lights=torch.normal(0,1,size=[100,3])。键入as(tensor)
,其中
tensor
是cuda上的某个张量。

建议的方法是做
lights=torch.normal(0,1,size=[100,3],device=self.device)
,如果这是在lightning类中的话。
您也可以这样做:
lights=torch.normal(0,1,size=[100,3])。键入作为(张量)
,其中
tensor
是cuda上的某个张量。

只需将其移动到与其交互的其他张量之一的相同设备上即可。由于您没有发布任何代码,因此很难更具体地说明应该做什么。只需将其移动到与其他张量之一相同的设备上即可。因为您没有发布任何代码,所以很难更具体地说明应该做什么。