Make K2 an nn.Parameter and store it in the nn.Module. Like it is done for all nn modules.
If you don’t use nn.Module, juste make sure that K2 requires gradients and that it is passed to your optimizer.