In your original code you have:
   lin = nn.Linear(n_in, n_out)
...
   layers = [lin(n_in, n_out)]

The expression lin(n_in, n_out)
is not creating a linear layer (that already happens above!) – it’s trying to do a forward pass on the linear layer and failing because of the invalid arguments. Instead you should just write:
   layers = [lin]

The code in your second post is equivalent to this, but more complicated.