I tried using torch.stack but instead of getting a single element loss, i got this:

tensor([0.9472, 0.6654, 0.6768, 0.4873, 0.4726, 0.4873, 0.4873, 0.6212, 0.6212,
    0.5999, 0.6359, 0.5999, 0.7993, 0.4873, 0.6212, 0.6768],

   device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>)

tensor([0.9482, 0.6664, 0.6778, 0.4883, 0.4736, 0.4883, 0.4883, 0.6223, 0.6223,
    0.6010, 0.6370, 0.6010, 0.8003, 0.4883, 0.6223, 0.6778],

   device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>)

tensor([0.9484, 0.6666, 0.6780, 0.4886, 0.4738, 0.4886, 0.4886, 0.6225, 0.6225,
    0.6012, 0.6372, 0.6012, 0.8006, 0.4886, 0.6225, 0.6780],

   device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>)

tensor([0.9498, 0.6680, 0.6794, 0.4899, 0.4752, 0.4899, 0.4899, 0.6239, 0.6239,
    0.6026, 0.6386, 0.6026, 0.8020, 0.4899, 0.6239, 0.6794],

   device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>)

tensor([0.9501, 0.6683, 0.6797, 0.4902, 0.4754, 0.4902, 0.4902, 0.6241, 0.6241,
    0.6028, 0.6388, 0.6028, 0.8022, 0.4902, 0.6241, 0.6797],

   device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>)

tensor([0.9511, 0.6693, 0.6807, 0.4912, 0.4765, 0.4912, 0.4912, 0.6251, 0.6251,
    0.6038, 0.6399, 0.6038, 0.8032, 0.4912, 0.6251, 0.6807],

   device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>)

tensor([0.9524, 0.6706, 0.6820, 0.4925, 0.4778, 0.4925, 0.4925, 0.6265, 0.6265,
    0.6052, 0.6412, 0.6052, 0.8045, 0.4925, 0.6265, 0.6820],

   device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>


can you help me figure out what I’m doing wrong? aI probably need to correct the last line in my loss function.