liveBook · Manning

Loss scaling

As explained in Deep Learning with R, Third Edition

Loss scaling is the technique of multiplying a training loss by a scalar factor to increase the magnitude of gradients during numerical computation.

Loss scaling multiplies a training loss by a scalar so gradients become large enough to survive limited numerical precision. Mixed-precision training commonly uses it because float16 gradients may round to zero. section 18.3.4

Use loss scaling in two practical ways:

  • Set a fixed factor with an optimizer's loss_scale_factor argument. section 18.3.4
  • Wrap the optimizer in LossScaleOptimizer to adjust the scaling automatically as training changes. section 18.3.4
  • In YOLO, scale box-placement errors by 5 and empty-cell confidence errors by 0.5 so important signals are not drowned out. section 12.2.4

Automatic mixed-precision scaling

optimizer <- optimizer_adam(learning_rate = 1e-3) |> optimizer_loss_scale()

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains the numerical motivation and optimizer choices, then applies fixed factors to YOLO loss components without deriving scaling internals.
Examples
Uses Keras optimizer configurations and YOLO factors of 5 for box errors and 0.5 for empty-cell confidence errors.
What it assumes
Assumes familiarity with training loss, gradients, optimizers, and mixed-precision computation.
What you can do after
Configure loss scaling through a fixed optimizer factor or an automatic LossScaleOptimizer wrapper.
How it connects
Connects loss scaling with mixed precision, gradients, optimizers, and object-detection loss functions.

Also explained in

Compare how 2 books explain loss scaling →

Related concepts

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