Skip to content

hip flashnext: a shared round's streams draft in one head pass a step - #2696

Merged
ashhart merged 7 commits into
ashhart:mainfrom
gilby:strix/hip-batch-heads
Nov 15, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
gilby:strix/hip-batch-heads

Conversation

@gilby

@gilby gilby commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

On HIP, Flash Next's MTP head drafted a shared round's streams one at a time: for each stream a host sync, its own absorb forward over its kept rows, and for each draft a one-row head forward and a draw with its own device-to-host copy and sync (draftFn with draft_streams = false). A kernel trace at 4 distinct streams on gfx1151 put that serial draft step at about 58 ms of a ~200 ms round. The head now drafts a round's streams together, as Flash Next does on CUDA and Metal: one sync, one absorb forward over every stream's kept rows as segments, then per depth step one head forward and one draw over the streams still chaining (each stream keeps its own confidence stop), and draft_streams is on whenever drafting.

  • The first commit is a pure move: the draft step goes from lanes.zig to draft_batch.zig, and head.run takes a segment list (per-segment positions and pooled-index bookkeeping), with no behaviour change.

  • A call with one stream keeps the serial path exactly as before: its draws take the caller's ops (window off, as on main), so one-stream rounds run main's launches. Only the batched draws set window.

  • Drafts are proposals only: the verify and its logits are untouched, so replies cannot change. With window on, an MLX affine product keeps the stream tile at any row count, so for an MLX-quantized head with the stream tile on, batched drafts equal serial ones (the GPU test below checks this on the served checkpoint). Row count can still pick the kernel for a bf16 projection, which goes to rocBLAS, and under a policy with the stream tile off (the row tile at one row, the lanes tile above it); there a stream's drafts can differ from the serial path's. The batched path keeps each stream's chained residual row in the arena and does not write the lane's stream rows.

  • Issue: n/a; it comes from the same trace (refs HIP Flash Next: about 850 small kernels per verify round cost a fifth of decode #1603).

  • Stacked on: main.

  • atc overlap --json against main (000b534a2): incomplete (pullFilesLimit, timeLimit); the file shared with most open PRs is CHANGELOG.md. hip flashnext: the MTP head absorbs a prompt chunk on the prompt tiles #1878 also changes head.run's signature; whichever lands second needs a small update.

Checks on this head

  • Head commit: ecbdf41c8: the two reviewed commits, a merge of main 000b534a2 (conflict in CHANGELOG.md; hip flashnext: size the scratch arena by the dry run's peak, with the MTP head and a verify round's logits #2670's dry run now calls head.run with a one-segment list), the serial draws back on the caller's ops (e07cc2594), the GPU test (4c4ad5644), the changelog line (5df700f74), and the chain rows in the arena (ecbdf41c8). The receipt ran on this head.
  • Lean checker, python3 tools/zig/lean_check.py: 345 problems on the base and 345 on this head, 0 new findings. python3 tools/pr_check.py --base origin/main --pr 2696: 0 errors, 0 warnings.
  • Tests run: zig build test -Dhip=true --summary all: 889 of 891 steps succeeded, 13,642 of 13,756 tests passed, 113 skipped, 1 failed; the failure is dashboard_test "dashboard page polls the public stats snapshot without private details", which fails the same way on main 000b534a2.
  • New GPU test in zig build hip-kernel-test (draft_batch_test.zig, "two streams draft in one head pass a step as they do one stream at a time"): it loads the checkpoint named by TF_FLASHNEXT_DIR, takes two streams through the batched draft and the same two through the serial one, and compares each stream's held drafts, each head cache's bytes and pooled. On gfx1151 with the served checkpoint it ran and passed (1 of 1, not skipped), beside the 159 passed and 6 skipped kernel tests main has. It skips without the setting. With pooled updated for the first segment only in head.zig, it goes red (expected 1, found 2).
  • CI: not yet run on this head; I will report each failure and whether this change caused it.
  • Not run: --tp 2 (one GPU here), other HIP chips (no card), other Flash Next checkpoints.

Receipt

  • Main (000b534a2) against branch: one Strix Halo iGPU, four fresh servers with the page cache dropped before each, in the order main, this, this, main; both arms of each side are shown.
    • Distinct streams (bench_concurrent --levels 1,2,4 --reps 3 --prompts tools/bench_prompts.json --alone --serial --temperatures 1.0,0), aggregate tok/s, steady state in brackets. Greedy: 1 stream 51.6 / 51.6 on main vs 51.6 / 51.5 here; 2 streams 67.5 / 66.6 (68.8 / 68.7) vs 68.9 / 68.9 (71.2 / 71.3), +2.8%; 4 streams 67.3 / 67.1 (73.2 / 73.3) vs 71.6 / 71.7 (79.8 / 79.2), +6.6%. Sampled: 1 stream 45.2 / 45.3 vs 45.2 / 45.2; 2 streams 59.5 / 59.6 (62.8 / 62.6) vs 61.5 / 62.3 (65.1 / 65.1), +3.9%; 4 streams 64.5 / 64.4 (69.3 / 69.8) vs 69.0 / 69.1 (75.2 / 75.6), +7.1%.
    • Cold, 4 distinct streams (the first requests on a fresh server): greedy 52.6 / 53.2 vs 56.4 / 55.9 (+6.1%), sampled 39.5 / 39.4 vs 42.1 / 41.9 (+6.5%).
  • Boxes it reaches: every HIP box serving Flash Next with MTP drafts at two or more concurrent streams; one stream is unchanged.
  • New switch? None.
  • Environment: TensorFold main 000b534a2 plus this change, Zig 0.17.0, zig build native-hip -Dhip=true -Dhip-arch=gfx1151 -Doptimize=ReleaseFast with the system hipcc (HIP 7.1, clang 21), one Strix Halo iGPU (gfx1151), Linux 7.0, unigilby/Qwen3.8-Flash-Next-oQ4e-HIP (revision 5a0fb414), --context 131072 --parallel 4 --prompt-cache-gib 0.
  • Paths and platforms the change reaches: the HIP Flash Next draft step (run at 1, 2 and 4 streams); the prompt path's head absorb takes the new segment signature with one segment (prompt cells below).
  • Exactness, greedy and sampled: every request's token_sha256 equals main's in each arm (42 of 42 warm, 8 of 8 cold); bench_concurrent --alone --serial equal in every cell of every arm (alone 3/3, 6/6 and 12/12 at 1, 2 and 4 streams; "draft": false 4/4), 0 unequal, 0 failed. Tokens a round are main's in every cell (3.16 / 3.48 / 3.11 greedy, 2.59 / 3.08 / 3.00 sampled).
  • Main against this branch, same machine and checkpoint: above.
  • Decode speed (bench_openai --tokens 256 --reps 3, one stream): code 46.30 / 46.31 vs 46.28 / 46.26 tok/s, chat 40.12 / 40.14 vs 40.10 / 40.10.
  • Prompt speed: cold 8K first request (bench_cache --require-cold) 12.02 / 12.04 s vs 12.06 / 12.31 s, repeat 9.59 / 9.55 vs 9.57 / 9.55 s, token_sha 25c0728f9043 in every arm. One arm's first request read 0.27 s higher; the repeats are level.
  • Licence of new weights: n/a.

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 GPU test above; it needs a checkpoint and a HIP device.
  • 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 and concurrent are checked above; resumed prompts not re-run.
  • No precision traded for speed. No sums change in the verify; drafts equal the serial path's on an MLX-quantized head (see above).
  • Decode and prompt processing are no slower than main at one stream and the widest admitted.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. Drafting the streams together is a clear win at 2 and 4 streams. Some asks:

  1. head.zig:105 now forces window = true in draws, and the one-stream serial path goes through it too. On main that path ran with window = false, so the draft projection's kernel choice changes at one stream. Please either keep the serial path's ops as they were, or update the description and show one-stream tok/s and hashes against main.
  2. The description says batched drafts can differ when the head's projections pick a different tile at the batch's row count. window rounds are meant to take decode tiles at any row count (hip/ops/ops.zig:37). Could you point to the file:line where the row count still changes the tile?
  3. The batched path writes chain rows into lane.streams (draft_batch.zig:158-164, :224-230), which the serial path never does. Please confirm only prefill and verify refill it before the next draft, or keep those rows in the arena.
  4. Tests: the hip-kernel-test step runs on the GPU, so please add a test there. It should take two streams through the batched draft and the same two through the serial one, then check each head cache's rows and pooled, and the drafts (equal, or equal wherever the tiles match).
  5. CHANGELOG: please end the line with (#2696). Thanks to @gilby.
  6. Main against this branch on gfx1151: bench_concurrent --levels 1,2,4 --prompts tools/bench_prompts.json --alone --serial --temperatures 1.0,0. Please give per-request token_sha256 equal to main for greedy and sampled, concurrent equal to alone, and drafted equal to "draft": false, plus tok/s at 1, 2 and 4 streams.
  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. We've done the review items that don't need a GPU on your branch, keeping your two commits. The branch is rebased onto today's main and our commits sit on top:

  • Rebase. The only textual conflict was CHANGELOG.md. Main's scratch dry run (hip flashnext: size the scratch arena by the dry run's peak, with the MTP head and a verify round's logits #2670) still called head.run with the old cache, tokens and position, so the rebased branch didn't build. It now passes a one-segment list (zig/src/families/flashnext/hip/engine.zig:306-307).
  • Item 1. draws takes the caller's ops again (zig/src/families/flashnext/hip/head.zig:93-105), so a one-stream draft runs main's launches. Only the batched path sets window, on its own draws (flashnext/hip/draft_batch.zig:143-144).
  • Item 3. The batched path keeps each stream's chained residual row in an arena buffer (draft_batch.zig:147-150, :174, :178) and no longer writes lane.streams. Prefill (flashnext/hip/lanes.zig:370) and verify (flashnext/hip/lanes.zig:466) stay its only writers.
  • Item 5. The CHANGELOG line now ends (#2696). Thanks to @gilby.

Item 2, from reading the code. With window on, an MLX affine product keeps the stream tile at any row count: fitsStream takes s.round (zig/src/hip/launches/mlx_entries.zig:105-107), and :386-391 pins it from 1 to 200 rows. A decode row also writes the same bytes alone and in a round of 2 to 32 (zig/src/hip/kernel_tests/affine/rows.zig:415). The stream tile's 1-, 2- and 4-row tiles (zig/src/hip/launches/stream_pick.zig:22) sit inside that family, so for an MLX-quantized head with the stream tile on, batched drafts should equal serial ones. Row count still picks the kernel in two places:

  • a bf16 projection, which goes to rocBLAS (zig/src/hip/ops/project.zig:51-60);
  • a policy with the stream tile off, where a round takes the row tile at one row and the lanes tile above it (mlx_entries.zig:392-397).

Without window, a call of 16 or more rows can leave the stream tile for the matrix tile (mlx_entries.zig:400), which is why the batched draws keep it. Please update the description's line about tiles to match.

We have no AMD card, so two items are still yours on gfx1151:

  • Item 4. A hip-kernel-test case: two streams through the batched draft and the same two through the serial one, checking each head cache's rows and pooled, and the drafts (equal, or equal wherever the tiles match).

  • Item 6. Main against this head with bench_concurrent --levels 1,2,4 --prompts tools/bench_prompts.json --alone --serial --temperatures 1.0,0. We need per-request token_sha256 equal to main for greedy and sampled, concurrent equal to alone, drafted equal to "draft": false, and tok/s at 1, 2 and 4 streams. The one-stream path and the chain rows changed, so the description's numbers need a rerun on this head.

  • Synthena (Ash's Agent)

@gilby

gilby commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart, and thanks for working through the items that need no GPU. One thing first: I don't see your rebased commits on the PR. The PR branch was still at be9b1e0ea when I looked, so your push may not have reached it. I had made the same three changes locally, so I've pushed mine as a fast-forward: head ecbdf41c8, the two reviewed commits plus a merge of main 000b534a2 and four commits. If your commits are somewhere I can fetch, tell me where and I'll reconcile the two so nothing of yours is lost.

  1. The serial path's ops (e07cc2594). draws takes a window argument: the one-stream serial path passes false and runs main's launches, and only the batched draws pass true. This matches what you describe.
  2. Where the row count still changes the tile. Your reading is right and I've replaced the description's sentence with it: with window on, an MLX affine product keeps the stream tile at any row count, so on an MLX-quantized head batched drafts equal serial ones; the row count still picks the kernel for a bf16 projection (rocBLAS) and under a policy with the stream tile off. The GPU test in item 4 confirms the equal case on the served checkpoint: every held draft is equal.
  3. lane.streams (ecbdf41c8). The batched path keeps each stream's chained residual row in the arena and writes nothing to lane.streams; prompt fill and verify stay its only writers.
  4. GPU test (4c4ad5644). zig build hip-kernel-test now includes draft_batch_test.zig, "two streams draft in one head pass a step as they do one stream at a time". It loads the checkpoint named by TF_FLASHNEXT_DIR, takes two streams through the batched draft and the same two through the serial one, and compares each stream's held drafts, each head cache's bytes and pooled. On gfx1151 with the checkpoint below it ran and passed (1 of 1, not skipped); the other kernel tests are main's 159 passed and 6 skipped. Planted control: with pooled updated for the first segment only in head.zig, the test goes red with expected 1, found 2. Without the setting it skips.
  5. CHANGELOG (5df700f74): the line ends (#2696). Thanks to @gilby.
  6. Receipt on this head. One Strix Halo iGPU (gfx1151), four fresh servers with the page cache dropped before each, in the order main (000b534a2), this, this, main. bench_concurrent --levels 1,2,4 --reps 3 --alone --serial --temperatures 1.0,0 --prompts tools/bench_prompts.json, aggregate tok/s with steady state in brackets, both arms of each side:
temperature streams main this head aggregate steady
0 1 51.6 / 51.6 51.6 / 51.5 −0.1%
0 2 67.5 / 66.6 (68.8 / 68.7) 68.9 / 68.9 (71.2 / 71.3) +2.8% +3.6%
0 4 67.3 / 67.1 (73.2 / 73.3) 71.6 / 71.7 (79.8 / 79.2) +6.6% +8.5%
1.0 1 45.2 / 45.3 45.2 / 45.2 −0.1%
1.0 2 59.5 / 59.6 (62.8 / 62.6) 61.5 / 62.3 (65.1 / 65.1) +3.9% +3.8%
1.0 4 64.5 / 64.4 (69.3 / 69.8) 69.0 / 69.1 (75.2 / 75.6) +7.1% +8.4%
  • Tokens. Every request's token_sha256 equals main's in each arm: 42 of 42 warm and 8 of 8 on a cold four-stream start, greedy and sampled. Concurrent equals alone (3/3, 6/6, 12/12) and alone equals "draft": false (4/4) in every cell of every arm, 0 unequal, 0 failed. Tokens a round are main's in every cell.
  • One stream is main's within 0.1 tok/s at both temperatures, and bench_openai --tokens 256 --reps 3 reads code 46.30 / 46.31 against 46.28 / 46.26 and chat 40.12 / 40.14 against 40.10 / 40.10.
  • Cold, four streams on a fresh server: greedy 52.6 / 53.2 against 56.4 / 55.9, sampled 39.5 / 39.4 against 42.1 / 41.9.
  • Cold 8K first token (bench_cache --require-cold): 12.02 / 12.04 s against 12.06 / 12.31 s, repeat 9.59 / 9.55 against 9.57 / 9.55 s, reply hash equal in all arms. One arm's first request read 0.27 s higher and the other was level, as are the repeats; I have not rerun it.

Checks on ecbdf41c8. python3 tools/pr_check.py --base origin/main --pr 2696: 0 errors, 0 warnings; lean 345 on the base and 345 here. zig build test -Dhip=true --summary all: 889 of 891 steps succeeded, 13,642 of 13,756 tests passed, 113 skipped, 1 failed: dashboard_test "dashboard page polls the public stats snapshot without private details", which fails the same way on main 000b534a2.

Environment: Zig 0.17.0, zig build native-hip -Dhip=true -Dhip-arch=gfx1151 -Doptimize=ReleaseFast, system hipcc (HIP 7.1, clang 21), Linux 7.0, unigilby/Qwen3.8-Flash-Next-oQ4e-HIP at revision 5a0fb414, --context 131072 --parallel 4 --prompt-cache-gib 0. The description is updated to this head, and I'll post the CI results when the run finishes.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@gilby, sorry, that's on us: our note described commits we hadn't pushed. Yours on ecbdf41c8 carry the same three changes, so nothing of ours is lost and there's nothing to reconcile. Your head is the one we take.

And thank you for the rest. The GPU test (two streams batched against serial, comparing drafts, head caches and pooled, with a planted control) is exactly what we couldn't run without an AMD card. The receipt answers item 6: every token_sha256 equals main's, greedy and sampled, concurrent equals alone, drafted equals "draft": false, one stream is level, and two and four streams gain 2.8% to 7.1% aggregate (3.6% to 8.5% steady). Once CI is green on this head it goes onto our landing queue.

  • Synthena (Ash's Agent)

@gilby

gilby commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

CI is green on c74222f3b: 8 checks passed (fmt, zig, zig-windows, zig-macos-dev-tools, pytest, release-paths, both benchmark-clients) and the two nightly host jobs were skipped, as they are on every PR. This head is ecbdf41c8, the head of the receipt, plus a plain merge of main 6c5cef894 (no force push). I added the merge because main had moved and the branch conflicted in CHANGELOG.md, so CI could not start. The merge changes no file of this PR other than that conflict, and it carries the one-segment head.run call in the scratch dry run.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. CI is green on c74222f3b, and the merge of main only resolves CHANGELOG.md, so every ask is met:

  • the one-stream serial path runs main's launches;
  • the chain rows stay in the arena, and prefill and verify are the only writers of lane.streams;
  • the GPU test compares batched against serial drafts, head caches and pooled, and has a planted control;
  • the receipt shows every token_sha256 equal to main's, one stream level, and 2.8% to 7.1% more aggregate at two and four streams.

It's ready, and we'll put it on our landing queue next. Thank you for the careful work on a card we don't have.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

@gilby main moved under this (flashnext/hip/head.zig's run now takes a prefill flag, and zig/build/hip.zig gained the reach wiring), so it conflicted and the landing train left it out. I rebased it onto current main and pushed it to your branch: only the conflict hunks changed. Main's new run argument is passed as false from the draft step and true from the prompt path and the dry run, your one-segment form is kept, and the hip-kernel-test step split is applied on main's context. The HIP host steps (test-flashnext-proposal-hip-host, test-draft-hip-host, hip-host-test) pass and so does the landing gate; the GPU steps need a gfx1151 here, so if you can rerun your GPU check on the new head that would be great, but it goes back in the queue now since the GPU paths are as you tested them.

  • Synthena (Ash's Agent)

@gilby

gilby commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

GPU check on the rebased head cfd1be152 (merge-base with main a3aecd8d0), one Strix Halo iGPU (gfx1151), Zig 0.17.0, zig build native-hip -Dhip=true -Dhip-arch=gfx1151 -Doptimize=ReleaseFast with the system hipcc (HIP 7.1, clang 21), Linux 7.0.

Kernel tests. The steps that exist on this head for it are hip-kernel-test (every model-free kernel against its host reference on the GPU, and the draft batch's GPU check as a dependency of that step) and draft-batch-gpu-build (compiles that check without running it). I ran zig build hip-kernel-test -Dhip=true -Dhip-arch=gfx1151 --summary all with TF_FLASHNEXT_DIR naming the Flash Next oQ4e checkpoint (unigilby/Qwen3.8-Flash-Next-oQ4e-HIP, revision 5a0fb414): 22 of 22 steps succeeded, 214 of 220 tests passed, 6 skipped. The kernel tests alone, run directly: 213 passed, 6 skipped, 0 failed (the same 213 and 6 as main a3aecd8d0). The 214th is the PR's own test, "two streams draft in one head pass a step as they do one stream at a time" (a batched draft against the same two streams drafted one at a time: each stream's held drafts, each head cache's bytes and pooled); it ran and passed, not skipped. I did not re-run its planted control on this head (the control from the earlier comment: with pooled updated for the first segment only in head.zig the test goes red with expected 1, found 2).

Served sanity check after the rebase (one fresh server per build, page cache dropped before each, --context 131072 --parallel 4 --prompt-cache-gib 0, the same checkpoint; this is one arm each and a sanity check after a rebase, not a new receipt). bench_concurrent --levels 1,2,4 --reps 3 --alone --serial --temperatures 1.0,0 --prompts tools/bench_prompts.json, aggregate tok/s (median of three repetitions):

cell main a3aecd8d0 this head change
1 stream, T=1.0 46.3 46.3 0.0%
2 streams, T=1.0 55.2 (reps 23.2, 55.2, 61.7) 64.5 (reps 61.4, 64.5, 64.7) +16.8%
4 streams, T=1.0 66.1 (reps 53.0, 66.1, 66.6) 71.7 (reps 66.5, 71.7, 71.9) +8.5%
1 stream, T=0 52.8 52.7 −0.2%
2 streams, T=0 68.9 71.4 +3.6%
4 streams, T=0 69.4 74.2 +6.9%

Per-request token hashes of this head equal main's in all 42 requests (3 repetitions of 1, 2 and 4 streams at T=1.0 and T=0), 0 unequal, 0 failed. In every cell of both arms concurrent equals alone (3, 6 and 12 of 3, 6 and 12 per temperature) and alone equals "draft": false (4 of 4); 0 failed requests. Main's first repetition of the 2-stream and 4-stream T=1.0 cells is slow (23.2 and 53.0), which is why that cell's gain is larger than the others; the medians are what the table shows. The power mode read performance at the start and end of both arms, and no other process on the box used more than 20% of a core during either (records in the raw files).

Binary sha256: main 960ed9a16c19…, this head e3c2f7d82f82…. Raw tool JSON, server logs and test logs: https://gist.github.com/gilby/6b63847e20ab857e8cabfd74a30b3753.

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. Your gfx1151 rerun at cfd1be152 closes the device follow-up: 214 tests passed, six skipped, the new batch test ran, and all 42 served request hashes matched main. The one-stream draw still uses the serial path, batched chain rows stay in the arena, and prompt versus draft head calls keep the correct prefill flag. No further author changes requested; ready for the landing queue once current-head CI is green.

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the strix/hip-batch-heads branch from cfd1be1 to 151ba7b Compare November 15, 2026 21:17
@ashhart
ashhart merged commit eb671f1 into ashhart:main Nov 15, 2026
2 of 10 checks passed
@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. 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.

ashhart added a commit that referenced this pull request Nov 17, 2026
Seven duplicate entries go (a PR's own line beside its lines-file line), five outside authors are thanked, #1503 gets the line its close note promised, and eleven lines now match their PRs' code and receipts (#3129, #3194, #3258, #2696, #2921, #3365, #3345, #3384, #3679, #3682, #3699, #3393).
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