I had K-class classification problem.
I was getting this error when I was using CrossEntropyLoss:
RuntimeError: Expected object of type Variable[torch.LongTensor] but found type
Variable[torch.DoubleTensor] for argument #1 'target’
Here is how I fixed it:
I first defined:
target = Variable(torch.from_numpy(t_train[:batch_size]).long(), requires_grad = False)
loss = torch.nn.CrossEntropyLoss()
Then, in the training step, I defined:
…
y_pred = mlp_instance(x_data)
l = loss(y_pred, target)
…
where y_pred is a  batch_size by K tensor but target is a tensor (simply a vector) of size batch_size; note that target isn’t one-hot tensor with shape: batch_size by K.