Skip to content

fix: surface NaN GRPO/RLOO steps in log_history - #6772

Open
tonycoder-hub wants to merge 2 commits into
huggingface:mainfrom
tonycoder-hub:cursor/grpo-surface-nan-loss-steps-ecdb
Open

fix: surface NaN GRPO/RLOO steps in log_history#6772
tonycoder-hub wants to merge 2 commits into
huggingface:mainfrom
tonycoder-hub:cursor/grpo-surface-nan-loss-steps-ecdb

Conversation

@tonycoder-hub

@tonycoder-hub tonycoder-hub commented Aug 17, 2026

Copy link
Copy Markdown

What does this PR do?

Trainer logging_nan_inf_filter replaces a NaN loss with the previous average, so a corrupted GRPO step looks clean in log_history. This logs frac_non_finite_loss on GRPO and RLOO so a non-finite step is visible.

Fixes #6702

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that is the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link to it if that is the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

AI writing disclosure

  • No AI usage: the PR was written entirely by a human.
  • AI-assisted: some parts were suggested or improved by AI, but the PR was written and reviewed by a human.
  • AI-generated: the PR was mostly or fully generated by an AI tool.

Who can review?

Anyone in the community is free to review the PR once the tests have passed.

GRPO tests: 157 passed. RLOO tests: 70 passed.


Note

Low Risk
Small observability-only change in compute_loss with no change to loss computation or optimization logic; low risk aside from minor distributed logging overhead.

Overview
GRPO and RLOO now record frac_non_finite_loss in training/eval metrics so corrupted steps are visible in log_history even when Hugging Face Trainer’s default logging_nan_inf_filter replaces NaN/Inf losses with a smoothed finite value in the reported loss.

Each compute_loss call flags non-finite losses (gathered across processes), appends to the existing metrics pipeline, and still returns the raw loss for backward. GRPO covers both the standard and Liger-kernel paths.

Docs for GRPO and RLOO logged metrics describe the new field; regression tests poison the first step with NaN and assert frac_non_finite_loss > 0 on that step only while loss stays finite (fixes #6702).

Reviewed by Cursor Bugbot for commit 4972662. Bugbot is set up for automated code reviews on this repo. Configure here.

cursoragent and others added 2 commits August 17, 2026 08:28
A step whose loss is NaN or Inf is still backpropagated, but `Trainer` replaces it in the reported
running loss with the average of the previously logged losses (`logging_nan_inf_filter`, enabled by
default). A run that is corrupting its weights therefore reports a clean loss curve, in
`log_history` and in any tracker fed from it.

Record whether each forward pass produced a finite loss and log the fraction as
`frac_non_finite_loss`, so the filtered step leaves a trace. RLOO carries the same change, since it
shares the metric machinery and the same silent behavior.

Co-authored-by: Tony Coder <407243179@qq.com>
Co-authored-by: Tony Coder <407243179@qq.com>
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.

GRPO: a NaN training step is invisible in log_history, so a corrupted run reports a clean loss curve

2 participants