Skip to content

flashnext CUDA sampled draws: one launch and one wait a step, and #2753's check inside the top-k pass (#2920) - #2927

Merged
ashhart merged 6 commits into
mainfrom
lead/fn-cuda-batched-draws
Nov 14, 2026
Merged

ashhart merged 6 commits into
mainfrom
lead/fn-cuda-batched-draws

Conversation

@ashhart

@ashhart ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Fixes #2920. Three commits, in order.

  1. cuda: Flash Next refuses non-finite draft rows by name and never indexes past its ID table #2753's check inside fn_row_topk. The top-k pass flags a NaN of either sign or +Inf in its first pass. A bad row reports column -1, which the draw already refuses as ProposalNonfinite. Sampled verifies no longer run a separate fn_row_best pass and download just for the check; it remains for greedy rows and the full-row path. This commit alone is our candidate fix for 1.2.7's 0.3-0.5% slower sampled cells on a GB10.
  2. One launch and one wait for a shared verify's draws. On the one-GPU shared path, a verify group's rows get one best launch (if any stream is greedy), one top-k launch (for streams sharing a top_k), one wait and one download. Then they're checked and drawn stream by stream in today's order. Masked and non-usable streams, lone windows and TP=2 keep today's path.
  3. One launch and one wait per draft step. The active lanes' head rows are gathered, with one best and one common-K top-k launch, then the same per-lane picks.

TF_FLASHNEXT_BATCH_DRAWS=0 restores the per-stream reductions (commit 1's check stays), for an A/B in one binary. It accepts only 0 or 1 and refuses anything else by name. The head's new reduction buffers (a 25,600-byte verify region, plus a 2.5 MB draft score slab at 79,591 columns) are counted in the head's bytes and freed with it.

Exact: every row's draw is the same function on the same values, with its own seed and position, in today's order.

Tests: 41/41 focused tests on the recording device. Restoring the old extra verify pass, forcing serial verify draws, or forcing serial draft reductions each turns a runtime comparison red. Full CUDA host 6225/6264 (39 skipped), and the arm64 Linux CUDA tests compile.

Not yet checked on a device:

  • on a GB10, flashnext-mtp-parity, the fn_row_topk contract with the non-finite shapes, and kernel-contract-limits;
  • served bench_concurrent --alone --serial at 1-8 streams, greedy and sampled, with token hashes equal to main;
  • the A/B, with commit 1 alone against 1.2.7 at 1 and 8 streams sampled as the bisect.

Expected: sampled +0.3-0.8% at one stream and +1.5-3% at 4-8 streams.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Status on this head: the one red check was a test, not the change. Two of the new draw tests hand the draft a stack buffer of u16 (zig/src/families/flashnext/cuda_mtp_nonfinite_more_test.zig:294 and :354). On their serial side the draw reads the top-k columns as i32 from that buffer (zig/src/families/flashnext/cuda_mtp_draw.zig:80), so on Linux CI the eight-chain draft test stopped with "incorrect alignment". Production buffers come from the allocator at row scale and were never affected. The fix gives both test buffers align(4).

This head is also rebased on today's main. The one conflict was the environment test: main has since moved the Flash Next settings into their own scope and test file. TF_FLASHNEXT_BATCH_DRAWS stays in the CUDA scope with blank refused, and the generic test keeps both rules.

Still owed on a GB10 before this lands: flashnext-mtp-parity, the fn_row_topk contract with the non-finite shapes plus kernel-contract-limits (its record waits for fresh compiler usage), served 1-8 streams greedy and sampled with token hashes equal to main, and the A/B of the first commit alone against 1.2.7 at 1 and 8 sampled streams.

  • Synthena (Ash's Agent)

The serial side of the eight-chain draft test panicked with incorrect
alignment on Linux CI: candidates() reads the top-k columns as i32 from
the draft's u16 host buffer, and a stack [N]u16 is only 2-aligned.
Production host buffers come from the allocator at row scale.
@ashhart
ashhart force-pushed the lead/fn-cuda-batched-draws branch from 3592c10 to 246902a Compare November 14, 2026 14:21
@ashhart
ashhart merged commit d6c4cce into main Nov 14, 2026
2 of 10 checks passed
@ashhart
ashhart deleted the lead/fn-cuda-batched-draws branch November 14, 2026 14:21
ashhart added a commit that referenced this pull request Nov 14, 2026
… whole-buffer download

On the 1.2.9 release commit, one sampled stream of Flash Next (MLX 4-bit checkpoint, chat, temperature 1.0) decoded about 10% slower than 1.2.8 on a GB10: 48.7, 46.1 and 48.8 tok/s against 43.9, 44.3 and 42.2, alternating runs; the other sweep cells were level or faster. #2927's group path runs a top-k launch and a synchronous download of the whole batch buffer every draw step, which one stream cannot amortise. A lone stream now takes the per-stream draw it had before #2927; two or more streams keep the group draw. Tokens are unchanged either way: both paths draw the same rows, and the batch tests compare them.
ashhart added a commit that referenced this pull request Nov 14, 2026
… whole-buffer download

On the 1.2.9 release commit, one sampled stream of Flash Next (MLX 4-bit checkpoint, chat, temperature 1.0) decoded about 10% slower than 1.2.8 on a GB10: 48.7, 46.1 and 48.8 tok/s against 43.9, 44.3 and 42.2, alternating runs; the other sweep cells were level or faster. #2927's group path runs a top-k launch and a synchronous download of the whole batch buffer every draw step, which one stream cannot amortise. A lone stream now takes the per-stream draw it had before #2927; two or more streams keep the group draw. Tokens are unchanged either way: both paths draw the same rows, and the batch tests compare them.
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.

flashnext CUDA sampled draws: one launch and one wait a step, and #2753's check inside the top-k pass

1 participant