Your problem is not related to testing on cpu, but to that input is not contiguous. net.cpu() should be sufficient to pulling the network to CPU. There are two possibilities:

Your X or Y is not contiguous yet the first operation of your net expect them to be. .cuda() makes a contiguous CUDA tensor and copies from CPU so it was fine in training. Try using

X = Variable(torch.from_numpy(x).float().contiguous())
Y = Variable(torch.from_numpy(y).long().contiguous())


Some CPU kernel requires some tensor to be contiguous while the corresponding GPU one doesn’t. If this is the case, then it is a bug and you should submit it.