Pytorch RuntimeError: "host_softmax" not implemented for 'torch.cuda.LongTensor'
I know where the problem is.
y
should be in torch.int64
dtype without one-hot encoding.
And CrossEntropyLoss()
will auto encoding it with one-hot (while out is the probability distribution of prediction like one-hot format).
It can run now!
All right, this worked for me whenever I got error on similar lines (I am gonna keep it here for reference):
- When calling your model on input ensure that your x is float.
- However keep your target as long.
- Call loss on model output and y without any typecasting.
from torch import nn
net = nn.Linear(input, out_classes)
loss_criterion = nn.CrossEntropyLoss()
net = net.to(device)
X = X.to(device).float()
y = y.to(device).long()
y_hat = net(X)
l = loss_criterion(y_hat, y)