Skip to content

perf(hip): a routed prompt plan keeps the shared expert whole, and gfx1151 takes the GEMM tile from 33 rows - #3521

Merged
ashhart merged 4 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-shared-expert-block-tile
Nov 20, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-shared-expert-block-tile

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Below 64 rows a routed prompt plan cut every expert into items of 8 pairs, the stacked shared expert too. The shared expert holds every row whatever the routing, so a prompt of N rows ran it as ceil(N / 8) items, each reading its weights again. Both shapes from #3161, as you asked, and the route planner under the HIP kernel contract, as the review asked:

  • perf(hip): a routed prompt plan never cuts the stacked shared expert below the GEMM tile (d54171b), every card. tf_moe_route takes the shared expert's id and a tile of its own. In a prompt pass (Ops.prefill, outside a lane round) the stacked shared expert is cut at the 128-row GEMM tile, so below 128 rows it is one item. The routed experts keep tile_for's rule. Decode, lane rounds and the MTP draft head keep the 8-row tile for every expert. tp ranks and Nemotron do not stack the shared expert, so they pass none. No buffer shape changes: an item already carries its own rows, and capacity is an upper bound at the 8-row cut.
  • perf(hip): on gfx1151 a prompt pass's routed plan takes the GEMM tile from 33 rows (31fae4d). gfx1151's tuning table sets prompt_block_from = 33: a prompt pass's routed plan cuts at the GEMM tile from 33 rows. tile_for reads it for prompt passes only, so decode, lane rounds and the MTP draft head keep the 8-row tile below 64 rows. The value serves only the chip the table is named after (tuning.promptBlockFrom). gfx1150, gfx1152 and gfx1153 share gfx1151's costs but keep 64, as do gfx1030, gfx1100 and gfx1201. A table without the field keeps 64.
  • test(hip): put the MoE route plan under the HIP kernel contract (3fa055c).
    • tf_moe_route runs as the engine launches it, in five modes: a prompt pass with the GEMM tile from 33 rows and from 64 rows, a prompt pass with no stacked shared expert, decode with the MTP draft head, and a lane round.
    • Gates 1 and 3 check every member and item exactly against the entry's own statement of the cut. Gate 2 repeats the launch behind guard bytes. Gate 4 has no sums; the entry's stated rule says why.
    • Two planted bad cuts go red at gate 3, one for each of the two commits above.
    • Its launch record holds ROCm 10.1's usage on every served chip.

In both perf commits, the routed launches' m stays the most rows an item holds (itemRowsFor). The K-parallel tiers that do not loop cover only m rows of an item and fit by it (tierTakes). The registry ignores m when it prices a routed prompt plan, so the kernel chosen does not change: on the 35B-A3B, tf-qwen35-test check --explain-kernels reads routed prefill over a plan: 1-256 kp3 on main and on this branch.

Size: 726 lines (+638/-88) in 15 files: d54171b 296 (+217/-79, it also moves the route tests to kernel_tests/route.zig), 31fae4d 192 (+144/-48), 3fa055c 322 (+319/-3).

The asks on #3161 and the review

  1. Both shapes in one pull request, the 33-row start only on gfx1151 and only for prompt passes: the first two commits.
  2. The byte comparison at 40, 56 and 63 rows, plus the hidden check. tf-qwen35-test hidden on the 35B-A3B with 1,064, 1,080 and 1,087 tokens (last pieces of 40, 56 and 63 rows): main whole, main at --cut 1024 and this branch at --cut 1024 are byte-equal (fef76e440304, 3f048fc9d5a3, 52c3e4dc1c55). The served token hashes equal main's in every timed cell below.
  3. A plan test that pins the items a 33 to 63 row prompt gets, and a test that decode still gets the 8-row tile.
    • Kernel suite, kernel_tests/route.zig, a 33 to 63 row prompt plan: every expert whole where the GEMM tile starts at 33, routed 8-row items at 64.
      • tf_moe_route runs on the device for the 35B-A3B's 256 + 1 experts at 33, 40, 56, 63, 64 and 130 rows and Flash Next's 512 + 1 at 41. The picks are skewed so some routed experts hold more than 8 pairs.
      • With the start at 33 (gfx1151) every expert is one item from 33 to 127 rows. With it at 64 the routed experts are cut into 8-pair items below 64. The shared expert is one item on both.
      • Each item is checked (expert, first, count), and the launch's m equals the most rows an item holds.
      • The same picks under decode and the MTP draft head (neither switch) and a lane round get the 8-row tile for every expert below 64 rows, the shared one too.
    • Host, moe.zig, a card's start moves a prompt pass's GEMM tile to 33 rows; decode, lane rounds and the MTP draft head keep 64: the rule and the launch's m at ten row counts from 2 to 128, for a prompt pass at 33 and at 64, for decode and the draft head (an Ops with neither switch), and for a lane round.
    • Host, tuning.zig, only gfx1151 starts a prompt's routed GEMM tile below 64 rows, and only on that chip: 33 on gfx1151, none on gfx1150, gfx1152, gfx1153 and the other tables.
  4. The timing tables on current main, decode at 1 and 4 streams with MTP on, and the 27B as a control: under Receipt.
  5. The launch m at the most rows an item holds: point 3 checks it on the device. The served fixture (kernel_tests/affine/product.zig) and the tuner's routedShape plan as serving does, with the card's start.
  6. The route planner in the HIP kernel contract, with its launch record (review): the third commit; details under Checks.
  7. Device evidence for the affected paths (review): Nemotron, the 35B-A3B and the 27B under Receipt, cold boundary cells included. Flash Next is not served here; see "Not run".

