如何解决火炬闪电中的正态分布采样
在 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"] #already on GPU... sometimes...
lights = torch.normal(0,1,size=[100,3])
lights += centers
解决方法
如果这是在闪电课程之内,建议的方法是进行lights = torch.normal(0,1,size=[100,3],device=self.device)
。
您还可以这样做:lights = torch.normal(0,3]).type_as(tensor)
,其中tensor
是位于cuda上的某个张量。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。