Repository navigation
Cross entropy: 8192-wide chunks at 4 warps for the chunked forward on sm120 - #15744
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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.
Summary
Adds an sm120 (RTX PRO 6000, RTX 5090) entry to
_CHUNKED_FORWARD_CONFIGSinunsloth/kernels/cross_entropy_loss.py. sm120 now uses 8192-wide chunks at 4 warps for the chunked cross entropy forward, the same entry B200 got in #15141. Before this change, sm120 used the default single 65536-wide chunk at 32 warps.Only the
(12, 0)key is new. Every other compute capability, including sm121, routes exactly as before. The backward kernel is unchanged.Where this kernel runs
This kernel only runs when logits are materialised: with
UNSLOTH_RETURN_LOGITS=1, with an NVFP4 / MX fake-quantlm_head, and through the patched HFForCausalLMLoss. Default text SFT goes through the fused linear CE in unsloth-zoo and GRPO uses its own logprob path, so neither is affected.Kernel results (RTX PRO 6000, sm120)
Setup: 6 arms, 3 interleaved rounds, a fresh process per arm,
do_benchmedian with L2 flushed. The matrix was vocab 128256 / 151936 / 262144 x rows 2048 / 4096 / 8192 / 16384, bf16 and fp16, on torch 2.10.0 (Triton 3.6) and torch 2.14.1 (Triton 3.8). Main vs a repeat of main (A/A) stayed within 0.3% in every cell.The 16384 / 8, 32768 / 8 and 32768 / 16 configs all landed within 0.5% of 8192 / 4. No cell got slower. A 32000 vocab uses the single-block kernel and does not change (1.000x). I also swept the backward block size and warps: the best alternative was 1.6% faster on geomean, so I left the backward as is.
Accuracy
The result matches an fp64 reference (
F.cross_entropyin float64) as closely as before. Loss error is 2e-7 to 1.7e-6 for both configs. The max grad error is the same for both: 6e-6 in bf16, 3e-7 to 9e-7 in fp16. The output is not bitwise identical, because the per-chunk logsumexp values combine in a different order. The difference is well inside the tolerancetest_loss_and_grads_match_across_chunk_widthsalready uses for(8192, 4).End to end (RTX PRO 6000, torch 2.14.1,
UNSLOTH_RETURN_LOGITS=1, 30 LoRA steps)Arms ran in the order base, head, head, base. All 30 steps in every run went through the chunked kernel, with base at (65536, 32) and head at (8192, 4).
The end-to-end change is within noise. At about 3K tokens per step, the loss is about 1.5 ms of an 80 ms step, so most of the gain shows up on large token counts with logits returned. Per-step loss matches base within the same spread as two base runs.
Tests
tests/test_cross_entropy_sm120_chunk_config.pyis new and runs on CPU with a mocked capability. It pins (8192, 4) for sm120 across vocabs and checks that sm121, sm110, sm90 and sm89 keep the previous config. On main it fails 7 of 11.tests/test_cross_entropy_chunk_config.pygets the sm120 route, and its "other archs" case now uses(12, 1).