Thanks @albanD for replying. You are correct the values obtained are exactly similar for same z and y. My implementation of xent was wrong. Here is correct implementation.
def xent(z,y):
    y = torch.Tensor(to_one_hot(y,3))
    y_hat = pt_softmax(z)
    loss = -y*torch.log(y_hat)
    loss = loss.sum()/y.shape[0]
    return loss

Previously I was taking mean over all the elements but I have to sum the elements first then take the average w.r.t batch size.