The NanoGPT Record
Modded-NanoGPT Track-1 Short in 29.46 seconds on 8×H100 (PR #416)
December 2026 · PR #416 on KellerJordan/modded-nanogpt → · Standalone repo & ablations (MIT) →
In Modded-NanoGPT Track-1 Short, the goal is to train a 124M GPT-2 model on FineWeb across 8× H100 until validation loss is below 3.2800 (p < 0.01).
Building on PR #414 (29.858 s), I submitted PR #416 (20 files, +975 / −151 lines). Across 21 unseeded 8×H100 runs, it averages 29.463 s (median 29.430 s, fastest 29.341 s) with mean validation loss 3.27819 ± 0.00238 (18/21 below 3.28, one-sided t = −3.488, p = 0.00116, Wilcoxon p = 0.00335) and 1,280 MiB less peak reserved memory.1
In 4 interleaved rounds against PR #414 on the same node (12 runs vs. 4), our branch was 587 ms faster overall (29.516 s vs. 30.103 s, median difference −440 ms) and 365 ms faster on warm rounds 2 to 4 (Welch p = 0.00021). Eight more unseeded runs on a second node averaged 29.366 s with 8/8 below 3.28 (3.27721 ± 0.00167, p = 0.00109). Before cleaning the diff down to 20 files for the PR, the same training code was also 414.5 ms faster across two same-node pairs and cleared 3.28 on 14 / 14 held-out seeds (3.27748 ± 0.00108, p = 4.23 × 10−7).

| Run Set | n | Train Time (Mean ± SD) | Val Loss (Mean ± SD) | One-Sided p (< 3.28) |
|---|---|---|---|---|
| PR #414 reference (upstream) | 16 | 29.858 ± 0.015 s | 3.27869 ± 0.00144 | 0.00122 (13/16) |
| PR #414 interleaved on our node (C2) | 4 | 30.103 ± 0.385 s | 3.27725 ± 0.00108 | 0.00729 (4/4) |
| PR #416, all unseeded runs (C1 + C2 + C3) | 21 | 29.463 ± 0.146 s | 3.27819 ± 0.00238 | 0.00116 (18/21) |
| PR #416, same-node interleaved (C2) | 12 | 29.516 ± 0.162 s | 3.27875 ± 0.00271 | 0.0692 (9/12) |
| PR #416, second container (C3) | 8 | 29.366 ± 0.030 s | 3.27721 ± 0.00167 | 0.00109 (8/8) |
| Earlier held-out sweep (same code) | 14 | −414.5 ms (2 pairs) | 3.27748 ± 0.00108 | 4.23 × 10−7 (14/14) |
All 26 raw UUID logs (21 for our branch and 5 for #414) are committed in PR #416 under records/track_1_short/2026-12-02_StratifiedCPLM/.2
1. Stratified 256-LUT CPLM and Exact Dense dW
Most of the gain comes from the last third of Stage 2. In PR #414, those 125 steps run unweighted sampled softmax over P = 24,576 candidates across all T = 49,152 tokens per rank.3 That has two drawbacks. First, summing exp(z) over fewer than half of the 50,304 tokens with weight 1 biases the partition function right before Stage 3 switches to exact softmax. Second, because 49,152 >= 32,768 (MIN_ROWS), lm_head backward switches from dense FP8 GEMMs to sampled_head.py's 1-in-4 row-sampled dW estimator (12,288 rows at weight 4), adding gradient variance late in training.
Importance-weighted stratified softmax (PR #403 by x4ahmed) fixes the normalizer bias by keeping common tokens at weight 1 and weighting uniform tail samples by their inverse inclusion probability. The issue on H100 is that Modded-NanoGPT's cross-entropy kernel relies on a 256-entry FP8 E4M3 lookup table in shared memory. Because each logit is an 8-bit E4M3 byte, each row evaluates exp(A · σ(s) − A) once for the 256 possible values and looks up the rest. Adding a per-column weight col_logw[j] breaks the 256-entry table and adds another HBM read per logit.
In stratified_softmax.py and perf/kernels/cplm.py, we split each microbatch into 2 chunks of 24,576 rows at width P = 12,288 and arrange each chunk's candidates into two contiguous, 8-aligned bands. Columns [0 .. num_exact − 1] have weight 1.0, and columns [num_exact .. 12,287] are a uniform without-replacement tail sample. On the host prep thread (overlapped with the previous GPU step), we track token frequencies and select the top 12,288 tokens in O(V) using np.argpartition (~5× faster than argsort). Each chunk includes all of its targets plus the CPLM <copy> token (50257), rounds num_exact up to a multiple of 8 (default 6,144), fills any remaining exact slots from the top-frequency list, and samples 6,144 tail tokens from the rest. Every tail column shares a single scalar weight: tail_w = (50304 − 6144) / 6144 = 7.1875.
num_exact is a multiple of 8, every 8-byte load in the LUT CUDA kernel is either all-exact or all-tail. Splitting 49,152 rows into two 24,576-row chunks keeps backward below MIN_ROWS = 32,768 so it stays on exact dense dW.With num_exact % 8 == 0, no 8-byte uint2 load crosses the exact/tail boundary. Pass 1 sums 8 lookups from lut_e into csum and applies one select: (idx < num_exact) ? csum : csum * tail_w. Pass 2 keeps two 256-entry E5M2 gradient tables in shared memory (lut_g4 for exact columns and lut_gt4 scaled by tail_w for tail columns) and chooses the pointer once per 8-byte store. Extra HBM reads per chunk: two floats (8 bytes).
Because each chunk has 24,576 < 32,768 rows, lm_head backward stays on dense FP8 GEMMs across all 49,152 tokens while halving the logit projection width (24,576 → 12,288). One Triton kernel (sampled_densify2, BLOCK_R=64, BLOCK_V=128, num_warps=8) scatter-adds both [D, 12288] chunk gradients directly into the full [D, 50304] BF16 gradient tensor.
We also tested 3 × 16,384 @ P = 8,192 (exact = 5,120, tail_w = 14.71), which was a bit faster in Stage 2c but had higher variance. Doubling the tail sample to 2 × 24,576 @ P = 12,288 (tail_w = 7.1875) beat it on 6 / 6 paired seeds by −1.29 mnats (3.27902 → 3.27773, paired t = −5.38, p = 0.0014) while still saving nearly 200 ms in Stage 2c vs. #414.

3 × 16,384 @ P = 8,192 (tail_w = 14.71) to 2 × 24,576 @ P = 12,288 (tail_w = 7.19) lowered loss on all 6 seeds by −0.62 to −2.11 mnats.2. Stage-4 Linear LR Cooldown (0.30 → 0.18)
In PR #414, the learning rate decays to LR_FLOOR = 0.30 at step 1,029 (the end of Stage 3) and stays flat at 0.30 through all 20 steps of Stage 4. Right at step 1,029, embed and lm_head untie and the batch size drops from 20 to 8, so gradient noise increases right before final validation.
In schedule.py, we keep LR_FLOOR = 0.30 unchanged through Stage 3 and decay linearly from 0.30 to 0.18 over the 20 Stage-4 steps. On seed 0 that reduced validation loss by −0.48 mnats (3.27785 → 3.27737) with no change in runtime.
3. Six Kernel Changes
The remaining speedups come from six zero-loss kernel changes in the Stage 0 to 4 CUDA graphs.4
3.1 Fused transpose-densify (sampled_densify_t)
On the 565 sampled-head steps in Stages 0, 1, and 2a–b, sampled_head_wg accumulates the gradient in [P, D] FP32. PR #414 wrote that buffer out, ran transpose_copy into a [D, P] BF16 intermediate, and then ran sampled_densify into [D, 50304] BF16. sampled_densify_t (BLOCK_R=64, BLOCK_V=128, num_warps=8, num_stages=3) gathers active rows along D, casts to BF16 and transposes in registers with tl.trans, and stores straight into [D, V], removing the intermediate buffer and the transpose_copy call.
3.2 Fused negative + <copy> accumulation + counter advance
After the positive 1-in-4 sampled GEMM in sampled_head.py, PR #414 ran three Triton kernels:_negative_add (reading X), _copy_add (reading X again), and _advance[(1,)] to increment the sampling counter. On Stages 2 and 3, _negative_copy_add (BT=32, BD=128, num_warps=2) reads each tile of X once, handles both <copy> and MTP targets, skips PPOS/G loads when prefix_weight == 0, and increments COUNTER from CTA (0, 0). On Stage 1, _negative_add stays separate to avoid register pressure while _copy_add_advance absorbs the counter increment.
3.3 Asymmetric copy-pointer attention tiles (cplm_copy)
In perf/kernels/cplm.py, forward, dQ, and dK all used (BM=64, BN=64, num_warps=4, num_stages=3). Forward and dQ parallelize over queries and loop over keys, so using (BM=64, BN=128, num_warps=4, num_stages=2) halves the inner loop count. dK parallelizes over keys, so keeping BN=64 preserves its grid size.
3.4 MoE dispatch block size and warp count
In perf/kernels/moe_mlp.py, lowering DISPATCH_BLOCK from 1024 to 256 (with a power-of-2 fallback so num_blocks <= 512) increases dispatch CTA parallelism 4×. Raising num_warps from 4 to 8 on _grad_gather_quant_kernel and _dx_combine_kernel improves memory latency hiding with bit-exact results. We also pass write_col=False in local MoE FP8 refresh to skip writing an unused column cache.
3.5 Sequential wide QKV-RoPE backward (qk_dim = 128)
On layers 3 and 10 (qk_dim = 128), the backward kernel in perf/kernels/qkv_rope.py held Q, K, and V live in registers at once and spilled to local memory. _qkv_norm_rope_pack_fp8_backward_wide_kernel loads rotary factors once and processes Q, K, and V sequentially per BLOCK_T = 32 tile, writing each FP8 output before moving to the next. That cuts live registers roughly in half, runs cleanly at 4 warps with no spills, and matches the original FP8 outputs bit-for-bit.
3.6 ANVIL moe_bank persistent TMA path
In optim/anvil.py, banks with split_baddbmm = True run ANVIL's four Newton–Schulz steps through the fused persistent TMA kernel gemm_xb_add without copying X each step; otherwise they fall back to cuBLAS baddbmm with defensive copies. Because SPLIT_BADDBMM_MIN_ROWS = 1024 used strict >, the 1024 × 768 moe_bank missed by one row. Changing > to >= saves ~20 ms per run.
4. Systems and Overlap (PR #415 & PR #383)
We also pulled in several systems improvements from open PRs #415 and #383.5
On sampled steps (including both Stage-2c chunks), _gather_dual_fp8_kernel in sampled_softmax.py gathers FP8 candidate rows and writes both (P, D) and (D, P) layouts in one pass. On window transitions, _yarn_build_rows_kernel (model/attention.py) rebuilds rotary tables in one Triton kernel, and a 16-slot pinned host ring buffer in model/gpt.py copies SSMax window caps asynchronously into graph buffers.
After step 1,049, canonical_mask_build.py and canonical_mask.py build the BPE canonical mask directly into bit-packed uint8 on rank 0 and broadcast it asynchronously to ranks 1 to 7. At the same time, tail_average.py and train_gpt.py compute squared weight norms per 1/8 shard, sum them in one all_reduce, rescale on GPU without .tolist(), and overlap the async all_gather_into_tensor calls with the canonical mask broadcast. In ngram_table.py, eval_pulls also runs asynchronously on its own process group.

PR #414: 148 ms saved through step 600, the largest drop in Stage 2c (steps 850 to 975) from Stratified CPLM, and ~50 ms saved after step 1,049 from overlapped post-step shipping.5. Reproduce and Logs
The submission is PR #416 on KellerJordan/modded-nanogpt (commit 92b9ad6 on top of #414):
git clone https://github.com/Steve8323/modded-nanogpt.git cd modded-nanogpt git checkout 92b9ad6 python3 data/cached_fineweb10B.py 8 torchrun --standalone --nproc_per_node=8 train_gpt.py
All 26 raw logs/<uuid>.txt files (21 unseeded runs of 92b9ad6 and 5 runs of #414) are in records/track_1_short/2026-12-02_StratifiedCPLM/ on PR #416. Earlier ablation scripts and JSON logs are in Steve8323/modded-nanogpt-sota.
All 21 Unseeded Official PR Runs (Commit 92b9ad6)
| Run | Train Time | val_loss | Run | Train Time | val_loss |
|---|---|---|---|---|---|
| r1_cand0 (C2) | 29.463 s | 3.2763 | r4_cand2 (C2) | 29.382 s | 3.2821 |
| r1_cand1 (C2) | 29.399 s | 3.2778 | w1_r1 (C3) | 29.430 s | 3.2773 |
| r1_cand2 (C2) | 29.414 s | 3.2841 | w1_r2 (C3) | 29.387 s | 3.2779 |
| r2_cand0 (C2) | 29.558 s | 3.2822 | w1_r3 (C3) | 29.354 s | 3.2752 |
| r2_cand1 (C2) | 29.490 s | 3.2782 | w1_r4 (C3) | 29.354 s | 3.2791 |
| r2_cand2 (C2) | 29.457 s | 3.2758 | w1_r5 (C3) | 29.343 s | 3.2778 |
| r3_cand0 (C2) | 29.999 s | 3.2756 | w1_r6 (C3) | 29.353 s | 3.2794 |
| r3_cand1 (C2) | 29.530 s | 3.2771 | w1_r7 (C3) | 29.341 s | 3.2750 |
| r3_cand2 (C2) | 29.472 s | 3.2787 | w1_r8 (C3) | 29.364 s | 3.2760 |
| r4_cand0 (C2) | 29.536 s | 3.2790 | r1_cand0 (C1) | 29.612 s | 3.2793 |
| r4_cand1 (C2) | 29.491 s | 3.2781 | |||
| Mean (n = 21) | 29.463 ± 0.146 s | 3.27819 ± 0.00238 | Rule 2 (18/21 < 3.28) | t = −3.488 | p = 0.00116 |
Container notes: C1 was preempted after 2 runs (1 × #414 at 29.941 s / 3.2775, 1 × 92b9ad6 at 29.612 s / 3.2793). C2 ran 4 interleaved rounds (4 × #414, 12 × 92b9ad6), with host stalls in steps 1 to 25 on r1_base414 (30.678 s) and r3_cand0 (29.999 s). C3 ran 8 unseeded runs of 92b9ad6 (29.366 s mean, 8/8 below 3.28) before preemption. Every completed run across C1, C2, and C3 is included above.