title: RuntimeError: mat1 and mat2 shapes cannot be multiplied (3x128 and 255x100) in torch with attention layer
body: <p>I have a model and I want to use attention layer in it. In my model I have two encoders and one decoder. Here is one of the encoder, I want to get the output of encoder as a Guassian with <strong>mean = mu_r</strong> and standard deviation as <strong>log_var_r</strong>. I don't have an experience with attention, however here when I want to use the following inputs and layers, I got an error. If I change the linear layer to <strong>nn.Linear(hidden_dim,</strong>..., it works. However, it seems that it is a simple linear. Could you please help me with that? I don't know the other more complicated attention also. Thanks</p>
  <pre><code>hidden_dim = 128
  r_input        = torch.nn.LSTM(24, hidden_dim,5, batch_first=True)
  latent_size    = 100
  mu_r      = nn.Linear(2*hidden_dim  - 1, latent_size) #attention
  log_var_r = nn.Linear(2*hidden_dim  - 1, latent_size) ##attention
          
  def encode_r(self,y):
      
      y         = torch.reshape(y, (-1, 1, 24)) #y = torch.Size([3, 24])
      
      hidden    = torch.flatten(nn.functional.relu(r_input(y)[0]), start_dim=1) #torch.Size([3, 128])
      z_mu      = mu_r(hidden)
      z_log_var = log_var_r(hidden)
      
      return z_mu, z_log_var```
  </code></pre>