How to use nn.optimizer in my own problem

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.Parameters, as it’ll also make sure to register this parameter e.g. inside an nn.Module.