loss = nn.CrossEntropyLoss()
input = torch.randn(3, 5, requires_grad=True)
target = torch.empty(3, dtype=torch.long).random_(5)
output = loss(input, target)
output.backward()

This is an example of nn.crossentropy loss from Pytorch docs.
https://pytorch.org/docs/stable/nn.html#torch.nn.CrossEntropyLoss
This is run on torch 0.1.5 version and shows no grad_fn error