What’s wrong?
        print("loss: (1)",loss)
        print("penalty: ",penalty)
        loss += penalty
        print("loss: (2)",loss)
        loss.backward()


I got
loss: (1) tensor(5.2173, device='cuda:0', grad_fn=<NllLossBackward>)
penalty:  tensor(0.1816, device='cuda:0', grad_fn=<DivBackward0>)
loss: (2) tensor(5.3989, device='cuda:0', grad_fn=<AddBackward0>)

Traceback (most recent call last):
    loss.backward()
  File ".../torch/tensor.py", line 166, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File ".../torch/autograd/__init__.py", line 99, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: tensor does not have a device

An idea why I get this RuntimeError?