How to customize parameters in the model?

If I want to customize a 2048 length vector as a parameter in the model, how do I define it in model’s __init__ function?Its operation in forward() is:x = F.relu(x * self.W_sub1).unsqueeze(1).
I have used self.W_sub1 = nn.Parameter(torch.randn(2048)) to define it,but got:
`TypeError: mul received an invalid combination of arguments - got (Parameter), but expected one of:

  • (float value)
    didn’t match because some of the arguments have invalid types: (Parameter)`

self.W_sub1.data will return tensor object. But the code shouldn’t be worong…Follwing code has right output

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.W_sub1 = nn.Parameter(torch.randn(2048))
    def forward(self, x):
        x = F.relu(x * self.W_sub1).unsqueeze(1)
        return x
net = Net()
x = torch.randn(2048)
y_pred
tensor([[0.1318],
        [0.0000],
        [0.0000],
        ...,
        [0.2246],
        [0.0000],
        [2.0227]], grad_fn=<UnsqueezeBackward0>)