Repository navigation
Log GRPO loss-path metrics once per optimizer window - #7053
Closed
behroozazarkhalili wants to merge 3 commits into
Closed
behroozazarkhalili wants to merge 3 commits into
behroozazarkhalili wants to merge 3 commits into
Conversation
_compute_loss appended entropy, kl, policy_loss and aux_loss to self._metrics once per micro-batch and log() took a flat mean over the entries of the logging interval. transformers shortens the last accumulation window of an epoch to the remainder, so an interval that mixes window sizes weighted each window by its micro-batch count: with gradient_accumulation_steps=3 over four micro-batches policy_loss logged -0.000557 where the mean over the two optimizer windows is -0.001114. In train mode each metric's micro-batch contribution is now divided by the current window size and accumulated, and the window value is appended once when the accelerator syncs gradients, so the entry count equals the optimizer-step count and log()'s mean is exact. Equal windows log the same numbers as before. Evaluation has no accumulation and keeps appending per batch. train() clears the window accumulator on entry so a run interrupted inside a window cannot leak into the next call. The training loss and gradients are unchanged. The GMPO and GSPO-token copies of the block are updated identically; MiniLLM and the replay-buffer trainer inherit the method. The regression test drives two windows of sizes 3 and 1 through _compute_loss and asserts one entry per window with the per-window mean; the equal-window case asserts the old and new values coincide. On the previous code the uneven case logs -1.75 for an expected -2.5. Fixes #7047.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Collaborator
Author
|
Closing this one myself. It came from reading the code, not from a failure in a real training run, and per the discussion on #6862 that isn't the bar for this repo. If someone hits this in practice, the branch is still here and I'm happy to reopen it with a reproduction. |
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.
GRPO gave longer gradient accumulation windows more weight when averaging loss metrics. I changed GRPO and its GMPO and GSPO-token copies to record one value per optimizer window, and tests for equal and uneven windows pass. This overlaps #7042 on the same lines and will need a small conflict resolution.
Fixes #7047.
Note
Low Risk
Changes only how training metrics are aggregated for logging; optimization math is explicitly unchanged. Clip-ratio and other per-micro-batch diagnostics are untouched.
Overview
Fixes incorrect logged
policy_loss,entropy,kl, andaux_losswhen gradient accumulation uses uneven windows (e.g. a shortened last window), while leaving the actual training loss and gradients unchanged.In train mode, micro-batch metric values are now scaled by
1 / current_gradient_accumulation_steps, summed in_loss_window_metrics, and appended to_metricsonly whenaccelerator.sync_gradientsis true—solog()’s mean is one value per optimizer step with equal weight per window. Eval still logs per batch.train()clears the accumulator at the start to avoid stale partial sums after an interrupted run. The same logging block is applied in the GMPO and GSPO-token GRPO trainer copies.Adds
test_policy_loss_is_averaged_over_accumulation_windowsto assert window-weighted averaging vs the old flat micro-batch mean.Reviewed by Cursor Bugbot for commit 0c3d4dc. Bugbot is set up for automated code reviews on this repo. Configure here.