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.
Also, if you are using e.g. batchnorm layers, their running stats will be updated in each forward pass, which might not fit your use case.