Solved by ptrblck in post #2 
              
              
                Your approach would calculate the gradients of the used model parameters w.r.t. the “lowest loss”, i.e. sort_losses[0]. 
Note however, that all computation graphs (with all intermediate activations) will be stored during the execution of the loop, which will of course increase the memory usage. 
Als…