Repository navigation
nvfp4 experts: Flash Next decode rows in equal waves, two warps a unit for one row - #1351
Conversation
|
I measured the dispatch between classic, waves and half on GB10 for M = 1..16 (spread, mixed and hot routing, with and without the shared slot, cold L2, median of 50 replays x 3 repeats, 4 and 1 warps a CTA). Half wins whenever every half unit fits (M=1: -7 %, and still -2 to -8 % at smaller plans); its edge is exactly 2 x active units <= resident warps, +19 % one point past it, so that rule stays. Waves only pays when the plan spills past one wave (M=4 spread -9 %, M=8/16 mixed -5 to -7 %); on a plan that fits one wave it is identical work and cost +2 % on gate-up in the hot case (M=2/3, 95 -> 97 us). The M=2 161.6 -> 162.2 in the table is noise (+0.3 %, spread 0.5 %). TF_NVFP4_DECODE_WARPS 1 vs 4 is within +-1 % on the same grids, so the default stays. So pick() now returns the classic kernel while items x blocks fit one wave and no half fit applies (Flash Next rows 2 and 3); everything else is unchanged, same bits (768/768 sweep, kernel contract 343/343). Served decode 1/2/4/8 streams is flat within noise (2+2 alternating), so I do not claim a served gain. |
|
Review against main e9b69ed. The wave split covers every unit exactly once, and the half kernel's sums and output columns match the classic kernel's. The gap is in the contract: its fixture has 4 experts and at most about 480 units against 768 resident warps, so the waves kernel never runs a second wave there, and the byte-equality check only exercises the case that is identical to the classic kernel. The served 4-row case (780 units) is covered only by your sweep. Please add a contract shape that forces at least two waves, and register the 1-warp instances that |
|
Both are in a8683df, contract only. No kernel or dispatch change. Two waves. The waves kinds' served shapes gain a 1,024-row shape: 2,048 pairs over 4 experts make at least 128 items of 16 pairs. That is 2,560 or more gate-up units and 10,240 or more down units, against 768 resident warps on GB10, so gate-up runs at least 4 waves and down at least 14. Gate 3 still compares the bytes with the classic kernel's at every shape. Two planted controls show the shape really needs a second wave. Each one runs the waves entry with the plan's item count cut to what one wave of its grid holds. The cut changes nothing at shapes that fit one wave, so a control can only go red where a later wave exists:
If a larger GPU ever holds the whole shape in one wave, these controls go green and the contract fails, instead of passing without testing the later waves. 1-warp instances. All seven kernels that Results on GB10 (sm_121):
|
|
Thank you for the two-wave shape and the 1-warp kinds. Both are what we asked for, and the controls that go red only Before we can run it on device, the branch needs a rebase. Main's K32 prompt work ( Two smaller points. First, |
|
Thanks for checking the half kernel term by term. Rebased on main
Checks: lean 0 new; |
|
Thanks for the quick rebase, and for keeping main's One ask before the device run:
After that we'll run Flash Next FP4 with MTP at |
|
Thanks, that was a real bug. Fixed in
Checks: |
|
Thanks @jschmied, that's the fix we asked for. On a merge with current main, these all pass: Next we'll run it on device:
For the new dispatch to stay on by default, we still need a served gain at 1 and 2 streams, so we'll take speed rounds there against main. |
|
Thanks @jschmied. First device results, from a GB10 with Qwen3.8-Flash-Next FP4-Local, your two commits on main
That's a small gain, but in the right direction. Still to run on our side: the kernel contract for the decode kinds (the two-wave shape and its controls, and the limits at every SM), Flash Next with MTP drafts at |
…t for one row The decode form's units go out in equal waves: past the resident grid, ceil(units / waves) warps run and the rest leave, so no wave is a short tail (gate-up at four rows had 12 units left over a 768-warp grid). When every half unit fits the grid (one row's eleven items), two warps share a unit's 32 columns. A plan that fits one wave and no half fit (Flash Next rows 2 and 3) keeps the classic kernel, where waves cost 2 % and gain nothing. Each output keeps the same mma sequence over the same K order and epilogue: the bits do not change. A plan with no items returns before it divides by its waves. cuda_nvfp4_tile.run keeps main's run(k, pt, ...): prompt tiles take the K32 tile or runFact as before, decode tiles (pt == 16) take experts_waves.run. Its dispatch test expects the half, classic and waves kernels by plan size, with the classic kernel's arguments. The contract's nvfp4 group (contract_nvfp4_tile.Group) loads the decode kernels at 4 warps (the baseline, whatever the environment says) and at 1, and holds every kind: the waves, half and 1-warp instances TF_NVFP4_DECODE_WARPS=1 selects, byte-compared with the 4-warp classic kernel, with a 1,024-row two-wave shape and two controls cut to one wave that go red only there, then the K32 tile's kinds. The classic kernel is untouched (same SASS); only the four waves instances change with the early return. Launch records for nvcc 13.0, and a 13.2 set for the six 1-warp instances it compiles differently. GB10 gate-up: -6 % at one row, -11 % at four, -2 % at five and eight; down -1.5 % at four and five.
…ident warps pick judged both the half test and the one-wave test against the half kernel's resident warps. The one-wave test decides whether the classic kernel holds every unit in one wave, so it now reads that kernel's residency (resident[0] gate-up, resident[1] down). Their registers differ: with TF_NVFP4_DECODE_WARPS=1 a four-row gate-up plan fit half's warps and kept classic's tail wave; at 4 warps one-row down was judged against half's 768 warps. A pick test with unequal residencies covers both and fails on the previous pick.
|
Thanks @jschmied, this is merged. What we ran on our side:
Thanks for the careful kernel work, and for the unequal-residency test. |
|
Thanks @jschmied: the NVFP4 decode waves shipped in TensorFold 1.1.9. |
Flash Next's routed experts at decode rows (16-pair items,
nvfp4_expert_kernel) run behind Humming on GB10. At one row gate-up is 21 % slower, and at four rows 20 % slower. This PR fixes two causes without changing a bit:nvfp4_expert_wavesdeals the units in equal waves instead: ceil(units / waves) warps run and the rest exit at once. A plan with no items returns before the division.nvfp4_expert_halfgives a unit's 32 columns to two warps of 16 columns each.Every output keeps the same per-16 mma from zero, the same
fmafinto its sum in ascending K, the same global scale and the same epilogue. The classic kernel's SASS is unchanged, so Nemotron and GLM are untouched. Only the four waves instances changed SASS in the rebase, from the zero-items return. Only Flash Next's decode tile routes toexperts_waves.run:cuda_nvfp4_tile.run(k, pt, ...)keeps main's signature and K32 prompt path, and takesexperts_waves.runforpt == 16.GEMM time on GB10 (top-10 of 512 experts, cold L2, median of 50, µs)
Row 2 now takes the classic kernel, so its 161.6 -> 162.2 is the same kernel within noise (spread 0.5 %). The rest of the gap to Humming is Humming's stream-K, which splits K. Splitting K would change the summation order, so this PR does not use it.
Served decode
Flash Next FP4 with MTP drafting at 1, 2, 4 and 8 streams (fresh servers, 2+2 alternating) is flat within noise against main. I do not claim a served gain. Every decode text is identical between the arms, and TTFT is unchanged. The GEMM-level gain at one and four rows is real, but too small a share of a served step to clear run-to-run noise.
Gates
contract_nvfp4_tile.Group). The group loads the decode kernels at 4 warps (the baseline, whatever the environment says) and at 1. Besides main's prompt-tile and K32 kinds, it holds:TF_NVFP4_DECODE_WARPS=1selects;zig build testpasses (including the tile dispatch test, which now expects half, classic and waves by plan size with the classic kernel's arguments); lean check 0 new.