Hi,
This error happens because we try to reduce memory usage and so free all the temporary buffer when you do a backward pass (because in most cases you only do one).
If you plan on doing more than on (using backward or grad), all but the last one should be called with retain_graph=True.