perf(grpo): batch rollout diagnostic metric gathering - #10082
Open
taking-lying-flat wants to merge 1 commit into
Open
perf(grpo): batch rollout diagnostic metric gathering#10082taking-lying-flat wants to merge 1 commit into
taking-lying-flat wants to merge 1 commit into
Conversation
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.
PR type
PR information
When rollout log probabilities and IS correction are enabled, HF GRPO performs 13 individual
gather_for_metrics()calls for off-policy diagnostics and three for IS diagnostics in each micro-batch. Each call is followed by a scalar read. These operations execute in the loss path rather than only when logging.Keep the local diagnostic values as tensors and gather the combined metrics once per micro-batch. Preserve each metric's existing cross-rank
nanmean,max, orminreduction. Packing one row per rank also preserves Accelerate's dataloader remainder slicing.Retain the reduced tensors until
log(), then copy them together and compute the logging-period means in CPU double precision, matching the range of the previous Python-float aggregation. Importance-sampling weights and their update frequency are unchanged.This PR changes only
swift/rlhf_trainers/grpo_trainer.py: 34 insertions and 23 deletions. Megatron and other diagnostic metrics are outside this change.Experiment results
gather_for_metrics()with IS correction.item()readsFor 16 micro-batches, these diagnostic gathers decrease from 256 to 16. This is an operation-count reduction, not an end-to-end throughput measurement.
39 local two-rank Gloo comparisons of the production metric, loss, and logging methods passed. Coverage includes all four IS modes, diagnostics without correction, uneven local batch sizes, empty masks, NaNs, extrema, dataloader remainder trimming, train/eval logging, and low-precision/large-value logging means. Loss and gradients matched exactly; metric and logging values matched within floating-point tolerance. CPU profiling confirmed no
aten::itemoperations in the updated diagnostic path.All applicable pre-commit checks passed. Validation scripts remain outside the repository; this PR contains production code only.