chore(claude): learn from #374#375
Merged
Merged
Conversation
Add rule 5 bullet on gathering row-aligned per-sample tensors in a single gather_for_metrics dict call to survive ragged last-batch de-pad. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
Author
|
[claude-review] summary for commit 03feecb No blocking issues found. Re-verified after the refine/broaden commit. The new rule-5 bullet matches the code it cites: |
shuheng-liu
approved these changes
Jun 2, 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.
What this does
Captures a lesson from the review of #374 (per-(dataset, control_mode) validation aggregation) under rule 5 in
CLAUDE.md, and broadens that rule so the new bullet sits honestly.The reviewer flagged — and the author fixed in commit
8559365— that gathering per-sample losses and their provenance indices in separategather_for_metricscalls is fragile.accelerate.gather_for_metricsde-pads the ragged final batch by trimming the gathered result togradient_state.remainder; a tensor and a non-tensor (e.g.dataset_repo_idstrings, which take thegather_objectpath) trim differently, so provenance can desync from the loss rows. The fix gathers everything as int tensors in onegather_for_metrics({...})dict call, so a single trim applies to every entry and rows stay aligned by construction. This is a non-obvious distributed correctness gotcha — silent wrong per-dataset metrics, not a hang — that the CPU suite can't catch (the multi-rank de-pad path only fires on >1-rank hardware).Two refinements over the original lesson draft:
📝 Documentation
How it was tested
Documentation-only change to
CLAUDE.md. Markdown-relevant pre-commit hooks pass (trailing-whitespace,end-of-file-fixer,typos). No code touched; nothing to run.How to checkout & try? (for the reviewer)
Checklist
Note: Before submitting this PR, please read the contributor guideline.