It’s weird that it worked. I don’t think the problem is from torch.log., because if the input to torch.log is in CUDA, the output will also be in CUDA:
>>> x = torch.tensor([1.0, 2.0, 3.0])
>>> device = torch.device('cuda:0')
>>> device
device(type='cuda', index=0)
>>> x.device
device(type='cpu')
>>> x = x.to(device)
>>> x.device
device(type='cuda', index=0)
>>> torch.log(x)
tensor([0.0000, 0.6931, 1.0986], device='cuda:0')