Skip to content

GRPO subclass test: compare rollout and gradient-pass scores within 1e-12, not bit for bit - #18939

Merged
danielhanchen merged 1 commit into
mainfrom
fix/grpo-subclass-scores-close
Nov 22, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/grpo-subclass-scores-close

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

tests/test_grpo_subclass_compute_loss.py::test_rollout_scores_feed_the_subclass_objective[logits_route-*], added by #18851, failed in the Repo tests (CPU, rest) shard of a staging run on main d10f9d6:

tests/test_grpo_subclass_compute_loss.py:521: in test_rollout_scores_feed_the_subclass_objective
    assert torch.equal(current[cm], scored[cm])
E   assert False

The two tensors in the failure print identical to four decimal places. The test scores the rollout with batch_size = 2, then scores the same weights again in a single batch, and asserts the two are bit for bit equal. On the logits route those are float64 matmuls of different shapes, and on some CPUs they can differ in the last bit. The code under test is fine. The assertion asks for more than the contract does: the scores have to match, not come from identically shaped kernels.

Fix

torch.equal becomes torch.testing.assert_close(..., rtol = 0, atol = 1e-12):

The following abs(loss - want) < 1e-12 check is unchanged.

Testing

  • tests/test_grpo_subclass_compute_loss.py with TRL 1.18.2, transformers 5.18.0, torch 2.10 CPU and zoo main: 29 passed, 1 skipped.
  • Sabotage, shifting the rollout scores before the comparison:
    • By 1e-9: both float64 logits-route cases fail ("Greatest absolute difference: 1.0e-09 (up to 1e-12 allowed)"). On the float32 fused route, 1e-9 rounds away, so it is not a real change there.
    • By 1e-4: all four cases fail.
  • I could not reproduce the last-bit difference on this host (AVX2, AVX-512 and default ATen kernels, 1 and 4 threads all pass), so the CI log above is the only evidence of it.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T19:17:00.941089Z 095fab5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 095fab549e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 03664ed into main Nov 22, 2026
@danielhanchen
danielhanchen deleted the fix/grpo-subclass-scores-close branch November 22, 2026 19:18
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.

1 participant