Checks on this head

  • Head commit: 3fa055c, on main 25de9d7. Both sides of every line below were built from git archive trees.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 on the base and 221 on this head, 0 new (tools/zig/lean_new.py). No file past 600 lines.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test test-golden -Dhip=true --summary all: this head passed 10,569 of 10,650, with 79 skipped and 2 failed; main passed 10,563 of 10,644, with 79 skipped and 2 failed. The same two fail on both, here only: cli_config_test (serve --config: expand reads the file, ...) and stage_hip_test (every staged call on HIP memory equals the reference, whole and in parts). The six extra tests are the three new host tests (two in moe.zig, one in tuning.zig), each in the two binaries that compile it. The suite also compiles the contract runner against stub kernels (check-hip-kernel-contract-host).

    • zig build hip-kernel-build, then its test binary, on gfx1151: with the system hipcc (-Dhip-device-lib=...), 223 of 229 passed, 6 skipped, 0 failed. With ROCm 10.1's hipcc: 223 passed, 6 skipped, 0 failed.

    • New tests, each failing before its change and passing after it (run on the commits before the rebase, which applied unchanged).

      • With the rule and the table stubbed (the start ignored, no prompt_block_from on gfx1151), the kernel suite read 220 passed, 6 skipped, 3 failed: exactly the three new tests. The plan test failed expected 128, found 8, the host rule expected 128, found 8, and the table test expected 33, found null.
      • The first commit's three tests were run the same way before its change: its route test's shared cases (the item slices differ), its plan test (expected 33, found 8) and its host rule (expected 128, found 8).
      • The contract entry's planted controls are its red cases. Each undoes one commit's rule and fails at gate 3.
    • zig build hip-kernel-contract on gfx1151 with ROCm 10.1's hipcc, main against this head:

      main  SUMMARY gfx1151 161 kernels: 161 pass gates 1-4, 0 fail, 2 known findings; 42 controls: 42 red as planted, 0 missed; 2 limit problems
      head  SUMMARY gfx1151 166 kernels: 166 pass gates 1-4, 0 fail, 2 known findings; 44 controls: 44 red as planted, 0 missed; 2 limit problems
      
      • The five extra kernels and two extra controls are tf_moe_route's. The two controls read at 40x257x9: item 147 field 2 is 8, the plan's 40 (expert 256, ...) (the shared expert cut at the routed tile) and at 40x257x9: item 0 field 2 is 8, the plan's 29 (expert 0, ...) (a prompt planned from 64 where the start is 33).
      • main prints 811 PASS and 46 FAIL lines, this head 827 and 48. The extras are the five entries' gates 1 to 3, the route's live limits line and its two controls. Every other PASS, FAIL, KNOWN and CONTROL line is the same, apart from gate 5's table line (242 registered launches against 241).
    • zig build hip-kernel-contract-limits with ROCm 10.1's hipcc: moe route tf_moe_route is current on gfx1030, gfx1100, gfx1151 and gfx1201 (63 VGPRs and 28 SGPRs, 64 and 27 on gfx1201, no static LDS and no scratch; the launch's dynamic LDS is 47,104 bytes at most). Both sides read the same 7 problems: stale records of tf_moe_combine_gate and tf_vl_resize with this toolchain, already on main.

    • zig fmt --check build.zig zig and git diff --check: both pass.

  • CI: runs on this head (e1d840c, the previous head, was 8 of 8 green with the 2 nightly jobs skipped).
  • Not run, and why:
    • gfx1030, gfx1100, gfx1201 and gfx1150/1152/1153: I have only gfx1151. Their start stays at 64, so on them only the first commit changes the plan. The contract's records cover all four served chips.

    • Flash Next end to end: its checkpoint is 113 GB, about 105 GiB of weights against the 116 GiB this machine's GPU can address, so it is not served here. What covers its path:

      • the contract entry at 512 + 1 experts: prompt passes at 33, 41, 63 and 64 rows with both starts, decode with the draft head at 8 and 41 rows, and a lane round at 41;
      • the device plan test at 41 rows;
      • the served fixture's 41- and 42-row Flash Next cases.

      It stacks its shared expert last and its prompt path sets Ops.prefill, the plan the 35B-A3B takes.

    • Sampled decode and a separate --drafter: decode keeps the 8-row tile; it ran greedy with each checkpoint's MTP drafts on.

    • --explain-kernels with the plan's real item count (HIP: below 64 rows a routed prompt plan cuts every expert into 8-row items, the shared one too; planned with the 128-row tile from 33 rows, Qwen3.6-35B-A3B's resumed first token is 7-16% sooner on #2878's head, same bytes #3161's last point): not in this pull request.

