Hi! The following code:
import torch
h_ = torch.nn.Parameter(torch.ones([1,1]))
h = h_**2
optimizer = torch.optim.SGD([h_], lr=0.1)

for _ in range(2):
  optimizer.zero_grad()
  loss = h.sum()
  loss.backward()
  optimizer.step()

throws a
RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.
Can anyone tell me whats the issue? Thanks!