Skip to content

native hip: skip dead-row stream folds on gfx1151 single-round routed 4-bit 3-4 row items (stacked on #3774) - #3559

Merged
ashhart merged 7 commits into
ashhart:mainfrom
gilby:strix/k2-stream-item-rows
Nov 20, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
gilby:strix/k2-stream-item-rows

Conversation

@gilby

@gilby gilby commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

On Strix Halo (gfx1151), single-round (K <= 1024, single_round_k = 32 * 32) plain fp32-output routed 4-bit stream launches whose largest item holds 3 or 4 rows set Routing.item_rows = 1, so rows past an item's count skip the epilogue lane fold in stream_body (zig/kernels/hip/tiles/stream.hpp) while writing identical bytes to item_rows = 0. Multi-round (K > 1024) and fused epilogues (pair, relu2, fp16 output) keep item_rows = 0: work() already skips dead-row dot work, so rounds >= 2 already amortize the epilogue fold below 2% while shifting small-window cost ratios in lanes/depth.zig. Limiting to single-round plain routed 4-bit plans leaves 339 of the 341 dot2_tiles functions unchanged (gfx1151 plain stream tile 4-bit 4x2 and 4x4 add 0 VGPRs and +1 SGPR each, with 0 extra HIP 7.1 limit lines).

  • Issue: Refs HIP: a routed stream tile that skips the lane fold of an item's dead rows (gfx1151), proposed gate before a PR #3305 (settles the four device-evidence items agreed there).
  • Stacked on: native hip: size RDNA3.5 MoE lane plans to window rows and pool rising row steps #3774 (6315cdc37, which sizes RDNA3.5 lane-round routed MoE plan buffers to exact window rows and pools rising added-row window costs within four-row regimes). Adds 180f52497 (12-file code commit, tree-identical to qualified b4fe2f74e outside CHANGELOG.md) and 0c43cd0d6 (CHANGELOG.md).
  • atc overlap --json: incomplete (complete: false, API/PR limits) across 15 changed files against main. Across all 100 open PRs on GitHub against the 12 code files changed in #3559: 0 overlap zig/kernels/hip/** or zig/src/hip/launches/**; 8 touch docs/kernel-contract.md or zig/tests/hip/contract_main.zig (#3575, #3613, #3676, #3689, #3694, #3734, #3735, #3736), and 29 touch CHANGELOG.md only. git merge-tree --write-tree origin/main b4fe2f74e (code changes on 8cbef9777) merges cleanly (0 conflicts); git merge-tree --write-tree origin/main HEAD conflicts in CHANGELOG.md only.

Checks on this head

  • Head commit: 0c43cd0d6 (180f52497 code plus 0c43cd0d6 changelog), stacked on #3774 (6315cdc37) on main 3f1290ffe. All GPU binaries, kernel contract runs, microbenches, and #2984 served benchmarks ran on b4fe2f74e (git diff b4fe2f74e 180f52497 -- ':!CHANGELOG.md' is empty).
  • Lean checker, python3 tools/zig/lean_check.py, on the base (6315cdc37 and 3f1290ffe) and on this head: 221 and 221, 0 new findings. python3 tools/pr_check.py --base 6315cdc37 --pr 3559: 0 error(s), 0 warning(s). python3 tools/pr_check.py --base 3f1290ffe --pr 3559: 0 error(s), 0 warning(s). Upstream publish check across 3f1290ffe..HEAD: clean. zig fmt --check: clean across all changed Zig files.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test test-kernel-contract test-golden fuzz-cortheon --summary all on RDNA3.5 host: 756/758 steps succeeded (762/777 tests passed, 14 skipped, 1 pre-existing failure in stage_hip_test.test.every staged call on HIP memory equals the reference, whole and in parts, matching main).
    • zig build test -Dhip=true --summary all on RDNA3.5 host: 769/771 steps succeeded (576/591 tests passed, 14 skipped, same pre-existing stage_hip_test failure).
    • Direct unit tests on macOS host (zig test on zig/src/hip/root.zig): 119/119 passed (stream_pick, stream_variant, moe, etc.).
    • zig build hip-kernel-test -Dhip=true -Dhip-arch=gfx1151 --summary all: 22/22 steps succeeded (224/231 tests passed, 7 skipped, 0 failed; #3774 base had 220/227 passed, 7 skipped, 0 failed — the +4 new tests are stream_pick, stream_variant, and affine/items.zig checks).
    • New tests and how each goes red:
      • Host test (stream_pick.zig and stream_variant.zig): covers every chip in Caps, widths 2..8, rows 1..64, k in {512, 640, 1024, 1056, 1856, 2048, 2688}, dense and routed, plain vs fused (pair/relu2). Removing or m > 4 fails launches.stream_variant.test.item_rows stays off ... at stream_variant.zig:48 (TestUnexpectedResult) and launches.stream_pick.test.only RDNA3.5's single-round ... at stream_pick.zig:107 (expected .none, found .items). Removing or k > single_round_k fails stream_variant.zig:53 (TestUnexpectedResult) and stream_pick.zig:107 (expected .none, found .items).
      • Device test (zig/src/hip/kernel_tests/affine/items.zig): covers windows of 1..8 random rows, 16 and 17 rows with cap=4, and 8 rows at cap=4 vs cap=5 across all 6 served routed shapes (Lightning fc1/fc2, Flash Next gate+up/down, Qwen3.6-35B-A3B gate+up/down), checking byte equality against item_rows = 0 and against each pair alone, with random inputs plus -0/+inf/-inf/NaN planted in x, scales, and biases. Removing or m > 4 in stream_pick.zig fails with Flash Next down: largest item 5 of cap 5, item_rows true; removing or k > single_round_k fails with Lightning fc2: largest item 4 of cap 4, item_rows true; moving the Routing.item_rows fold exit one row early (row0 + r + 1 >= a.m in tiles/stream.hpp) fails with item rows: 1279488 words differ from the tile, 1279488 from each pair alone across 15 Flash Next down and Qwen3.6-35B-A3B down cases (random and special).
  • CI: no checks reported yet on strix/k2-stream-item-rows.
  • Not run, and why: gfx1030, gfx1100, and gfx1201 hardware (no such cards; the stream_pick host test and hip-kernel-contract-limits check those generations). Qwen3.8-27B was not served: it is dense (num_experts defaults to 0, checkpoint reader returns .dense at zig/src/families/qwen3_5/config.zig / checkpoint.zig) and cannot reach a routed launch.

Receipt

  • Main against branch: 0 two-series losses (LOSSES_TOTAL=0) across all 64 cells (16 cells x 4 routed MoE checkpoints) both stacked (#3559 vs #3774) and cumulative (#3559 vs main) under #2984's noise rule. Full Group 2 (merged12.md, served12.md, rerun12.md), Cumulative (cum12_merged.md, cum12.md, cum12_rerun_L4.md), narrowed microbench (mb-k2n-v6.txt), and runners: https://gist.github.com/gilby/0afb93436834f38d94c67fb674ddb3dd.
  • Boxes it reaches: single-round (K <= 1024) plain fp32-output routed 4-bit launches (Routing.item_rows) on RDNA3.5 (gfx1151) holding 3 or 4 rows in their largest item: Flash Next down (K = 640, group 32) and Qwen3.6-35B-A3B down (K = 512, group 64).
  • New switch? None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: TensorFold b4fe2f74e (code-identical to 180f52497) vs #3774 (a4f62edf5 / 6315cdc37) and main (3f1290ffe), with #3242 (be9fe6237) merged onto both arms for Lightning oQ4e only. Zig 0.17.0, HIP 7.1 runtime, one Strix Halo (Radeon 8060S, gfx1151, 128 GB unified, stock 12.3 GiB reserve via env -u TENSORFOLD_MEMORY_RESERVE_GIB, performance power mode). Checkpoints: Qwen3.8-Flash-Next oQ4e; Nemotron 3.5 Lightning 30B-A3B MLX 4-bit; Qwen3.6-35B-A3B MLX 4-bit with MTP; Nemotron 3.5 Lightning oQ4e (user3892 r4).
  • Paths and platforms the change reaches, which I ran and which I could not: ran routed 4-bit MoE paths of flashnext, qwen3_5 MoE, and nemotron on gfx1151, plus host rule tests and contract limits over gfx1030/gfx1100/gfx1151/gfx1201; could not execute on gfx1030/gfx1100/gfx1201 GPUs (verified off in stream_pick.variant and stream_variant.Table.load).
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: 57/57 token_sha256 equality, alone [42, 0], serial [24, 0] in every arm and rerun across all 4 checkpoints for both stacked (#3559 vs #3774) and cumulative (#3559 vs main, including CK2_L4).
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): 1-discard then base/head/head/base on fresh servers (--context 131072 --parallel 4 --prompt-cache-gib 0, page cache dropped each arm); bench_openai --tokens 256 --reps 3, bench_concurrent --levels 1,2,4 --reps 3 --alone --serial --temperatures 1.0,0, bench_cache --require-cold at 2K/8K/32K. Any single-series SLOWER cell got one full rerun series per #2984:
    • Stacked (#3559 vs #3774): Lightning stock 4-bit had 1 first-series flag (openai fibonacci-raw T0 -0.93%/-1.53%), passing on rerun (+1.60%/+0.29%); Lightning oQ4e had 1 first-series flag (conc T1 x4 -1.16%/-1.22%), passing on rerun (+0.37%/-0.87%). Flash Next gained >=2% on cold 8k ttft_s (+13.82%/+3.27%) and stayed +0.87% to +1.89% across solo/OpenAI cells. Result: 0 two-series losses.
    • Cumulative (#3559 vs main): Lightning stock 4-bit had 1 cross-series flag (openai gpu-chat-no-think T0 -4.50%/-4.11%); dedicated 5-arm CK2_L4 rerun passed (+3.67%/+0.03%). Qwen3.6-35B-A3B kept all 10 >=2% decode gains (+2.58% to +15.68%). Result: 0 two-series losses.
  • Decode speed before and after, from tools/bench_openai.py (in tok/s; full bench_concurrent and bench_cache decode tables in the gist):

Stacked (#3559 vs #3774, Group 2 — 0 two-series losses):

checkpoint cell #3774_1 #3559_1 #3559_2 #3774_2 pair 1 pair 2 rerun pair 1 / pair 2 verdict
Qwen3.8-Flash-Next oQ4e fibonacci-raw T1 49.51 50.26 49.88 49.40 +1.51% +0.98% - within the rule
Qwen3.8-Flash-Next oQ4e gpu-chat-no-think T1 38.37 38.36 38.47 38.13 -0.03% +0.89% - within the rule
Qwen3.8-Flash-Next oQ4e fibonacci-raw T0 50.22 50.90 50.97 50.23 +1.36% +1.47% - within the rule
Qwen3.8-Flash-Next oQ4e gpu-chat-no-think T0 43.49 43.78 43.82 43.51 +0.67% +0.70% - within the rule
Nemotron 3.5 Lightning 4-bit fibonacci-raw T1 115.81 116.97 117.50 117.06 +1.00% +0.37% -0.07% / -0.12% within the rule
Nemotron 3.5 Lightning 4-bit gpu-chat-no-think T1 91.60 92.41 90.27 92.32 +0.89% -2.23% +0.09% / +1.13% within the rule
Nemotron 3.5 Lightning 4-bit fibonacci-raw T0 124.50 123.34 122.61 124.52 -0.93% -1.53% +1.60% / +0.29% passes on rerun
Nemotron 3.5 Lightning 4-bit gpu-chat-no-think T0 98.33 94.76 94.82 94.81 -3.63% +0.02% -3.50% / -3.58% slower on rerun only: passes
Qwen3.6-35B-A3B MLX 4-bit fibonacci-raw T1 108.00 108.66 108.74 108.09 +0.61% +0.60% - within the rule
Qwen3.6-35B-A3B MLX 4-bit gpu-chat-no-think T1 105.09 105.04 105.04 105.76 -0.05% -0.69% - within the rule
Qwen3.6-35B-A3B MLX 4-bit fibonacci-raw T0 128.31 128.87 128.93 128.23 +0.43% +0.54% - within the rule
Qwen3.6-35B-A3B MLX 4-bit gpu-chat-no-think T0 100.07 101.09 101.07 99.98 +1.02% +1.09% - within the rule
Nemotron 3.5 Lightning oQ4e (+#3242) fibonacci-raw T1 96.09 96.07 96.06 96.07 -0.02% -0.01% +0.09% / +1.76% within the rule
Nemotron 3.5 Lightning oQ4e (+#3242) gpu-chat-no-think T1 83.27 84.05 81.63 81.31 +0.93% +0.39% +1.68% / +0.38% within the rule
Nemotron 3.5 Lightning oQ4e (+#3242) fibonacci-raw T0 112.26 112.37 112.32 112.26 +0.10% +0.05% +0.08% / +0.11% within the rule
Nemotron 3.5 Lightning oQ4e (+#3242) gpu-chat-no-think T0 90.81 90.19 90.29 90.86 -0.68% -0.62% +0.05% / +0.02% within the rule

Cumulative (#3559 vs main, LOSSES_TOTAL=0): Qwen3.8-Flash-Next (fib T1 +1.41%/+0.80%, chat T1 +0.44%/+0.41%, fib T0 +1.35%/+1.52%, chat T0 +0.66%/+0.73%), Lightning stock 4-bit (fib T1 -0.76%/+0.44%, chat T1 -1.22%/-1.71%, fib T0 +0.25%/-0.30%, chat T0 -4.50%/-4.11% -> rerun CK2_L4 +3.67%/+0.03%), Qwen3.6-35B-A3B (fib T1 +2.98%/+3.11%, chat T1 +4.82%/+4.88%, fib T0 +3.34%/+3.45%, chat T0 +15.68%/+5.96%, plus conc T1 x2 +6.81%/+6.72%, conc T0 x1 +3.93%/+3.93%, conc T0 x2 +4.58%/+3.97%, cold 2k +6.80%/+6.94%, cold 8k +5.35%/+5.44%, cold 32k +3.18%/+2.58%), and Lightning oQ4e +#3242 (fib T1 -0.98%/+0.02%, chat T1 +3.88%/+0.57%, fib T0 +0.12%/+0.04%, chat T0 -0.73%/-0.61%).

Narrowed microbench (mb-k2n-v6.txt, warm per-launch microseconds, single-round plain routed 4-bit shapes where CB4 is picked):

shape (picked: CB4) m=3 random m=3 shared m=4 random m=4 shared m=5 random m=8 random m=16 random m=17 random
Flash Next down (2560x640, K<=1024) 171.86 -> 141.32 (-17.8%) 171.75 -> 140.66 (-18.1%) 226.90 -> 187.44 (-17.4%) 222.53 -> 183.51 (-17.5%) 281.21 -> 232.33 (-17.4%) 443.00 -> 367.20 (-17.1%) 843.28 -> 705.89 (-16.3%) 890.79 -> 745.55 (-16.3%)
Qwen3.6-35B-A3B down (2048x512, K<=1024) 69.79 -> 64.14 (-8.1%) 68.28 -> 63.76 (-6.6%) 89.41 -> 83.73 (-6.3%) 85.29 -> 81.02 (-5.0%) 109.77 -> 102.77 (-6.4%) 166.88 -> 157.86 (-5.4%) 302.78 -> 288.30 (-4.8%) 321.07 -> 305.35 (-4.9%)
  • Prompt speed before and after (bench_cache --require-cold ttft_s): in stacked Group 2 (#3559 vs #3774), all 12 cold ttft_s cells stay within or faster than #2984: Flash Next 8K gains (10.887 -> 9.565 +13.82%, 9.583 <- 9.896 +3.27%), 2K (3.225->3.259 -1.04% / 2.975<-2.962 -0.43%), 32K (-0.39%/-0.18%), and across Lightning 4-bit, Qwen3.6-35B-A3B, and Lightning oQ4e all pairs lie between -0.99% and +1.08%. Cumulative (#3559 vs main) cold ttft_s has 0 losses (-0.70% to +1.42%, except Flash Next 2K single-pair -8.15% / +0.62% within rule).
  • Licence of any new weights or drafter, or "n/a": n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: hip affine_dot2_stream item-rows (4-bit, group 64, fp32 out) and hip affine_dot2_stream item-rows (4-bit, group 32, fp32 out) (zig/tests/hip/contract_stream_items.zig), gated inside stream_body (tiles/stream.hpp) via Routing.item_rows rather than adding separate _items kernel entry points. Each replaces affine_dot2_stream with item_rows off on the same plan and Gate 3 (shapes) checks byte equality (worst 0.000 of the bound) at served single-round routed shapes (3x2048x512, 4x2048x512, 3x2560x640, 4x2560x640).
  • A planted control for each new kernel, and each one fails as planted: "control: the item-rows tile with every item one row short" (tf_ctl_items_short_plain_2 and tf_ctl_items_short_plain_4 in zig/kernels/hip/contract_controls.hip) is red at Gate 3 (shapes) on both specs (differing from byte 49152 at 3x2048x512 and from byte 61440 at 3x2560x640).
  • Each backend's SUMMARY line and exit status (gfx1151):
    • Built with ROCm 10.1 hipcc: SUMMARY gfx1151 164 kernels: 164 pass gates 1-4, 0 fail, 2 known findings; 45 controls: 45 red as planted, 0 missed; 2 limit problems; gates 371256 ms, limits 2272 ms, exit 1 (identical 2 pre-existing limit problems tf_moe_combine_gate and tf_vl_resize as main and #3774).
    • Built with HIP 7.1 hipcc: SUMMARY gfx1151 164 kernels: 164 pass gates 1-4, 0 fail, 2 known findings; 45 controls: 45 red as planted, 0 missed; 175 limit problems; gates 379290 ms, limits 2270 ms, exit 1 — identical 175 limit problems as #3774 / main (0 extra HIP 7.1 limit lines). Under HIP 7.1, the two changed plain stream tile 4-bit variants report 126/124 (4x2) and 184/182 (4x4) VGPRs against their ROCm 10.1 records, the same HIP 7.1 register delta already on main; gating via Routing.item_rows inside stream_body avoided spawning 6 separate _items symbols.
    • zig build hip-kernel-contract-limits -Dhip=true -Dhip-relax-branches=true with ROCm 10.1: FAIL kernel-contract-limits: 30 problems (1230 log lines, identical count to #3774/main). Comparing all 1230 lines shows only gfx1151 plain stream tile 4-bit 4x2 (124 VGPRs, SGPRs 71 -> 72) and 4x4 (182 VGPRs, SGPRs 73 -> 74) updated in zig/src/core/contract/hip_records_stream_plain.zig, with 0 VGPR, LDS, or scratch changes on any kernel or chip.
  • Chips I could not run: gfx1030, gfx1100, and gfx1201 (ROCm 10.1 compiler records checked on all 4 chips via hip-kernel-contract-limits; rule keeps item_rows = 0 off RDNA3.5).

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.
  • 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.
  • No precision traded for speed. The bits are unchanged.
  • 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.

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 18, 2026
@gilby
gilby force-pushed the strix/k2-stream-item-rows branch from 23c4159 to 0c43cd0 Compare November 18, 2026 06:39
@gilby gilby changed the title native hip: gfx1151's routed 4-bit plans skip the lane fold of an item's dead rows native hip: skip dead-row stream folds on gfx1151 single-round routed 4-bit 3-4 row items (stacked on #3774) Nov 18, 2026
@gilby
gilby marked this pull request as ready for review November 18, 2026 07:01
@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby, and for settling #3305's device items with a full main-against-branch receipt.

  • The gate is narrow: stream_variant.Table sets item_rows only on RDNA3.5, and only for single-round (K <= 1024) plain fp32-output routed 4-bit launches whose largest item has 3 or 4 rows (stream_pick.variant). Other generations, multi-round launches and the fused epilogues keep item_rows = 0, and the host tests walk every chip, width, row count and K you list.
  • Same bytes: in stream_body, a skipped row is one past the item's count, and your device test (affine/items.zig) compares the outputs byte for byte against item_rows = 0, with -0, ±inf and NaN planted. Your 57 token hashes agree across every arm.
  • The affine.zig line joins keep that file under 600 lines.

One thing on order: this branch is stacked on #3774, which is not on main yet. Its diff therefore also carries #3774's two changes: exact plan rows for RDNA3.5 lane rounds (moe.planRows) and the pooled window costs (costs.poolWindowRows). This lands after #3774, so nothing for you to change for that.

It applies to current main apart from the CHANGELOG line, which we settle when it lands. Before landing it still needs CI green at this head and a device check on gfx1151.

  • Synthena

@ashhart
ashhart force-pushed the strix/k2-stream-item-rows branch from 0c43cd0 to ff7f656 Compare November 19, 2026 02:04
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

gilby and others added 7 commits November 20, 2026 05:37
…, not synthetic percentages

# Conflicts:
#	CHANGELOG.md
… with the thank-you

Drop the older synthetic M5 Max line that the served-results line replaced and the blank line it left before 1.2.9, and end the kept line with "Thanks to @gilby." as ashhart#2973's line and main's lines for his work do.

# Conflicts:
#	CHANGELOG.md
@ashhart
ashhart force-pushed the strix/k2-stream-item-rows branch from ff7f656 to ee47661 Compare November 20, 2026 05:37
@ashhart
ashhart merged commit 2cee7d9 into ashhart:main Nov 20, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 20, 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.

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