Skip to content

Fix double loss normalization in server policy_loss/importance_sampling#13

Merged
zzz0906 merged 1 commit into
mainfrom
fix/server-rl-loss-double-normalization
Jun 17, 2026
Merged

Fix double loss normalization in server policy_loss/importance_sampling#13
zzz0906 merged 1 commit into
mainfrom
fix/server-rl-loss-double-normalization

Conversation

@kiddyboots216

Copy link
Copy Markdown
Contributor

Problem

Server forward/backward uses deferred loss normalization: each micro-batch returns a raw summed loss, and optim_step divides the accumulated gradient once by total valid tokens.

The policy_loss and importance_sampling call sites in model_runner.py omitted loss_reducer, so the loss defaulted to TokenPartial(scale=valid_count) — a local per-micro-batch token-mean. That mean was divided again by total tokens at optim_step, normalizing the gradient twice. grad_norm collapses toward zero and the model fails to learn — at any batch size, since both divisors scale with the batch.

causallm_loss and opd_loss already pass loss_reducer=token_sum_reducer; only the two RL paths were missing it.

Fix

Pass loss_reducer=token_sum_reducer to both calls so they return raw summed losses, matching the other loss functions.

Server forward/backward defers loss normalization: each micro-batch returns
a raw summed loss and optim_step divides the accumulated gradient once by
total valid tokens. The policy_loss and importance_sampling calls omitted
loss_reducer, so the loss defaulted to a local per-micro-batch token-mean
and was normalized twice -> grad_norm collapses and the model fails to learn
at any batch size.

Pass loss_reducer=token_sum_reducer to both calls, matching causallm_loss
and opd_loss.
@kiddyboots216 kiddyboots216 requested a review from zzz0906 June 17, 2026 08:32
@zzz0906 zzz0906 merged commit 577f34d into main Jun 17, 2026
2 checks passed
@kiddyboots216 kiddyboots216 deleted the fix/server-rl-loss-double-normalization branch June 24, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants