Repository navigation
Conversation
Afloat16
requested review from
andyland,
k223kim,
lianakoleva and
t-vi
as code owners
November 12, 2026 20:31
This branch has not been deployed
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.
Fixes #2411.
Problem
Both chunked cross-entropy branches sum token losses in the original dtype before dividing by the valid-target count. With direct float16 inputs, the sum can exceed 65504 even when every token loss and the correct mean are small and finite. A 4 x 4096-token, 128-class uniform example returns
infinstead of approximately 4.852. This also affects an actual half-precision GPT training loss.Change
Use at least float32 for the scalar sum and normalization, then convert the mean back to the original loss dtype. Preserve float64 accumulation, the existing chunk construction, masking, valid-target count and result dtype. This adds no full-size float32 copy of the per-token losses.
Validation
Base:
5341568a65e918a85cb284fac038de2157eebf3f.git diff --checkpassed.Linux, Python 3.12, PyTorch 2.15.0+cpu. These are direct half-precision inputs; this does not claim the same overflow for autocast paths that already return float32 CE outputs. No downloaded model, numerical mocks, GPU/distributed run or full repository suite. Prettier and pyproject-only hooks were skipped because neither changed file uses those formats; applicable Python hooks passed.
The native issue was opened before implementation. Checked current/legacy source history, all-state chunked-loss/overflow/dtype/precision searches and all nine existing fork heads. #751 adds valid-target normalization, #1374 removes synchronization, #2312 changes chunk-size budgeting and #2347 adds accumulation-window normalization; none widens this sum. #2398 fixes a different unchunked all-ignored-target path.