Thanks, I think this is what I needed. Unfortunately, the first part of initializing the weights doesn’t work with this solution for some reason.
Now, I have the following:
import torch 
import torch.nn as nn 
import numpy as np

class SomeClass(nn.Module):

        def __init__(self):
             super().__init__()

             # create a learnable weight vector
             self.my_weights= nn.Parameter(torch.FloatTensor(240))  # I need the vector to be learned weights
             nn.init.xavier_normal_(self.my_weights)

             self.conv = nn.Conv2d(240, kernel_size=1, out_channels=1)  # are the arguments correct?
   
        def forward(q):

             # q = np.random.randn(150, 96, 96, 240)
             # size: [batch_size, sentence_length, sentence_length, weight_size]
             
            k = (q*self.my_weights)
            k = self.conv(k.permute((0, 3, 1, 2))).squeeze()

I get the following error:
raise ValueError("Fan in and fan out cannot be computed for tensor with less than 2 dimensions")
ValueError: Fan in and fan out cannot be computed for tensor with less than 2 dimensions
(cuda_pytorch)

which is apparently coming from: nn.init.xavier_normal_(self.my_weights)
If I don’t do nn.init.xavier_normal_(self.my_weights), the loss is NaN.
Would doing:
self.concat_linear = nn.Linear(240, 240) 
nn.init.kaiming_normal_(self.concat_linear.weight)

k = self.concat_linear(q)

be an equivalent of:
self.my_weights= nn.Parameter(torch.FloatTensor(240))
nn.init.xavier_normal_(self.my_weights)
k = (q*self.my_weights)

?
However, when I do that, I get the following later on in my code:
  File "...\lib\site-packages\torch\tensor.py", line 381, in __iter__
    raise TypeError('iteration over a 0-d tensor')
TypeError: iteration over a 0-d tensor