torchmin.Minimizer.step

Minimizer.step(closure)[source]

Perform an optimization step.

The function “closure” should have a slightly different form vs. the PyTorch standard: namely, it should not include any backward() calls. Backward steps will be performed internally by the optimizer.

>>> def closure():
>>>    optimizer.zero_grad()
>>>    output = model(input)
>>>    loss = loss_fn(output, target)
>>>    # loss.backward() <-- skip this step!
>>>    return loss
Parameters

closure (callable) – A function that re-evaluates the model and returns the loss.