Hi folks! I ran into the following issue. I was wondering if someone could help me out.
I have a loss l(w,theta), where w is weights and theta is network parameters. I need to first calculate theta.hat using S.G.D. as follows.
theta.hat = theta - alpha * grad l(w,theta).

Then, I need to use the updated theta.hat in the same network and calculate another loss L(theta.hat). As theta.hat is a function of w, so is L. My question is, how can I get the gradient of L with respect to w?
All my attempts had the following error: One of the differentiated Tensors appears to not have been used in the graph. So I guess w was not really in my graph.
For example, I tried using optimizer.step(), but after that, theta.hat got the updated values, but w was lost from the graph. In other words, optimizer.step() was sort of like with torch.no_grad(), whereas I would like something that kept the graph that traced back to w.
Thanks for your help!