I’m trying to implement meta-gradient learning similarly to [https://arxiv.org/pdf/1805.09801.pdf 12].
I need to backpropagate through a parameter update.
The following is a minimum example that highlights the problem:
                meta_param = torch.tensor(5.0,requires_grad=True) # this is the variable i want to learn
                param = torch.nn.Parameter(torch.tensor(4.0,requires_grad=True)) # this is a module param
                param.data = meta_param * 2

                meta_objective = - (param * 2)
                meta_objective.mean().backward()

I’m trying to get the gradient of meta_param wrt meta_objective, but it has to pass through a nn.Parameter update for param. If param was a regular tensor as so:
                meta_param = torch.tensor(5.0,requires_grad=True) # this is the variable i want to learn
                param = meta_param * 2

                meta_objective = - (param * 2)
                meta_objective.mean().backward()

meta_param.grad has a sensible value. But when param is an nn.Parameter, meta_param.grad is None.
When assigning the new value to the nn.Parameter, i notice it has no .grad_fn method, and it is a leaf_tensor=True for it.
This is true for all model weights i want to update. Is there a way to make an nn.Module’s weights differentiable? Perhaps making a temporary model and make its weights views of non-leaf tensors?
How do I work around this?