Dear @albanD thank you for your reply. 
Does the total_loss will still be accurate for optimizer that require a closure?
I didn’t really understand why a closure is necessary for certain optimizer
but from my current understanding the optimizer will run the closure multiple times each step.
Does the total_loss will still be a valid way to stop training in that case?
Thank you so much