Skip to content

Flash Next MTP wide norm: more blocks a row, byte-identical (CUDA sm_120/121, HIP gfx1201) - #1702

Merged
ashhart merged 3 commits into
ashhart:mainfrom
laudney:pr-rms-wide-tiles
Oct 31, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
laudney:pr-rms-wide-tiles

Conversation

@laudney

@laudney laudney commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1689.

Flash Next's MTP head norms each row of its four 2,560-value streams as one 10,240-value row, one block a row. At decode row counts most of the GPU idles. This PR adds faster kernels for that shape that store the current kernels' bytes by construction: the same per-thread sums, reduction trees, division, square root, multiply order and rounding. Every other shape, SM and architecture keeps the current launch.

CUDA: tf_rms_rows_sums_tiles (rms_tiles.cuh)

  • Grid (tiles, rows), 256 threads, tiles in {1, 10, 40}. Each block repeats its row's inverse norm exactly as tf_rms_rows_sums forms it: thread c of the 1,024-thread kernel's ten-value __fmaf_rn chain, four chains a thread; chain t + 256 j is lane t & 31 of native warp (t >> 5) + 8 j, so it runs the same warp XOR tree, then the same 32-warp tree and __fdiv_rn/__fsqrt_rn steps. The block stores its tile's y and that tile's FP32 sums of 32 stored BF16 values in ascending order.
  • Norms reads the current context's device capability once (Driver.currentCapability). rmsSums takes the tiled launch for width 10,240, group 32 and rows 1–16 on sm_120 (40 tiles at one row, else 10) and sm_121 (10 tiles up to four rows, else 1).

HIP (gfx1201): tf_fn_rms_wide_waves + tf_fn_rms_wide_apply (streams.hpp)

  • fn_block_sum is two stages, each wave's XOR tree and then the eight wave sums in order; the launch boundary follows it. tf_fn_rms_wide_waves runs one 32-thread group per (wave, row) with tf_fn_rms_wide's thread chains and tree and stores the wave sum. tf_fn_rms_wide_apply adds a row's eight wave sums in order in every thread, forms the same rsqrtf(total / width + eps) and stores (x * rinv) * scale, one value a thread.
  • Both read and write bf16 through bf16_to_float/float_to_bf16, what load/store do at kind 2; the runtime kind branch kept the forty loads a thread from issuing together. rmsWide takes the split on gfx1201 builds with alternates on (Choices.fuse), bf16, width 10,240, the head's scratch (8 floats a row) and rows 1–16.

Gates

  • Kernel contract: both register as replacements (replaces), so gate 3 requires the current kernel's bytes. CUDA registers two views of the launch (BF16 y; FP32 group sums, whose stress rows sum exactly in fp32 while bf16 and fp16 sums miss).
    • GB10 (sm_121): SUMMARY 472 kernels: 472 pass gates 1-4, 0 fail, 6 known findings; 321 controls: 321 red as planted, 0 missed; 181 limit problems — both views 16 shapes bit-equal to the kernel it replaces, group sums exact sums at k 10240, where fp16 sums would miss by infx and bf16 by 8388608x; the new launch's live limits match its record (48 registers, 20612 shared bytes); the limit problems are inherited and none is a new launch.
    • RTX PRO 6000 Blackwell (sm_120): both views pass gates 1-4 (16 shapes bit-equal to the kernel it replaces; group sums exact sums at k 10240, where fp16 sums would miss by infx and bf16 by 8388608x).
    • Radeon AI PRO R9700 (gfx1201): SUMMARY gfx1201 50 kernels: 50 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 120 limit problems — the limit problems are inherited live-register differences of other kernels under ROCm 7.16; none is a new launch.
    • Gate 5 records: CUDA from nvcc 13.0 for sm_80/86/89/120/121 (current on all five); HIP for gfx1030/1100/1151/1201 (all PASS).
  • Byte tests against the current kernels: CUDA tiles 1, 10 and 40 at rows 1–17, HIP split versus .fuse = false at rows 1–17, on random, zero, mixed-magnitude, fp32-overflowing, NaN and ±Inf rows (CUDA with rows 64 elements apart and NaN between them). GB10 and RTX PRO 6000 tf-cuda-test norm-rows PASS; R9700 hip-kernel-test 107/107.
  • Host: dispatch table and fallbacks (other SMs, widths, groups, rows 0 and 17), the existing row-launch ABI digest unchanged; zig build test 1388/1396 (8 skipped), test-cuda-host 3736/3744 (8 skipped), test -Dhip=true 429/434 (5 skipped); lean checker at the 425 baseline.

Timings

Width 10,240, captured graphs of 1,000 operations, alternating order, eleven samples, median; buffers repeat in cache, so these are kernel timings, not model throughput.

GPU Rows Current New Gain
Radeon AI PRO R9700 (gfx1201) 1 22.21 us 4.36 us 5.09x
Radeon AI PRO R9700 (gfx1201) 4 22.06 us 4.47 us 4.94x
Radeon AI PRO R9700 (gfx1201) 16 21.78 us 5.44 us 4.00x
RTX PRO 6000 Blackwell (sm_120) 1 4.67 us 1.75 us 2.67x
RTX PRO 6000 Blackwell (sm_120) 4 4.84 us 1.89 us 2.55x
RTX PRO 6000 Blackwell (sm_120) 16 4.85 us 2.15 us 2.26x
DGX Spark GB10 (sm_121) 1 5.34 us 2.16 us 2.48x
DGX Spark GB10 (sm_121) 4 5.43 us 2.34 us 2.32x
DGX Spark GB10 (sm_121) 16 5.43 us 3.95 us 1.37x

The CUDA rows were measured on a prototype with this kernel's arithmetic and launch geometry; the HIP rows on this PR's kernels. The norm runs once per MTP step, so whole-model decode gains are small.

Not run

  • Flash Next drafted-versus-plain token checks: the replacements store the current kernels' bytes, which the contract and byte tests check directly.

laudney and others added 3 commits October 31, 2026 10:45
tf_rms_rows_sums runs Flash Next's 10,240-wide MTP norm on one block
a row, so decode rows leave most SMs idle. tf_rms_rows_sums_tiles
splits each row into 1, 10 or 40 output tiles of 256 threads; every
block repeats the row's sums in the native kernel's exact order, so
its normed values and group sums keep the current bytes. A table by
the current device's SM and row count picks the tiles on sm_120 and
sm_121, every other call keeps the one-block row, and the kernel
registers with the contract as tf_rms_rows_sums' replacement.
tf_fn_rms_wide norms Flash Next's 10,240-wide bf16 MTP row in one
256-thread block, and its runtime kind branch serialises each
thread's forty loads. On gfx1201 the launcher now runs its two
fn_block_sum stages as two launches: tf_fn_rms_wide_waves stores
each wave's sum from the same thread chains and xor tree, and
tf_fn_rms_wide_apply adds a row's wave sums in order and stores y
over 160 groups a row, so the bytes stay the current kernel's. It
serves rows up to 16 with alternates on and registers with the
contract as tf_fn_rms_wide's replacement.
@ashhart
ashhart merged commit 421ac98 into ashhart:main Oct 31, 2026
8 of 9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

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

@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney! The faster Flash Next MTP head norm on CUDA and HIP is in 1.2.1: https://github.com/ashhart/TensorFold/releases/tag/v1.2.1

@laudney
laudney deleted the pr-rms-wide-tiles branch November 2, 2026 21:03
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.

Flash Next MTP wide norm: more blocks per row, byte-identical (CUDA tf_rms_rows_sums, HIP tf_fn_rms_wide)

2 participants