I found this discussion about this, in which the code
if std.is_cuda:
eps = torch.FloatTensor(std.size()).cuda().normal_()
else:
eps = torch.FloatTensor(std.size()).normal_()
becomes the nice
eps = std.new().normal_()
but it is said there that
- How to create a new tensor directly on a specific device?
- How to create a new tensor on the same device like another tensor without the ugly
if?