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.