Skip to content

Cross entropy: 8192-wide chunks at 4 warps for the chunked forward on sm120 - #15744

Merged
danielhanchen merged 5 commits into
mainfrom
ce-sm120-config
Oct 28, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
ce-sm120-config

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Adds an sm120 (RTX PRO 6000, RTX 5090) entry to _CHUNKED_FORWARD_CONFIGS in unsloth/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.

_CHUNKED_FORWARD_CONFIGS = {
    (7, 5): (16384, 8, None),
    (8, 0): (16384, 8, 163840),
    (10, 0): (8192, 4, None),
    (12, 0): (8192, 4, None),
}

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-quant lm_head, and through the patched HF ForCausalLMLoss. 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_bench median 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.

torch 2.10 torch 2.14
chunked forward kernel, bf16 1.09x to 1.18x 1.13x to 1.39x
chunked forward kernel, fp16 1.11x to 1.26x 1.15x to 1.41x
loss forward + backward, bf16 1.03x to 1.06x 1.04x to 1.13x
loss forward + backward, fp16 1.03x to 1.08x 1.05x to 1.14x

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_entropy in 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 tolerance test_loss_and_grads_match_across_chunk_widths already 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).

model base ms / step head ms / step A/A spread
Qwen3-0.6B 81.19 / 78.36 79.63 / 79.76 3.5% / 0.2%
Llama-3.2-1B-Instruct 86.46 / 85.46 86.08 / 85.45 1.2% / 0.7%

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.py is 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.py gets the sm120 route, and its "other archs" case now uses (12, 1).
  • CE tests on an RTX PRO 6000 (10 files): 249 passed with this change. On main, 12 fail, and all 12 are the new sm120 pins.

@danielhanchen danielhanchen self-assigned this Oct 28, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T11:27:50.287028Z caa9bd6 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: caa9bd69c3

ℹ️ 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 fa96c94 into main Oct 28, 2026
3 of 34 checks passed
@danielhanchen
danielhanchen deleted the ce-sm120-config branch October 28, 2026 15:32
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