Two tensors are on the same device, but I get the error: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu
I have:
def loss_fn(self, pred, truth):        
    truth_flat = torch.reshape(truth, (truth.size(0),-1)).to(truth.device)
    pred_flat = torch.reshape(pred, (pred.size(0),-1)).to(pred.device)
    
    stoi_loss = NegSTOILoss(sample_rate=16000)(pred_flat, truth_flat)
    print('truth', truth.size(), truth_flat.size(), stoi_loss)

    return torch.nn.MSELoss()(pred, truth)

As you can see, I'm making sure that it's on the same device, but I still get the error:
Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu

Any ideas?

You are assigning to two different devices, truth.device and pred.device.
