It shouldn’t be necessary to change the model architecture, since the input shape is wrong.
I’m not sure where you’ve checked the shape of the input tensor, but you might want to check the shape of all intermediate activation tensors in the forward method, since the error message gives the shape as [1, 0, 1, 512].