Linear multiplication over every element of 2d input?

Suppose I have an input like torch.shape = (64, 123)

I want to do a nn.linear(64,1) on each of the rows so I get output shape = (1, 123) Is there a way to do this?

You could transpose the input and output:

x = torch.randn(64, 123)
lin = nn.Linear(64, 1)

out = lin(x.T).T
# torch.Size([1, 123])

but should make sure the dimensions are interpreted correctly.
Note that the linear layer expects inputs in the shape [batch_size, in_features] so check if transposing is creating these dimensions.

Dang! It works! Thanks a million.