liveBook · Manning

Optimizer state

As explained in Deep Learning with PyTorch, Second Edition

The internal state of an optimization algorithm, such as momentum buffers, that can be saved to resume training exactly.

Optimizer state is information an optimizer keeps while training. It is distinct from a model’s weights and biases. The PyTorch examples show how an optimizer receives parameters and updates them, but do not inspect its internal state or show how to save it. section 6.2.2

An optimizer in a training loop

For a linear model, create `optimizer = optim.SGD(linear_model.parameters(), lr=1e-2)`. Each training iteration calls `optimizer.zero_grad()`, computes a loss, calls `loss.backward()`, then calls `optimizer.step()`. Backward fills the parameters’ `grad` attributes; `step()` uses those gradients to change the parameters. The example does not expose any separate optimizer state. section 6.2.2

A model with multiple linear layers follows the same pattern: `model.parameters()` supplies their weights and biases to the optimizer. AdamW and SGD are also suggested for comparison during segmentation training, but no procedure for saving or restoring either optimizer is shown. section 6.3.2 section 15.10

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Shows SGD construction and parameter updates, but does not inspect internal optimizer state or demonstrate saving and restoration.
Examples
Uses a thermometer-data linear model and a multi-layer model; proposes comparing SGD and AdamW on segmentation training.
What it assumes
Introduces module parameters and their gradients in context, without assuming knowledge of optimizer internals.
What you can do after
Evaluate/understand how SGD receives parameters and updates them after backpropagation, without inferring a checkpoint procedure.
How it connects
Connects optimizers to model parameters, gradients, backpropagation, SGD, and AdamW.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.