liveBook · Manning

AdamW

As explained in Build a Text-to-Image Generator (from Scratch)

AdamW is an adaptive gradient-based optimizer that decouples weight decay from the parameter update.

AdamW is an adaptive gradient-based optimizer and a variant of Adam. It updates model parameters to reduce training error while applying weight decay directly to the parameters after optimization, rather than directly to gradients. section 3.4.1 section 3.1.2

A typical training step connects AdamW to the surrounding optimization process:

  • Run a forward pass to produce predictions, compare them with targets through a loss function, and backpropagate the gradients. section 3.1.2
  • Call AdamW to update the network weights in the direction that reduces the error. section 3.1.2
  • Apply weight decay separately to the parameters, helping prevent the decay rate from adapting with the learning rates. section 3.4.1

PyTorch configurations

A ViT classifier uses AdamW with a learning rate of 0.01 and weight decay of 1e-2. A diffusion denoising U-Net uses learning rate 0.0001, betas of (0.95, 0.999), weight decay of 0.00001, and eps of 1e-8. section 3.4.1 section 7.3.2

from diffusers.optimization import get_scheduler

optimizer=torch.optim.AdamW(model.parameters(),lr=0.0001,
    betas=(0.95,0.999),weight_decay=0.00001,eps=1e-8)    #1
lr_scheduler=get_scheduler(    #2
    "cosine",
    optimizer=optimizer,
    num_warmup_steps=300,
    num_training_steps=(len(train_dataloader) * 100))

Inspect a complete AdamW configuration alongside a cosine learning-rate scheduler with warmup for diffusion training. section 7.3.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Defines decoupled weight decay and demonstrates configurations, but stops short of deriving AdamW’s update equations.
Examples
Uses PyTorch configurations for CIFAR-10 ViT classification and diffusion-based denoising U-Net training.
What it assumes
Assumes familiarity with model weights, loss functions, gradients, backpropagation, and iterative training.
What you can do after
Apply it via PyTorch to optimize neural networks with configurable learning rates, weight decay, and optimizer parameters.
How it connects
Connects Adam to weight decay, learning rate, backpropagation, loss functions, and learning rate schedulers.

Also explained in

Compare how 3 books explain AdamW →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.