Sometimes, we need to create a module with learnable parameters. For example, when we construct a-softmax module, we need the module contains a weight W which should be learnt and updated during the process of training.
By looking at the docs, it seems that I should use it like this:
class mod(nn.Module):
    def __init__(self):
         self.W = torch.tensor(torch.random(3,4,5), requires_grad=True)
    def forward(self, x):
        w_norm = torch.norm(self.W, 2, 1, True).expand_as(self.W)
        x_norm = torch.norm(x, 2, 1, True).expand_as(x)
        theta = torch.mm(x, self.W) / (x_norm * w_norm)
        return theta
...
loss = mod()
params = loss.parameters()
optim = Optimizer(params, lr = 1e-3...)
...

I am just trying to confirm, is this the recommanded way to do this ?