GitHub: github.com/atveit/diffusion-nanogpt · Try Track 3: Open in Colab (GPU / TorchTPU) · Minimal Inference Sibling: github.com/atveit/diffusion-picogpt (Part 1)
⚠️ Baseline #0 calibration runs — the first official speedrun records are wide open. Just as
modded-nanogptstarted with a 45-minutellm.cbaseline before the community drove it under 30 seconds, the 8×H100 runs below are Baseline #0 calibration runs (4.062and4.034NELBO in ~4 minutes) proving out the locked harness, canary checks, and Track 3 regime. The first official≤ 3.40Sprint and≤ 3.28Full records are up for grabs.
Over the past couple of months I've had a lot of fun chasing milliseconds on Keller Jordan's modded-nanogpt speedrun — taking GPT-2 pretraining down to 29.90 seconds on 8×H100 and testing Looped Transformers against that 30-second stopwatch.
Meanwhile, discrete text diffusion has crossed from research papers into ultra-fast real systems — from Block Diffusion and LLaDA to Mercury, Gemini Diffusion, DiffuCoder, and DFlash (see the Part 1 Appendix for links). Yet discrete diffusion didn't have a single, open modded-nanogpt-style speedrun on 8×H100 to race schedules, objectives, optimizers, and kernels apples-to-apples.
Today I'm open-sourcing atveit/diffusion-nanogpt (alongside its minimal inference sibling atveit/diffusion-picogpt from Part 1).
Discrete text diffusion in 15 lines of NumPy
Before getting into rules and 8×H100 leaderboards, it helps to see the entire mechanics of discrete text diffusion in plain NumPy — no PyTorch, no mystery. Three tiny pieces from diffusion-picogpt explain both how the model trains and how it generates in parallel:
1. The 5-line stratified 1/t NELBO training step (with gather-before-lm_head)
Pick a random mask rate t ∈ [ε, 1], replace each token with MASK_ID independently with probability t, run a bidirectional Transformer to get hidden states h, gather only the masked positions before the 50,304-way vocabulary projection (cutting head FLOPs and logit VRAM roughly in half!), and weight cross-entropy by 1 / t:
t = np.random.uniform(1e-3, 1.0)
mask = np.random.rand(len(x0)) < t # ~50% masked on average
x_noisy = np.where(mask, MASK_ID, x0)
h = bidirectional_transformer(x_noisy) # (L, D) hidden states
logits = h[mask] @ lm_head.T # gather-before-lm_head (~2x less head compute/VRAM)
nelbo = (cross_entropy(logits, x0[mask]).sum() / t) / len(x0)
2. The 3-line vectorized Block Diffusion (BD3-LM) attention mask
For Track 1 Block Diffusion (B ≥ 16), we concatenate [x_noisy, x_clean] into length 2L so all blocks train in one vectorized pass: noisy block b attends bidirectionally inside itself (bq == bk) and to strictly earlier clean blocks (bk < bq), while clean blocks stay strictly block-causal (bk <= bq) and never see noisy tokens:
def build_block_mask(seq_len, block_size):
"""Exact (2L, 2L) vectorized BD3-LM mask for concatenated [x_noisy, x_clean]."""
b = np.arange(seq_len) // block_size
bq, bk = b[:, None], b[None, :]
return np.block([[bq == bk, bk < bq], [np.zeros((seq_len, seq_len), dtype=bool), bk <= bq]])3. The 5-line parallel confidence-unmasking sampler
At inference time, start from [MASK] tokens and unmask k = ceil(remaining / steps_left) of the model's highest-confidence positions per pass — filling in easy anchors from both ends first, then resolving the ambiguous words between them:
def _unmask_step(x_view, logits, masked, steps_left, temperature, top_k, rng, real_vocab):
pred, conf = sample_tokens(logits, temperature, top_k, rng, real_vocab)
k = len(masked) if steps_left == 1 else min(len(masked), max(1, math.ceil(len(masked) / steps_left)))
chosen = masked[np.argsort(conf[masked])[-k:]]
x_view[chosen] = pred[chosen]Once those three snippets click, the entire benchmark design below falls right into place.
The hardest rule-design problem: stopping diffusion from collapsing back into AR
In standard modded-nanogpt, the rules are crisp: train on the fixed FineWeb10B stream, evaluate exact cross-entropy on the first 10,485,760 tokens of fineweb_val_000000.bin, and cross ≤ 3.28 validation loss as fast as possible.
If you naively copy that setup for diffusion, a clever speedrunner will break it on day one:
- AR collapse: In Block Diffusion, if you shrink the block size
Bdown to1, the model collapses identically to causal autoregressive GPT — which wins the single-pass loss race easily while throwing away parallel decoding. - Silent clean-token leakage: In vectorized
[x_noisy, x_clean]Block Diffusion, a single bug in the attention mask (or<|endoftext|>document boundary logic) lets noisy blockbpeek at clean tokens in block≥ b, producing impossibly low fake loss. - Evaluation noise & grid overfitting: Monte Carlo masking introduces variance, while a small fixed table of mask rates
tcan be overfit.
To make the benchmark ungameable, every official run goes through a locked evaluation harness (eval/harness.py — git diff eval/harness.py must be empty) built on three mechanisms:
1. Stratified continuous-t NELBO (a strict upper bound on exact NLL)
Under absorbing-state masked diffusion with mask probability (), the continuous-time Negative Evidence Lower Bound per token is:
For Track 1 Block Diffusion (), the same expectation runs per block conditioned only on strictly earlier clean blocks and the noisy current block . Crucially, the harness slices logits strictly to logits[..., :50257] and applies FP32 log_softmax over the 50,257 real GPT-2 tokens (zero probability mass on MASK_ID = 50257). That makes NELBO ≤ 3.28 a mathematical guarantee that the model defines a valid probability distribution over GPT-2 tokens with exact negative log-likelihood ≤ 3.28 — matching Karpathy's GPT-2 Small / modded-nanogpt target.
2. Batch- and world-size-invariant SplitMix64 seeding
We partition [ε, 1] into 16 equal strata and draw continuous jitter inside each stratum over K_EVAL = 2 full passes (20,971,520 token evaluations, Monte Carlo standard error ≈ 0.00053 nats). Each sequence s derives its own deterministic seed via SplitMix64 in eval/harness.py, so masks are bit-identical whether you evaluate on 1 GPU with batch size 4 or 8×H100 with batch size 32:
def _sequence_seed(seed: int, pass_idx: int, seq_idx: int) -> int:
"""Derive a deterministic 63-bit seed uniquely from (seed, pass_idx, seq_idx)."""
mask64 = 0xFFFFFFFFFFFFFFFF
x = (
((int(seed) & mask64) * 0x9E3779B97F4A7C15)
^ (((int(pass_idx) + 1) & mask64) * 0xBF58476D1CE4E5B9)
^ (((int(seq_idx) + 1) & mask64) * 0x94D049BB133111EB)
) & mask64
x = ((x ^ (x >> 30)) * 0xBF58476D1CE4E5B9) & mask64
x = ((x ^ (x >> 27)) * 0x94D049BB133111EB) & mask64
return (x ^ (x >> 31)) & 0x7FFFFFFFFFFFFFFF3. Automated canary anti-leakage tests
Before official validation runs, eval/harness.py actively tries to catch your model cheating. For Track 1, it enforces block_size >= 16, mutates x_clean at block ≥ b (including toggling <|endoftext|> boundaries), mutates x_noisy in all blocks ≠ b, and asserts that block b's output logits do not move by more than 1e-4:
# Check 2: No clean current or future block leakage (including EOT toggling).
for b in probe_blocks:
start, end = b * block_size, (b + 1) * block_size
x_clean_mut = x_clean.clone()
x_clean_mut[:, start:] = _mutate_clean_tokens(x_clean[:, start:])
logits_2 = eval_fn(x_noisy.clone(), x_clean_mut, t_blocks.clone(), block_size)
diff = float((logits_1_real[:, start:end] - logits_2_real[:, start:end]).abs().max().item())
if diff > tol:
raise AssertionError(
f"Canary [no_clean_current_future_leakage] FAILED on block {b}: max_abs_diff={diff:.6e}"
)For Tracks 2 & 3, eval_fn(x_noisy, t) never receives x_clean at all, and the canary verifies finite logits and strict determinism across intervening batches (blocking hidden cross-batch state tricks). Every valid log must print CANARY: PASS and the locked HARNESS_SHA256.
The four competition tracks (8× NVIDIA H100 SXM)
All tracks evaluate on the same locked 10.49M-token FineWeb validation set and follow modded-nanogpt's statistical discipline (p < 0.01 via eval/verify_pvalue.py, untimed synthetic-only warmup, no hidden inductor flags, full source embedded in every log):
| Track | Model Class | Training Data Rule | Official Metric & Target |
|---|---|---|---|
| Track 1a: Block Diffusion (Sprint) | Block-causal across blocks, bidirectional masked diffusion within blocks (B ≥ 16) |
Fixed FineWeb10B stream | ≤ 3.40 stratified NELBO (p < 0.01) |
| Track 1b: Block Diffusion (Full) | Block-causal across blocks, bidirectional masked diffusion within blocks (B ≥ 16) |
Fixed FineWeb10B stream | ≤ 3.28 stratified NELBO (p < 0.01) |
| Track 2: Full MDLM | Full bidirectional masked diffusion (no clean prefix blocks) | Fixed FineWeb10B stream | ≤ 3.28 stratified NELBO (p < 0.01) |
| Track 3: Data-Constrained | Full MDLM or Block Diffusion (B ≥ 16) |
Strictly first 20,000,000 tokens of fineweb_train_000001.bin (multi-epoch allowed) |
Lowest NELBO in ≤ 300.0 s (p < 0.01 vs prior record) |
First 8×H100 baselines: Tracks 1 & 2 (and the speedrun headroom)
Our starter trainer (train_diffusion.py) adapts the modded-nanogpt stack cleanly to discrete diffusion: a 12-layer / 768-dim Transformer (278M params) with RMSNorm, QK-Norm, half-truncated RoPE, symmetric U-Net skips, value embeddings, ReLU² MLP, logit softcap, gather-before-lm_head (projecting only the ~50% masked positions through the 50,304-way vocabulary head during training), FlexAttention, and distributed Muon (with Polar Express) + AdamW.
Here are the first real 8×H100 SXM5 calibration runs for Track 1 (B = 16) and Track 2 (Full MDLM):
- Track 1 Block Diffusion (
B = 16):132 ms/step(2.0M tok/s) over2,000steps (524Mtokens) →4.062val NELBO in264.3 s(CANARY: PASS). - Track 2 Full Bidirectional MDLM:
89 ms/step(2.95M tok/s) over2,600steps (682Mtokens) →4.034val NELBO in230.6 s(CANARY: PASS).
That leaves roughly ~0.75 nats of speedrun headroom between Baseline #0 (4.03–4.06) and the 3.40 / 3.28 targets — wide open for FP8 matmuls, FlashAttention-3, variance-reduced ELBO objectives, tuned noise/LR schedules, and better optimizers.
Real bidirectional infilling from the 4.4-minute 8×H100 checkpoint
Even at 4.062 NELBO, you can watch the Track 1 checkpoint perform real bidirectional fill-in-the-middle infilling on a held-out FineWeb validation passage (masking a 24-token interior span and unmasking it in 12 parallel steps in 0.091 s on H100):
[MASKED INPUT]
|Viewing Single Post From: Spoilers for the Week of February 11th|
|Lil||Feb 1 2013, 09:58 AM|
Don't care [MASK x 24] some good "SAMANTHA GENE!!" Marlena Death-Stares out of it. And "newfound" feelings. Please. If only.
[PROGRESSIVE BIDIRECTIONAL UNMASKING TRAJECTORY]
step 0/12 (masks_left=24): [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_] [_]
step 2/12 (masks_left=20): if [_]'re [_] [_] [_] [_] [_] [_] [_] [_] [_] [_]. [_] [_] [_] [_] [_] [_] [_] [_] for
step 5/12 (masks_left=14): if you're [_] [_] the [_], [_] [_] [_] [_] [_] it.
I [_] [_] [_] [_] [_] [_] for
step 7/12 (masks_left=10): if you're [_] [_] the [_], but I [_]'t [_] it.
I'm [_] [_] [_] [_] [_] for
step 10/12 (masks_left= 4): if you're new to the [_], but I don't recommend it.
I'm [_] [_] to the [_] for
step 12/12 (masks_left= 0): if you're new to the album, but I don't recommend it.
I'm going on to the lookout forNotice step 2: before most of the middle exists at all, the model immediately pins "if ... 're" onto "Don't care" on the left and pins "for" right against "some good ..." on the right, then builds the bridge inward from both ends.
The Track 3 money result: 20M tokens, AR collapse vs. MDLM endurance
If Tracks 1 and 2 ask "how fast can diffusion catch up to AR when tokens are unlimited?", Track 3 flips the question to the regime where diffusion genuinely shines: what happens when unique data is scarce?
In Track 3, training is strictly capped to the first 20,000,000 tokens of fineweb_train_000001.bin with a 300-second wall-clock cap on 8×H100. To calibrate the track, we trained two models with the exact same 12L/768d backbone and Muon optimizer on those exact same 20M unique tokens and evaluated both on the same 10.5M-token FineWeb validation shard:
- AR-20M: Standard causal autoregressive GPT (reporting exact validation NLL).
- MDLM-20M: Full bidirectional masked diffusion (reporting validation NELBO, a strict upper bound on exact NLL).
Here is what happened on 8×H100:
| Model (same 12L/768d + Muon) | Best Val Loss | Best Epoch | End-of-Run Val Loss | End Epoch | Wall Time |
|---|---|---|---|---|---|
| AR-20M (exact val NLL) | 4.654 (ppl 105) |
2.6 |
7.280 (ppl 1,452) |
7.2 |
120.2 s |
| MDLM-20M (val NELBO upper bound) | 4.718 |
9.8 |
4.983 |
44.1 |
300.0 s |
The contrast is stark. AR-20M peaks early at epoch 2.6 (4.654), then memorizes the 20M-token training slice (train_loss plunges from 6.53 down to 1.82) while validation loss falls off a cliff to 7.280 (ppl = 1,452) by epoch 7.2.
MDLM-20M, running the exact same backbone and optimizer, keeps improving all the way to epoch 9.8 (4.718, 67.0 s) — and even after 44.1 epochs across the exact same 20M tokens (at the 300-second ceiling), its validation NELBO is still 4.983.
The intuition is simple — reading the exact same script vs. moving the blanks on every quiz: every epoch of autoregressive training replays the identical deterministic next-word quiz (The cat sat on → the), so the model memorizes the 20M-token book by rote and collapses on unseen text. Masked diffusion moves the [MASK] blanks randomly on every pass, turning those same 20M tokens into virtually infinite fresh fill-in-the-blank puzzles.
One immediate architectural clue: value_embeds as a 20M-token memorization sponge
Looking closely at our 278M-parameter baseline pointed straight to an easy Track 3 win for the first contributor who wants it.
Because DiffusionGPT inherited modded-nanogpt's architecture, it includes three full-vocabulary value_embeds lookup tables (3 × 50,304 × 768 = 115.9M parameters — 42% of the entire model! — on top of another 77.3M in embed and lm_head). On unlimited FineWeb10B tokens (Tracks 1 & 2), huge token-keyed tables accelerate convergence dramatically. On strictly 20M unique tokens, however, 193M vocabulary-table parameters act like a massive memorization sponge — amplifying AR-20M's cliff after epoch 2.6 and driving MDLM-20M's gentle late-epoch drift from 4.718 (epoch 9.8) to 4.983 (epoch 44.1).
Simply disabling or shrinking value_embeds, adding weight decay / dropout, or averaging weights with EMA/SWA should push Track 3 well below 4.718 — and probably past AR-20M's 4.654 best — on the very first community PR.
Hardware physics: compute vs. memory bandwidth (and why diffusion accelerates AR too)
Autoregressive and diffusion models sit on opposite sides of the GPU roofline:
- Inference is about memory bandwidth: When an autoregressive GPT generates text at batch size 1, it has to haul the entire model weights out of HBM just to emit one single token — leaving the Tensor Cores mostly idle. Block Diffusion (
B = 16) reads the weights from HBM once and unmasks 4–16 tokens in parallel, turning a memory-bandwidth bottleneck into high-utilization Tensor Core compute. That is the core hardware reason commercial diffusion LLMs like Mercury and Gemini Diffusion hit1,000–1,470+ tok/son H100s. - Even autoregressive serving wins via DFlash / DFlare: An autoregressive verifier can check 16 drafted tokens in a single HBM read (almost the same memory traffic as generating 1 token). Pairing it with a tiny Block Diffusion drafter (like DFlash / DFlare) lets the drafter propose all 16 tokens in parallel instead of 16 sequential draft steps — meaning faster, sharper Track 1 Block Diffusion models directly accelerate autoregressive LLMs too.
- Training is about raw FLOPs and attention throughput: Because discrete diffusion burns ~
2.5–4×(Block Diffusion) to ~9–16×(Full MDLM) more training compute than AR to reach the same validation loss, next-gen hardware with much higher FP8/FP4 FLOPs and faster attention engines (B200, B300 Ultra with its 2× attention engine, TPU7x Ironwood, MI355X MXFP6) compresses diffusion training times disproportionately.
| Hardware Setup | Precision | Est. Block Diffusion (B=16, ~3.40 ELBO) |
Est. Full MDLM (3.28 exact NLL) |
Porting Notes |
|---|---|---|---|---|
| 8× NVIDIA H100 SXM (Official) | BF16 / FP8 | 45–60 s |
4.5–6 min |
Baseline (CUDA / Triton / FA3) |
| 4× NVIDIA B300 SXM6 | BF16 / FP8 / FP4 | 33–45 s |
3.0–4.5 min |
Low–Med (FA4 + 2× Attention; ~same hourly cost as 8×H100) |
| 8× NVIDIA B200 / MI355X / TPU7x | BF16 / FP8 / MXFP6 | 22–35 s |
2.2–3.5 min |
Blackwell FA4 / ROCm AITER / JAX SplashAttention |
| 8× NVIDIA B300 Ultra | BF16 / FP8 / FP4 | 20–28 s |
1.8–2.8 min |
FA4 + 2× Attention engine |
(Official leaderboards stay standardized on 8× NVIDIA H100 SXM for direct 1:1 comparability with modded-nanogpt and wide cross-cloud access; next-gen hardware estimates above assume an optimized FP8/FA4 stack.)
Come take the first records
Everything is MIT-licensed and ready to run on 1×H100 for development or 8×H100 for official records:
git clone https://github.com/atveit/diffusion-nanogpt.git
cd diffusion-nanogpt
python data/cached_fineweb10B.py 9
# Run any track on 8xH100 (or set NPROC=1 for single-GPU dev)
./run.sh block_sprint # Track 1a (B>=16, target <= 3.40)
./run.sh mdlm # Track 2 (Full MDLM, target <= 3.28)
./run.sh data_constrained # Track 3 (20M tokens, <= 300s cap)
# Verify p < 0.01 across seeds
python eval/verify_pvalue.py --target 3.40 --logs logs/*.txtAnd if you train a checkpoint you're proud of, you can export it to a single DPIC .bin file with atveit/diffusion-picogpt and run it anywhere — pure NumPy on a laptop, Lean 4 with proved mask isolation, or raw CUDA/Rust/Swift/Mojo.
Pull requests for the first official Track 1a (≤ 3.40), Track 1b (≤ 3.28), Track 2 (≤ 3.28), and Track 3 (< 4.718 in ≤ 300 s) records are officially open!
ℹ️ How this benchmark was built
I built atveit/diffusion-nanogpt using Google Antigravity with parallel Gemini agents for the locked NELBO harness and canary verifier, baseline PyTorch/FlexAttention/Muon training stack, unit tests, and 8×H100 SXM5 calibration runs on RunPod.
All four 8×H100 calibration logs (with full embedded source code and CANARY: PASS) are checked into the repository under records/. The benchmark design, claims, and any mistakes are mine.
Best Regard,
Amund