‘function’ is a callable that returns a differentiable loss (i.e. main nn.Module with attached loss function), these algorithms have an [inner] training loop inside optimizer.step, hence this ‘closure’ is mostly a boilerplate to have a loop turned inside out (i.e. a delegate allowing nested forward+backward+change_params iterations)