The error message is (wrongly) raised, if you pass the input as a LongTensor, which won’t work since gradients aren’t calculated for int/long types.
How are you creating the input to this loss function?
If you are calling output.long() on the model output, note that this operation will detach the tensor from the computation graph.