You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(trainer): MoE loss-free load balancing and block dropout
Add training-time MoE load balancing and per-block dropout to the custom
model implementation.
MoE load balancing via [model.moe_load_balance] (mode/coeff), off by default.
mode='loss_free' applies the DeepSeek auxiliary-loss-free bias update
(arXiv:2408.15664) once per optimizer step: expert_bias += coeff * sign(load
error), from a per-step usage accumulator, with the delta recentered to zero
mean (matches torchtitan) so the bias vector doesn't drift a global offset.
Expert usage is aggregated across the dp_cp group so balancing targets the
whole global batch. Default coeff 1e-3. Before this, prime-rl only allocated
the expert_bias buffer (loaded from checkpoints and frozen) with no update.
model.dropout applies dropout at each block's output before the residual add
(attention + FFN/MoE), intended for SFT/self-distillation (e.g. 0.15);
default 0.0 so RL is unaffected. SFT validation switches the model to eval
mode when dropout is active so val/loss stays deterministic (skipped when
dropout is off to avoid torch.compile recompilation).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@@ -50,6 +52,22 @@ DeepEP requires some careful tuning to achieve optimal performance, tuning param
50
52
51
53
With DeepEP, gradient clipping is currently not supported. (`optim.max_norm` is set to `None` automatically.)
52
54
55
+
### MoE Load Balancing
56
+
57
+
Custom MoE models can rebalance expert usage during training via `[model.moe_load_balance]`. This is off by default (a pretrained router bias, if present, is still used for routing).
58
+
59
+
```toml
60
+
[model.moe_load_balance]
61
+
mode = "loss_free"# "off" (default) | "loss_free"
62
+
coeff = 1e-3# bias update step size
63
+
```
64
+
65
+
**`loss_free`** applies the DeepSeek auxiliary-loss-free update ([arXiv:2408.15664](https://arxiv.org/abs/2408.15664)): each optimizer step it nudges the router `expert_bias` toward balanced usage by `coeff · sign(load_error)` (the delta is recentered to zero mean so the bias vector doesn't drift a global offset), with no extra loss term. Expert token counts are summed across the data-parallel (`dp_cp`) group so balancing targets the whole global batch rather than each rank's shard.
66
+
67
+
### Block Dropout
68
+
69
+
`model.dropout` (default `0.0`) applies dropout at each block's output before the residual add — attention block and FFN/MoE block. It is intended for SFT/self-distillation (e.g. `0.15`); leave it at `0.0` for RL. Requires the custom model implementation.
Copy file name to clipboardExpand all lines: packages/prime-rl-configs/src/prime_rl/configs/trainer.py
+21Lines changed: 21 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -116,10 +116,31 @@ class DebugModelConfig(BaseConfig):
116
116
"""Replace MoE token-choice routing with a round-robin assignment so every expert sees an equal share. Intended for fake-data smoke tests where untrained routing would otherwise OOM under severe imbalance. Gating scores are still gathered from the override indices so the forward pass stays consistent."""
117
117
118
118
119
+
classMoELoadBalanceConfig(BaseConfig):
120
+
"""Training-time MoE load balancing (only affects the custom MoE implementation).
is aggregated across the data-parallel group so balancing targets the whole global batch rather
124
+
than each rank's local shard.
125
+
"""
126
+
127
+
mode: Literal["off", "loss_free"] ="off"
128
+
"""``off`` disables training-time balancing (a pretrained ``expert_bias`` is still used for routing if present). ``loss_free`` updates the router ``expert_bias`` each optimizer step from expert usage."""
"""Dropout applied at each block's output before the residual add (attention block and FFN/MoE block). Intended for SFT/self-distillation (e.g. 0.15); leave at 0 for RL. Requires the custom model implementation."""
0 commit comments