You are already calculating the “inverse” ce losses via: [1/ce_1, 1/ce_2, 1/ce_3], so instead of rewrapping them in a tensor, you could use torch.stack([1/ce_1, 1/ce_2, 1/ce_3]), which would not detach these values.