If youâ€™re using CrossEntropyLoss, your target (label) should be a LongTensor. It varies based on the loss function. For example, for MSELoss, your target (label) should have the same type as your input.
To convert any tensor t to a LongTensor, you can do t.long().

Thanks @richard for your reply I fixed it. I also observed that for cross entropy loss requires a [1,] size tensor for batch size =1. I was giving a [1x1] tensor and it was not being able to work with that. This was pretty annoying though.

It would have been better if these things were consistent for all the loss functions.