Solved by colesbury in post #2 
              
              
                The memory is from the output out1 and intermediate activations needed to compute the gradient. The first increase is from computing out1. The second increase is from computing net(data1) while out1 is still alive. The reason is that in: 
out1 = net(data1)

The right-hand side net(data1) is evaluate…