Wrapping the tensor into nn.Parameter
makes sure it’s trainable, i.e. it uses requires_grad=True
. You can also set it manually, but I would generally recommend to use nn.Parameter
s, as it’ll also make sure to register this parameter e.g. inside an nn.Module
.