Fix double loss normalization in server policy_loss/importance_sampling#13
Merged
Merged
Conversation
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.
zzz0906
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Server forward/backward uses deferred loss normalization: each micro-batch returns a raw summed loss, and
optim_stepdivides the accumulated gradient once by total valid tokens.The
policy_lossandimportance_samplingcall sites inmodel_runner.pyomittedloss_reducer, so the loss defaulted toTokenPartial(scale=valid_count)— a local per-micro-batch token-mean. That mean was divided again by total tokens atoptim_step, normalizing the gradient twice.grad_normcollapses toward zero and the model fails to learn — at any batch size, since both divisors scale with the batch.causallm_lossandopd_lossalready passloss_reducer=token_sum_reducer; only the two RL paths were missing it.Fix
Pass
loss_reducer=token_sum_reducerto both calls so they return raw summed losses, matching the other loss functions.