【pytorch错误】:Pytorch RuntimeError: “host_softmax” not implemented for 'torch.cuda.LongTensor'

问题

Pytorch RuntimeError: “host_softmax” not implemented for ‘torch.cuda.LongTensor’


报错的位置在这个地方

    loss=criterion(out,train_y)  # train_y 应该是int64
原因

参考:https://stackoverflow.com/questions/51818225/pytorch-runtimeerror-host-softmax-not-implemented-for-torch-cuda-longtensor。
大致就是说,train_y应该是int64类型.

解决

在将train_y变为一个tensor的时候,设置数据类型为int64。

    train_x=torch.tensor(train_x,dtype=torch.float32).cuda()
    train_y=torch.tensor(train_y,dtype=torch.int64).cuda()
    train_x = Variable(train_x)
    train_y = Variable(train_y)