jarvico:

First of all , I needed to use softmax at last layer.


Why would that be the case?



 jarvico:

If I remove Relu from last layer, how can I guarantee the term output in torch.log become non negative?


F.nll_loss or nn.NLLLoss expects log probabilities as the model output, so you should use:
output = F.log_softmax(x, dim=1)
loss = F.nll_loss(output, target)

while nn.CrossEntropyLoss expects raw logits and will apply F.log_softmax + F.nll_loss internally.