From 3c1acee5a39935476deca86644dd1d91160737e2 Mon Sep 17 00:00:00 2001 From: Gleb Karpushkin Date: Mon, 5 Dec 2022 12:39:10 +0300 Subject: [PATCH] Update loss.py Fixed an issue of RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! --- modules/loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/loss.py b/modules/loss.py index f9d6e39b28..eb118bc7e8 100644 --- a/modules/loss.py +++ b/modules/loss.py @@ -74,7 +74,7 @@ def rand_between(low, high, normal=False): if normal: return torch.randn(1) * (high - low) + low else: - return torch.rand(1) * (high - low) + low + return torch.rand(1, device=torch.device('cuda:0')) * (high - low) + low def get_target_tensor(self, prediction, target_is_real): """Create label tensors with the same size as the input.