Unable to free the intermediate values in the graph.
coreqode opened this issue · comments
Chandradeep Pokhariya commented
Hey, I was integrating Fast-Snarf with another project. However, I am not able to free up the gradients even though I am detaching the tensors of broyden cuda. Are you familiar with this error?
RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.
Chandradeep Pokhariya commented
Wrapping the calculation of the gradients under torch.no_grad()
solved the issue