There might be something calculate globally, and when you .backward() first time, it breaks the computation graph, and the second time you call .backward(), it still need the ‘global’ variable to compute gradient, but it has beed freed (as the error raised). So checking your code, whether there are some variables in computation graph globally.