It’s probably because you’re caching a lot of intermediate results (e.g. output_all, h, c, loss_tot, etc.) and they prevent the graph from being freed. Also, if you want to run in inference mode only use volatile=True.