Could you run the code on the CPU and see if you get a proper error message?
That’s basically right. Since PyTorch is a dynamic framework, you have to specify the in and out features of the linear layer, so that the weight matrix can be properly initialized.