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
{{ message }}
Repository navigation
Normalize the in-loss survivor denominator once instead of rescaling gradients by G/K #4242
With loss_fn.seq_logprob_error_in_loss (#4171), each microbatch normalizes by the unfiltered global token count G, because the survivor count K is not known until every microbatch has run. The worker then multiplies gradients by G/K before optimizer.step():
Have the loss emit raw sums and divide by K once after the reduction. Same result, without threading global_valid_toks into the loss as a placeholder and without a second rescale pass (rescale_loss_metrics) that has to stay in sync with the gradient one.
What it needs
Convergence runs, not just an algebraic argument. The two forms are equal on paper, but dropping the per-microbatch division changes what the optimizer sees along the way, so the dynamics have to be compared end to end.
The current shape also buys a cross-check worth giving up deliberately: both paths divide by global_valid_toks, so in-loss can be diff-tested against separate-forward by swapping a single input. If the separate-forward path is retired, that argument goes away on its own.
Scope
Loss: emit unnormalized sums where global_normalization_factor is used today.
Worker: divide by the reduced survivor counts once, after the DP all-reduce and PP broadcast; drop the G/K rescale and its rescale_loss_metrics pair.
Keep the empty-survivor guard at megatron_policy_worker.py:1020.
Activity