Receipt

  • Main against branch: the tables under "Prompt speed" and "Decode speed" below.

  • Boxes it reaches: gfx1151 (Strix Halo) serving a MoE on HIP: the 35B-A3B and Flash Next (both perf commits), Nemotron (the start only: its shared expert runs apart). Other cards: the first commit only.

  • New switch? Default, accepted values, profile row: no switch. prompt_block_from is a field of a tuning table (64 where unset, 33 on gfx1151), not a setting.

  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision:

    • Machine: Ryzen AI Max+ 395 (gfx1151), Ubuntu 26.04.1, Zig 0.17.0. One GPU process at a time. Each timing step started only after the GPU read 0% busy for 10 s and no process held /dev/kfd.
    • Builds and runs: hipcc with HIP 7.1.52801 and Ubuntu clang 21.1.8, ReleaseFast.
    • Contract, its limits and the second kernel-suite run: ROCm 10.1's hipcc with its own device library.
    • Checkpoints: Qwen3.6-35B-A3B-MLX-4bit-MTP and NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, each with its MTP head, and Qwen3.8-27B-MLX-4bit. No drafter.
    • Base and head: main 25de9d7 and 3fa055c for every line.
  • Paths and platforms the change reaches, which I ran and which I could not:

    • A routed prompt pass of 9 to 63 rows (the shared expert's cut, every card) and of 33 to 63 rows on gfx1151 (the routed experts' cut), whole prompts and the last piece of a long one. I ran the 35B-A3B (both commits) and Nemotron (the start).
    • Decode, lane rounds and the MTP draft head keep their plan. The 27B has no routed experts and is the dense control.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false:

    • tf-qwen35-test hidden, 35B-A3B, 1,064, 1,080 and 1,087 tokens: main whole, main at --cut 1024 and this branch at --cut 1024 are byte-equal (fef76e440304, 3f048fc9d5a3, 52c3e4dc1c55: sha256 of the .npy of final-norm rows, 2,048 wide).
    • Served cold and resumed prompts (below), every one of them: token_sha equal to main's, and each resumed request's equal to its cold first request's.
    • tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 0 --alone --serial at --parallel 4, three servers a side (and six more a side for the 35B-A3B): token hashes equal to main's on every server; every alone reply equal to its concurrent one and the "draft": false replies equal, 0 failed.
      • 35B-A3B: 9f2923ac14d0 (code) and a8c28b8297b4 (chat).
      • Nemotron: 60defcdbd7ab (code) and 0b14844d0632 (chat).
      • 27B: 2cbda70e0639 (code) and ded27583c51f (chat).
  • Main against this branch, same machine and checkpoint: all of it, below.

  • Decode speed before and after: decode keeps the 8-row tile. bench_concurrent above, aggregate tok/s, MTP drafts on, greedy, B C C B B C, median of 3 servers; the 35B-A3B's rows are a second chain with six servers a side. "Every run" compares each of this PR's servers with each of main's.

    checkpoint, cell main this PR change every run
    35B-A3B, code x1 123.2 123.1 -0.1% within the spread
    35B-A3B, code x4 235.9 236.1 +0.1% within the spread
    35B-A3B, chat x1 98.0 97.3 -0.7% within the spread
    35B-A3B, chat x4 202.6 203.5 +0.4% within the spread
    Nemotron, code x1 127.5 128.4 +0.7% within the spread
    Nemotron, code x4 247.6 252.9 +2.1% within the spread
    Nemotron, chat x1 100.9 100.5 -0.4% within the spread
    Nemotron, chat x4 204.1 202.6 -0.7% within the spread
    27B, code x1 14.4 14.4 +0.0% within the spread
    27B, code x4 46.3 46.3 +0.0% within the spread
    27B, chat x1 14.8 14.7 -0.7% within the spread
    27B, chat x4 45.9 45.8 -0.2% within the spread

    The 35B-A3B's code x4 is bimodal on both sides: of six servers a side, main's read 227.7, 229.5, 230.0, 241.8, 243.0 and 245.9 tok/s, and this PR's 227.7, 227.8, 229.3, 242.8, 243.3 and 244.8. The first chain's three a side happened to hold two high and one low on main's side and the reverse on this PR's, so its medians read 243.6 against 230.7 (-5.3%); the second chain was run to settle that cell. The other three cells were within the spread in both chains (the first read -0.3% to +0.0%).

  • Prompt speed before and after. Runs alternate B C C B B C, one fresh process or server a run, or that sequence twice where a cell has six a side. A cell is the median over the runs. Under "every run", "faster" or "slower" means every run of this PR beat, or lost to, every run of main.

    • Whole prompt pass, tf-qwen35-test prefill <model> 9 12 16 20 24 28 32 33 40 48 56 63 64 65 96 128, ms (the tool reports whole ms), three processes a side:

      rows 35B-A3B main this PR change every run 27B main 27B this PR change every run
      9 35 35 +0.0% within the spread 157 155 -1.3% within the spread
      12 38 38 +0.0% within the spread 158 152 -3.8% within the spread
      16 42 42 +0.0% within the spread 161 158 -1.9% faster
      20 51 51 +0.0% within the spread 238 240 +0.8% within the spread
      24 55 55 +0.0% within the spread 253 253 +0.0% within the spread
      28 61 61 +0.0% within the spread 325 325 +0.0% within the spread
      32 65 65 +0.0% within the spread 334 335 +0.3% within the spread
      33 84 76 -9.5% faster 286 286 +0.0% within the spread
      40 91 81 -11.0% faster 292 291 -0.3% within the spread
      48 99 85 -14.1% faster 295 296 +0.3% within the spread
      56 108 89 -17.6% faster 309 309 +0.0% within the spread
      63 114 92 -19.3% faster 312 312 +0.0% within the spread
      64 90 91 +1.1% within the spread 306 306 +0.0% within the spread
      65 92 93 +1.1% slower (rechecked below: level) 317 317 +0.0% within the spread
      96 107 107 +0.0% within the spread 341 342 +0.3% within the spread
      128 123 122 -0.8% within the spread 377 375 -0.5% within the spread
      • At 64 and 65 rows both sides plan every expert at 128, the shared one included, with the same launch m: the same launches. With three processes a side and whole-ms readings, a 1 ms step trips the rule both ways; the 27B's 16-row cell, a model with no routed plan, reads faster in every run.
      • Recheck with the same binaries, six processes a side, at 33, 63, 64, 65 and 96 rows:
        • 33 rows: 84 against 76.5 ms, -8.9%, faster in every run.
        • 63 rows: 117 against 93 ms, -20.5%, faster in every run.
        • 64 rows: 91 ms in all twelve runs.
        • 65 rows: 93 ms in all twelve runs but one, this PR's 92.
        • 96 rows: -0.9%, within the spread.
    • Resumed first token, 35B-A3B, at --context 34816 --parallel 1 --prompt-cache-gib 4, ttft_s in ms, three servers a side. A prompt of 1,056 to 1,088 tokens is sent once (cold), its state is kept at 1,024 tokens, and it is sent 10 times more. Each cell is a server's median over those repeats, then the median over the servers. 32 and 64 rows left are controls.

      rows left main this PR change every run cold first request, main this PR change
      32 77.3 78.0 +0.9% within the spread 561.6 562.9 +0.2%
      33 98.9 91.5 -7.5% faster 594.6 597.8 +0.5%
      40 104.6 91.1 -12.9% faster 620.1 604.7 -2.5%
      48 124.3 115.6 -7.0% faster 642.3 634.1 -1.3%
      56 125.8 104.9 -16.6% faster 641.9 625.6 -2.5%
      63 134.9 113.1 -16.2% faster 638.3 615.8 -3.5%
      64 110.8 111.1 +0.3% within the spread 629.2 628.3 -0.1%
    • Cold boundary cells, 35B-A3B, the same server settings: the cold first request of 1,056, 1,057 and 1,088 tokens (32, 33 and 64 rows past 1,024), six servers a side, each sent 4 distinct prompts a cell. Each cell is a server's median over its 4, then the median over the six. The old head's +1.8% at 32 rows was one request a server, with one outlier.

      rows past 1,024 main this PR change every run
      32 586.0 587.5 +0.3% (all 24 requests a side: +0.0%) within the spread
      33 597.2 591.3 -1.0% within the spread
      64 616.0 617.3 +0.2% within the spread
    • Nemotron: its shared expert runs apart, so only the 33-row start reaches it. Its 128 experts at top 6 rarely hold more than 8 pairs at these sizes, so the gain is small. Same server settings, six servers a side.

      • Cold prompts of 16 to 128 tokens, 4 distinct prompts a cell on each server:

        tokens main this PR change every run
        16 61.6 61.4 -0.2% within the spread
        32 97.1 96.4 -0.7% within the spread
        33 105.0 103.7 -1.3% within the spread
        40 114.9 113.9 -0.8% within the spread
        48 128.0 126.6 -1.1% within the spread
        56 138.6 136.8 -1.3% within the spread
        63 149.2 147.4 -1.2% within the spread
        64 149.3 149.0 -0.2% within the spread
        96 191.6 191.5 -0.0% within the spread
        128 230.9 231.0 +0.1% within the spread
      • Resumed first token, as the 35B-A3B's (kept at 1,024 tokens, 10 repeats):

        rows left main this PR change every run cold first request, main this PR change
        32 96.4 96.5 +0.1% within the spread 555.6 551.8 -0.7%
        33 107.4 106.8 -0.6% within the spread 579.4 578.2 -0.2%
        40 117.0 116.3 -0.6% within the spread 596.5 595.1 -0.2%
        48 128.8 127.8 -0.8% within the spread 611.5 609.3 -0.4%
        56 138.4 137.2 -0.9% within the spread 622.6 621.7 -0.2%
        63 151.9 150.5 -0.9% within the spread 628.5 629.3 +0.1%
        64 151.3 150.9 -0.3% within the spread 631.8 632.9 +0.2%
    • Raw logs and summaries, with the chains that ran them: a secret gist, https://gist.github.com/AbrahamCete/69cde9feb0d6cbc96837d46647d411b0 (local paths read $LAB, $MODELS, $WT and $SCRATCH).

  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack. (To tick on the pushed head.)

  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The plan test needs the GPU and runs in the kernel suite; the contract entry's planted controls go red at gate 3.)

  • 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. (A prompt pass's plan changes how its items are cut, inside the same launches.)

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Hidden states are byte-equal to main's at 40, 56 and 63-row last pieces. The served token hashes equal main's in every cold, resumed and decode cell on the three checkpoints, a resumed prompt's hash equals its cold first request's, and bench_concurrent --alone --serial found every alone reply and every "draft": false reply equal.)

  • No precision traded for speed. If the bits change, the description says which sums change and why. (The bits do not change: a prompt tile writes the same bits however a prompt's rows are cut into items, which the served fixture checks entry by entry, and hidden is byte-equal to main's.)

  • 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. (Every cell on the three checkpoints keeps every token. Once rechecked, no cell of this PR is slower in every run than every run of main; the 35B-A3B's 65-row whole pass read +1 ms in each of three processes a side, with the same launches on both sides, and read level at six a side. Prompt passes are faster from 33 to 63 rows on gfx1151 (35B-A3B whole pass -9.5% to -19.3%, resumed -7.0% to -16.6%; Nemotron -0.6% to -1.3%) and level elsewhere. The cold boundary cells are level with six servers a side. Decode is level at 1 and 4 streams, greedy, with the MTP drafts on. It keeps the 8-row tile, so I did not run sampled decode or a separate drafter.)

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @AbrahamCete. Both requested shapes are here, and the prompt-only gate leaves decode and lane rounds on their existing tiles. The hidden-row and served comparisons cover the 40-, 56- and 63-row tails.

Please add the changed route planner to the HIP kernel contract and its launch records. The separate plan tests are useful, but there is no backend contract entry for the planner. It needs exact member/item checks, repeat and guard checks, and a planted bad-cut control; floating-point-only checks can state why they do not apply. The added comments that run past one line are ours to fold, and we will.

HIP is hardware we do not run, so your runs on gfx1151 of the affected Flash Next and Nemotron paths, alongside the 35B-A3B and dense 27B control, are the device evidence: the new default must keep every token and show no repeatable slowdown, including the cold boundary cells. On our side we check that the CUDA and Metal paths stay unchanged.

  • Synthena

@AbrahamCete
AbrahamCete force-pushed the perf/hip-shared-expert-block-tile branch from e1d840c to 3fa055c Compare November 17, 2026 02:39
@AbrahamCete

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Both asks are on a new head, 3fa055c. The branch is rebased on main 25de9d7: the two commits applied unchanged (now d54171b and 31fae4d), and a third commit puts the route planner under the contract.

tf_moe_route in the HIP kernel contract

test(hip): put the MoE route plan under the HIP kernel contract (3fa055c): zig/tests/hip/contract_route.zig; its seven entries (five modes and two controls), registered in contract_main.zig; and the launch record in hip_records_router.zig.

  • What runs. tf_moe_route through Launcher.tf_moe_route, the launch serving makes (one block, its dynamic LDS), once for each mode in which the engine asks for a plan:

    • a prompt pass with the GEMM tile from 33 rows (gfx1151);
    • a prompt pass with the GEMM tile from 64 rows (every other card);
    • a prompt pass with no stacked shared expert (Nemotron's 128 experts, top 6, and 257 ids as a tp rank plans them);
    • decode with the MTP draft head;
    • a lane round.

    The launch takes its tiles from moe.zig's rules. The check compares against the entry's own statement of the cut: 8-row items below the start, 128 from it, and a prompt pass's stacked shared expert at 128. A change to the kernel or to the rule goes red.

  • Exact member and item checks (gates 1 and 3, by the entry's own check):

    • every member is its expert's pairs in pick order;
    • every item's expert, first and count equal the stated cut;
    • every slot past the plan names the last expert with no pairs.

    Shapes: the 35B-A3B's 256 + 1 experts at 9, 32, 33, 40, 56, 63, 64, 127, 128 and 130 rows; Flash Next's 512 + 1 at 33, 41, 63 and 64; Nemotron's 128 at 9 to 130. Edges add 2, 63, 64 and 65 rows, and 16, 255, 256 and 257 experts, where the kernel's 64 count segments become 16. Each row's picks are distinct, half of them from six hot experts, so some experts fill several 8-row items. Gate 1 crowds the picks at both ends of the id range.

  • Repeat and guard checks (gate 2): five runs byte-identical, the picks unchanged, the guard bytes around the picks, members and items intact, and no overlap.

  • Floating-point gates. The rule the entry states, printed at gate 1, says why they do not apply: "int32 ids in and out, nothing to be NaN, infinite or summed". Gate 3 compares exactly rather than against a float64 bound. Gate 4 reads N/A (accum = .none, with sums.why "integer ids and counts: there are no sums to round").

  • Planted bad cuts, both red at gate 3:

    • the stacked shared expert cut at the routed 8-row tile in a prompt pass (the first commit undone): at 40x257x9: item 147 field 2 is 8, the plan's 40 (expert 256, 128 pairs an item);
    • a prompt pass planned from 64 rows where gfx1151's start is 33 (the second commit undone): at 40x257x9: item 0 field 2 is 8, the plan's 29 (expert 0, 128 pairs an item).
  • Launch record moe route tf_moe_route: 256 threads, with dynamic LDS at the launcher's most (1,024 experts, 47,104 bytes). Its usage comes from zig build hip-kernel-contract-limits with ROCm 10.1's hipcc: 63 VGPRs and 28 SGPRs on gfx1030, gfx1100 and gfx1151, 64 and 27 on gfx1201, no static LDS and no scratch. The record is current on all four chips.

zig build hip-kernel-contract on gfx1151 with ROCm 10.1's hipcc, main against this head:

main  SUMMARY gfx1151 161 kernels: 161 pass gates 1-4, 0 fail, 2 known findings; 42 controls: 42 red as planted, 0 missed; 2 limit problems
head  SUMMARY gfx1151 166 kernels: 166 pass gates 1-4, 0 fail, 2 known findings; 44 controls: 44 red as planted, 0 missed; 2 limit problems

The five new kernels and the two new controls are the route's. main prints 811 PASS and 46 FAIL lines; this head prints 827 and 48. The extra PASS lines are the five entries' gates 1 to 3 and the route's live limits line; the extra FAIL lines are its two controls going red. Every other PASS, FAIL, KNOWN and CONTROL line is the same on both sides, apart from gate 5's table line, which counts 242 registered launches where main counts 241. hip-kernel-contract-limits reads 7 problems on both sides: the same stale records of tf_moe_combine_gate and tf_vl_resize with this toolchain, none of them the route's.

Device evidence on gfx1151

main 25de9d7 against this head:

  • Both built from git archive trees with the system hipcc (HIP 7.1.52801, clang 21.1.8), ReleaseFast.
  • One GPU process at a time. Each step starts only after the GPU reads 0% busy for 10 s and no process holds /dev/kfd.
  • Runs alternate B C C B B C, one fresh process or server a run, or that sequence twice where a cell has six a side.

Your gate, per cell: every token kept and no repeatable slowdown. I count a slowdown as repeatable when every run of this head is slower than every run of main. Every token is equal in every cell, with no error, no unequal alone reply and no unequal "draft": false reply. Once rechecked, no cell is slower in every run. One cell tripped the rule with three processes a side: the 35B-A3B's whole pass at 65 rows, +1 ms in each, where both sides run the same launches. At six a side it reads level (below). The full tables are in the refreshed description; the cells you named:

Nemotron-3.5-Lightning-30B-A3B (NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, MTP head on). Its shared expert runs apart, so only the 33-row start reaches it. Its 128 experts at top 6 rarely hold more than 8 pairs at these sizes, so the gain is small. Six servers a side for the prompt cells:

cell main this head change every run
cold prompt, 32 tokens 97.1 ms 96.4 ms -0.7% within the spread
cold prompt, 33 tokens 105.0 ms 103.7 ms -1.3% within the spread
cold prompt, 48 tokens 128.0 ms 126.6 ms -1.1% within the spread
cold prompt, 63 tokens 149.2 ms 147.4 ms -1.2% within the spread
cold prompt, 64 tokens 149.3 ms 149.0 ms -0.2% within the spread
cold prompt, 128 tokens 230.9 ms 231.0 ms +0.1% within the spread
resumed at 1,024, 32 rows left 96.4 ms 96.5 ms +0.1% within the spread
resumed at 1,024, 33 rows left 107.4 ms 106.8 ms -0.6% within the spread
resumed at 1,024, 63 rows left 151.9 ms 150.5 ms -0.9% within the spread
resumed at 1,024, 64 rows left 151.3 ms 150.9 ms -0.3% within the spread
decode, code x1 / x4 (tok/s) 127.5 / 247.6 128.4 / 252.9 +0.7% / +2.1% within the spread
decode, chat x1 / x4 (tok/s) 100.9 / 204.1 100.5 / 202.6 -0.4% / -0.7% within the spread

Cold prompts were 4 distinct prompts a cell on each server; the cold rows also cover 16, 40, 56 and 96 tokens, all within the spread. The resumed cells, kept at 1,024 tokens with 10 repeats, also cover 40, 48 and 56 rows left and each cold first request; all are within the spread.

35B-A3B, the same cells as before on the rebased main, three servers or processes a side:

  • Whole prompt pass at 33, 40, 48, 56 and 63 rows: -9.5%, -11.0%, -14.1%, -17.6% and -19.3%, faster in every run. Rows 9 to 32 and 96 to 128 are within the spread.
  • Resumed first token at 33, 40, 48, 56 and 63 rows left: -7.5%, -12.9%, -7.0%, -16.6% and -16.2%, faster in every run. The 32 and 64 controls read +0.9% and +0.3%, within the spread.
  • At 64 and 65 rows both sides run the same launches: every expert, the shared one included, is cut at 128. With three processes a side, 65 rows read 92 against 93 ms, slower in every run by the rule. Rechecked with six a side it is level: 64 rows read 91 ms in all twelve runs, and 65 rows 93 ms in all twelve but one (this head's 92). The recheck kept 33 and 63 rows at -8.9% and -20.5%.
  • Decode at 1 and 4 streams with MTP on, six servers a side: -0.7% to +0.4%, with tokens equal (9f2923ac14d0, a8c28b8297b4). code x4 is bimodal on both sides: three servers near 228 to 230 tok/s and three near 242 to 246 on each. With three a side, the first chain read -5.3% on that cell because main drew two fast servers and this head two slow ones.

Cold boundary cells, 35B-A3B: the cold first request of 1,056, 1,057 and 1,088 tokens (32, 33 and 64 rows past 1,024). Six servers a side, each sent 4 distinct prompts a cell; each value is the median of the servers' medians:

rows past 1,024 main this head change every run
32 586.0 ms 587.5 ms +0.3% (all 24 requests a side: +0.0%) within the spread
33 597.2 ms 591.3 ms -1.0% within the spread
64 616.0 ms 617.3 ms +0.2% within the spread

So the first receipt's +1.8% at 32 rows, one request a server, came from one server's outlier.

27B (dense, the control):

  • The whole prompt pass at 9 to 128 rows is within -3.8% and +0.8% of main, and no cell is slower in every run.
  • Its 16-row cell reads faster in every run (-1.9%) on a model with no routed plan. That is the noise floor of three processes a side with whole-ms readings.
  • Decode is level (-0.7% to +0.0%), and the tokens are equal (2cbda70e0639, ded27583c51f).

Flash Next

Not served here. Its checkpoint is 113 GB, about 105 GiB of weights against the 116 GiB this machine's GPU can address, and the box would have to stay nearly empty for the runs, so I left it out. What covers its path without the checkpoint, all green on this head:

  • The contract entry at its 512 + 1 shape: prompt passes at 33, 41, 63 and 64 rows with the GEMM tile from 33 and from 64; decode with the MTP draft head at 8 and 41 rows; a lane round at 41. Each is exact on every member and item.
  • The device plan test in the kernel suite (kernel_tests/route.zig, 41 rows over 512 + 1 experts), for both starts and for decode, the MTP draft head and a lane round.
  • The served fixture's 41- and 42-row Flash Next cases (kernel_tests/affine/product.zig), which plan with the card's start.

Its prompt path sets Ops.prefill and stacks its shared expert last, the same plan the 35B-A3B takes, which the tables above time. Anyone with the checkpoint on a gfx1151 box can run the same cells with the chain in the raw files.

Scripts, summaries and raw logs for everything above: https://gist.github.com/AbrahamCete/69cde9feb0d6cbc96837d46647d411b0.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. Both points are resolved.

The route planner is now under the HIP kernel contract with exact member and item checks, repeat and guard checks, and both planted bad cuts going red. The launch record and the gfx1151-only 33-row start are in place.

Your gfx1151 runs keep every token and show no repeatable slowdown on Nemotron or the 35B-A3B at the cells you named. The 65-row cell that tripped our rule at three servers a side reads level at six, including the cold boundary cells. Flash Next could not be served on that box, and its 512+1 contract cases and device plan test cover the same path.

This is ready to land.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged 35df790d8 into current main 210e3b0c5. The merge was clean and the Mac M5 Max host run with Zig 0.17.0 passed 227 tests with 2 skips, including a compile of the HIP contract runner with inert kernels:

zig build test-qwen35-hip-host test-native-hip-host hip-host-test \
  check-hip-kernel-contract-host -Dhip=true -Dcpu=apple_m1 -j5 --summary all

Git also merged this tree cleanly with #4207 and #2490 in separate trials. The #2490 combination still hits the previously reported prompt_tail.zig:63 compile error. With p.format() == .dense in that scratch tree, the same command passed 143 tests with 2 skips. #3521 by itself passes unchanged.

For a device rerun, the first check I would carry forward from the author's receipt is zig build hip-kernel-contract -Dhip-arch=gfx1151 -Dhipcc=/path/to/hipcc with ROCm 10.1 and its device library. Look for all five tf_moe_route entries passing and both bad-cut controls going red on the exact item/count check. My run covered host behavior and registration only.

Igor Lessio - AIFLOW LABS

AbrahamCete and others added 4 commits November 20, 2026 18:40
…below the GEMM tile

Below 64 rows a routed prompt plan cut every expert into items of 8
pairs, the shared expert too. The shared expert holds every row
whatever the routing, so a prompt of N rows ran it as ceil(N / 8)
items, each reading its weights again.

`tf_moe_route` now takes the shared expert's id and a tile of its own.
In a prompt pass (`Ops.prefill`, outside a lane round) the stacked
shared expert is cut at the GEMM tile, 128 rows, so below 128 rows it
is one item; the routed experts keep `tile_for`'s rule. Decode, lane
rounds and the MTP draft head keep the 8-row tile for every expert,
and tp ranks and Nemotron, which do not stack it, pass none.

The routed launches' m stays the most rows an item holds
(`itemRowsFor`): the K-parallel tiers that do not loop cover only m
rows of an item and fit by it. The registry ignores m when it prices
a routed prompt plan, so the kernel chosen does not change. The served
fixture and `routedShape` plan as serving does.

The route tests move to kernel_tests/route.zig.
… from 33 rows

A routed prompt plan cut its routed experts into 8-pair items below 64
rows on every card. On gfx1151 the 35B-A3B's plan of 33 or more rows
already runs on the 64-row routed tile, which takes an item of up to 64
rows in one block, so the 8-pair items only split each busy expert's
rows into more items.

gfx1151's tuning table now sets `prompt_block_from = 33`: the fewest
rows a prompt pass's routed plan cuts at the 128-row GEMM tile. It
serves only the chip the table is named after (`promptBlockFrom`), so
gfx1150, gfx1152 and gfx1153, which share the table's costs, and the
other cards keep 64. `tile_for` reads it for prompt passes only
(`Ops.prefill`): decode, lane rounds and the MTP draft head keep the
8-row tile below 64 rows. The launches' m stays the most rows an item
holds (`itemRowsFor`), and the fixtures plan with the card's start.

The bytes hold: a prompt tile writes the same bits however a prompt's
rows are cut into items, which the served fixture checks entry by
entry, and the routed launches still cover every row of every item.
tf_moe_route joins the contract as the engine launches it: a prompt pass
with the GEMM tile from 33 and from 64 rows, a prompt pass with no stacked
shared expert, decode with the MTP draft head, and a lane round. Gates 1
and 3 check every member and item exactly against the contract's own
statement of the cut, gate 2 repeats it behind guard bytes, and gate 4 has
no sums to check. Two planted controls go red at gate 3: the stacked shared
expert cut at the routed 8-row tile, and a prompt planned from 64 rows
where the GEMM tile starts at 33. Its launch record holds ROCm 10.1's usage
on every served chip.
@ashhart
ashhart force-pushed the perf/hip-shared-expert-block-tile branch from 35df790 to cbc586e Compare November 20, 2026 18:40
@ashhart
ashhart merged commit 9cced0f into ashhart:main Nov 20, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

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

3 participants