Skip to content

flashnext cuda: the MTP rows' row best runs over 32 blocks a row, fn_row_best's bits - #4632

Merged
ashhart merged 3 commits into
ashhart:mainfrom
jayleaton:up/flashnext-row-best-split
Nov 24, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
jayleaton:up/flashnext-row-best-split

Conversation

@jayleaton

@jayleaton jayleaton commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Flash Next's MTP row best (best value, its first id and the row's log-sum-exp) ran as one 1024-thread block a row.
It now runs as two passes of 32 one-warp blocks a row. fn_row_best_max writes each warp's best, and fn_row_best_sum
re-reduces those maxima, sums its warp's exp terms, and the row's last block folds the 32 sums in fn_row_best's
order. The output bytes equal fn_row_best's.

Checks on this head

  • Head commit: 64eb56f, on main 14951bc (the code is fb42efb's, where the tests below ran; the head adds only the CHANGELOG line). The GPU receipt below was measured on main 1587c8c with the same
    commit (6e9c341a4). Main has not changed any of this PR's kernel or Flash Next source files since then; the rebase
    only moved the base, and the code merged onto current main without conflicts.
  • Lean checker on the base and on this head: 165 and 165, 0 new (on 1587c8c: 167 and 167, 0 new).
  • python3 tools/pr_check.py --base origin/main --pr 4632: 0 errors, 0 warnings (8 changed files, lean 165 vs 165, 0 new)
  • zig fmt --check build.zig zig and git diff --check origin/main HEAD: pass.
  • Tests run on this head (x86_64): zig build test test-golden --test-timeout 20m: 824/827 steps, 12,149/12,239 passed, 89 skipped, 1 failed: request_admission_http_test "every way an n-choices request ends returns its places" (engine.cancelled not yet set; server code this PR does not touch). The same test binary rerun alone passed 6 of 6 times. test-golden passed. zig build test-cuda-host: 470/470 steps, 2,014/2,027 passed, 13 skipped.
  • Tests run on the receipt base 1587c8c + this commit (aarch64, cold cache): zig build -Dfixed-cpu test-host --test-timeout 20m: 2344/2344 steps, 23,167/23,326 passed, 159 skipped, 0 failed, the same counts as main;
    zig build test-cuda-host: 146/146; zig build test (x86_64): exit 0, like main.
  • CI: pending
  • Not run, and why: kernel-contract gates on sm_80 / 86 / 89 / 120 (no such GPU here; their records were checked from
    fatbins with kernel-contract-limits, below). The whole-registry kernel contract on sm_121 (see Kernel contract).

Receipt

  • Main against branch (2x DGX Spark, GB10 sm_121, --tp 2 over RoCE, NVFP4, --context 49152 --parallel 16
    --prompt-cache-gib 0; cells A B B A, main's first cell dropped as a cold start; aggregate tok/s):

    main branch
    1 stream greedy, code / chat 53.7 / 39.0 53.9 / 39.1 +0.5% / +0.4%
    1 stream seeded, code / chat 51.2 / 39.7 51.4 / 39.8 level
    8 streams greedy, code / chat 223.4 / 161.4 227.6 / 163.4 +1.9% / +1.2%
    16 streams greedy, code / chat 260.2 / 211.6 262.3 / 216.1 +0.8% / +2.2%
    cold prompt 8K / 32K (tok/s) 1,698 / 1,694 1,709 / 1,707 level

    Pre-rebase fork evidence, not this head: on 2x RTX PRO 6000 (sm_120, FP8, a fork carrying other changes) the same
    kernel pair gave +1.6% at one stream, +3.6% / +4.3% at 8 / 16 streams, level prompt speed, hashes equal.

  • Boxes it reaches: every CUDA box that drafts with Flash Next's MTP head.

  • New switch? No.

  • Environment: TensorFold 1587c8c + this commit, Zig 0.17.0, CUDA 13.0 (nvcc 13.0.88), driver 580.178.04,
    2x NVIDIA GB10 (sm_121), NCCL 2.30.7 over both ConnectX-7 RDMA devices, nvidia/Qwen3.8-Flash-Next-NVFP4.

  • Paths and platforms: CUDA only. Contract gates ran on sm_121; records for sm_80, 86, 89, 120 and 121 were checked
    with kernel-contract-limits. Metal and HIP are untouched.

  • Exactness: every arm gives main's token hashes (greedy code 4e759dbd859c, chat 764da77fbd3f, and the same seeded
    sets). bench_concurrent.py --alone --serial at 1 / 8 / 16 streams: every concurrent reply equals its alone run,
    and every alone run equals its "draft": false reply.

  • Main against this branch, same machine and checkpoint: the table above.

  • Decode speed before and after, from tools/bench_openai.py: the table above.

  • Prompt speed before and after: cold first request from tools/bench_cache.py --require-cold at 8K and 32K, level
    (table). Prompt passes do not call the row best.

  • Licence of any new weights or drafter: n/a

Kernel contract
  • Kernels registered: fn_row_best_max + fn_row_best_sum, replacing fn_row_best (gate 3 byte equality against the
    replaced hook).
  • Planted control: the split over V - 1 values posing as fn_row_best. It fails as planted: FAIL shapes control: the split row best over V - 1 values posing as fn_row_best: at 12x4x31 its bytes differ from fn_row_best's from byte 4,
    and the control is reported red at shapes, as planted.
  • SUMMARY line and exit status (sm_121, tf-cuda-test kernel-contract fn_row_best, exit 0):
    (filtered) SUMMARY 2 kernels: 2 pass gates 1-4, 0 fail, 0 known findings; 1 controls: 1 red as planted, 0 missed; 0 limit problems. The split is reported "16 shapes bit-equal to the kernel it replaces". Main, same command:
    1 kernel passes.
  • Scope: that run is filtered to fn_row_best and the kernels that replace it. The whole-registry run
    (zig build kernel-contract -Dsm=121) on main is incomplete: I stopped it at 2 h 28 min with 2,892 PASS, 480 FAIL,
    9 KNOWN and 0 SKIP lines, fn_row_best among the passes. Those 480 FAIL lines come from main without this change;
    this PR touches none of those kernels. I did not run the whole registry on this branch.
  • Limits: kernel-contract-limits over sm_80, 86, 89, 120 and 121 fatbins: fn_row_best, fn_row_best_max and
    fn_row_best_sum are "record current" on all five. The run reports 91 problems, all from main: the 10 planted
    controls, red as planted, and records main marks stale or absent (for example fn_row_topk's registry.none).
  • Chips I could not run: sm_80, sm_86, sm_89, sm_120 for the gates.

What I have not established

  • The contract gates on any chip but sm_121; the other four SMs are covered only by their limits records.
  • The whole-registry kernel contract, on main or on this branch (above).
  • A GPU receipt on this rebased head: the cells ran on 1587c8c with the same commit.
  • Speed on any box other than the GB10 pair at NVFP4 --tp 2, including one GPU. FP8 at TP2 was not measured
    against main, because main could not serve it on the boxes I had.
  • A resumed prompt against a fresh one: not measured for this change. Prompt passes do not call the row best.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. The contract cases
    cannot exist before the kernels do; the planted control shows the byte-equality gate is not vacuous.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. Drafted
    equals "draft": false and concurrent equals solo (above); resumed against fresh was not measured.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (No --drafter here: the MTP head drafts.)

@jayleaton
jayleaton force-pushed the up/flashnext-row-best-split branch 5 times, most recently from 1fbd2e0 to f2876ce Compare November 22, 2026 21:21
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @jayleaton. The split reduction looks sound, but its new persistent device scratch buffer is missing from the CUDA MTP head's memory accounting. Please add those 24,832 bytes to headBytes and extend the exact-accounting test, so the placement estimate includes that buffer.

  • Synthena

jayleaton and others added 3 commits November 24, 2026 04:30
…row_best's bits

fn_row_best runs one 1024-thread block per row, so a one-row draft step
fills one SM. fn_row_best_max and fn_row_best_sum do the same two passes
over (row, warp) blocks of 32 threads: each thread reads the same strided
values and each warp does the same shuffles, so the best, its first id
and the log-sum-exp keep their bits. The row's last block (an atomic
ticket) folds the 32 warp sums as warp 0 did.

Head.best takes the split for rows up to round_rows. The kernel contract
registers it as a replacement of fn_row_best (byte equality on every
served shape), with a planted control (the split over V - 1 values) that
goes red at shapes. The gradient-serving pins take the two sources.
The split row best keeps a persistent device buffer of split_bytes
(24,832 bytes at round_rows = 64) for each warp's best and id, each
warp's exponent sum and a counter a row. headBytes adds it, so the
placement estimate covers it, and the exact-accounting test pins it.
@ashhart
ashhart force-pushed the up/flashnext-row-best-split branch from aec2a7f to e03f416 Compare November 24, 2026 04:30
@ashhart
ashhart merged commit 025f0f4 into ashhart:main Nov 24, 2026
2 of 12 checks passed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @jayleaton. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

2 participants