Summary
Z-loss adds a term proportional to to the cross-entropy objective, where is the softmax partition function over the vocabulary and are the pre-softmax logits.
A typical coefficient is . The term encourages to stay near zero, anchoring the common offset that cross-entropy leaves unconstrained. It does not bound every logit difference.
Two reasons, in order of how often they come up:
- Stability. Without z-loss, large LLM training runs occasionally see the
lm_headlogits drift to very large magnitudes, which can cause numerical issues in the softmax (especially in BF16 or FP8). PaLM and DeepSeek both used z-loss for this. - A controlled cooldown intervention. The Marin 8B retrospective reports a successful intervention in its recipe. Excluding normalization parameters from weight decay is an implementation choice, not proof that no other control exists. Z-loss anchors the common-offset direction; it does not bound every parameter norm or logit difference.
The mechanism
The cross-entropy loss for a single token with target is:
Note that is invariant to adding a constant to all logits (because shifts by the same amount that does). That invariance means cross-entropy alone provides no gradient pressure on the common offset of the logits. The model can drift the entire logit vector up or down without changing the loss.
Learning objective
A shared logit shift leaves probabilities unchanged but changes z-loss
Derivation
SAME PREDICTION, FREE OFFSET
Logits: [0, 1]
Probabilities: [0.269, 0.731]
Target CE: 0.313
log Z: log(1 + e) = 1.313
SHIFT BOTH BY -1.313
Logits: [-1.313, -0.313]
Probabilities: [0.269, 0.731]
Target CE: 0.313
log Z: 0, so z-loss is 0
Which quantity changes even when every softmax probability stays fixed?
Adding breaks the invariance. The gradient with respect to a logit becomes:
The second term pulls toward zero, anchoring the otherwise free common offset. The pressure is small per-step but persistent.
When to use it
Consider a measured ablation when diagnostics indicate a relevant failure mode:
- Track log-partition values, logit differences, finite-value failures, and held-out task behavior rather than choosing from model size alone.
- Treat Marin’s cooldown result and coefficient as a source-specific example to reproduce or test, not a universal prescription.
- Compare the actual low-precision implementation and a recoverable control run before attributing an instability to the common-offset direction.
Short fine-tuning and large pretraining both need a workload-specific decision; neither label settles whether the extra objective helps.
How to set the coefficient
A coefficient such as is a starting point for an ablation, not a scale-free guarantee of a small penalty. For that coefficient, contributes 0.0004, while contributes one. State token/batch reduction and log base: natural-log cross-entropy is measured in nats, not bits. The cross-entropy lesson separates the probability objective from added regularizers.
If you set much larger, the model spends capacity matching instead of fitting the data and downstream perplexity worsens. If you set it much smaller, you lose the regularization effect.
Subtle effects worth knowing
Subsequent Marin experiments showed that z-loss doesn’t just prevent logit blowup. In the steady state, z-loss increases the weight norm of the lm_head and decreases the scale of the final layer norm. This makes sense in retrospect: the final layer norm has a disproportionate impact on logit scale (one parameter affecting all logits), and it’s the only player not constrained by weight decay. Z-loss redistributes the pressure.
What an interviewer expects you to say
If asked about z-loss:
- State that it’s a penalty on added to cross-entropy.
- Explain that cross-entropy is invariant to adding a constant to all logits, so it provides no gradient on absolute logit scale. Z-loss breaks that invariance.
- Mention both use cases: stability against logit blowup and regularization on logit scale during deep cooldowns.
- Inspect the actual decay groups and precision policy; explain why a source-specific intervention is not a bound on every logit or parameter.
Further reading
- Marin 8B retrospective (Spoonbill section, where z-loss was diagnosed).
- Marin z-loss ablation experiment GH#935 and the WandB report.
- PaLM paper, Section 5.1 (the original published use of z-loss in a frontier LLM).