PyTorch expects the input tensor and model parameters to have the same dtype and thus raises the error. torch.randint returns a LongTensor, while the model parameters are initialized as FloatTensors, which is why you need to change the input to torch.float.