Hello. I am not sure why my code produces the error. I dont think that I should use the retain_graph=True feature but I am not sure how else to fix my problem.
cbdb16f09e85bea9993e0f0351f22841.png825×287 13 KB
   It works good the first time but for some reason it tries to go to the old graph even though I calculate all tensors from the loss function new. I would assume that the problem is because of the Trajectory object (net_outcome_values and net_probs have required_grad=True), but I am not sure how to fix it. Any help is greatly appreciated!
Error: 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.