Repository navigation
perf(hip): a routed prompt plan keeps the shared expert whole, and gfx1151 takes the GEMM tile from 33 rows - #3521
Conversation
|
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.
|
e1d840c to
3fa055c
Compare
|
Thanks for the review. Both asks are on a new head, 3fa055c. The branch is rebased on
|
| 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 becausemaindrew 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.
|
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.
|
3fa055c to
35df790
Compare
|
I trial-merged 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 allGit also merged this tree cleanly with #4207 and #2490 in separate trials. The #2490 combination still hits the previously reported For a device rerun, the first check I would carry forward from the author's receipt is Igor Lessio - AIFLOW LABS |
…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.
35df790 to
cbc586e
Compare
|
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. |
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_routetakes 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 keeptile_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, andcapacityis 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 setsprompt_block_from = 33: a prompt pass's routed plan cuts at the GEMM tile from 33 rows.tile_forreads 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_routeruns 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.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-kernelsreadsrouted prefill over a plan: 1-256 kp3onmainand 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).main25de9d7. Three commits: d54171b (shape 1), 31fae4d (gfx1151's start) and 3fa055c (the contract entry).atc overlap --json(2026-11-17 02:39Z, basemain25de9d7): incomplete (the repository's pull-request limits). The one overlap it reports is hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight #2490, which shareszig/src/hip/kernel_tests.zigandzig/tests/hip/contract_main.zig; it merges clean with this branch. My open perf(hip): score the planned decode walk at d = 256 without element tests #3508 also editszig/tests/hip/contract_main.zig; the two branches merge clean with each other.The asks on #3161 and the review
tf-qwen35-test hiddenon the 35B-A3B with 1,064, 1,080 and 1,087 tokens (last pieces of 40, 56 and 63 rows):mainwhole,mainat--cut 1024and this branch at--cut 1024are byte-equal (fef76e440304,3f048fc9d5a3,52c3e4dc1c55). The served token hashes equalmain's in every timed cell below.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_routeruns 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.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 (anOpswith neither switch), and for a lane round.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.main, decode at 1 and 4 streams with MTP on, and the 27B as a control: under Receipt.kernel_tests/affine/product.zig) and the tuner'sroutedShapeplan as serving does, with the card's start.Checks on this head
main25de9d7. Both sides of every line below were built fromgit archivetrees.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.zig build test test-golden -Dhip=true --summary all: this head passed 10,569 of 10,650, with 79 skipped and 2 failed;mainpassed 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, ...) andstage_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 inmoe.zig, one intuning.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).
prompt_block_fromon gfx1151), the kernel suite read 220 passed, 6 skipped, 3 failed: exactly the three new tests. The plan test failedexpected 128, found 8, the host ruleexpected 128, found 8, and the table testexpected 33, found null.expected 33, found 8) and its host rule (expected 128, found 8).zig build hip-kernel-contracton gfx1151 with ROCm 10.1's hipcc,mainagainst this head:tf_moe_route's. The two controls readat 40x257x9: item 147 field 2 is 8, the plan's 40 (expert 256, ...)(the shared expert cut at the routed tile) andat 40x257x9: item 0 field 2 is 8, the plan's 29 (expert 0, ...)(a prompt planned from 64 where the start is 33).mainprints 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-limitswith ROCm 10.1's hipcc:moe route tf_moe_routeis 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 oftf_moe_combine_gateandtf_vl_resizewith this toolchain, already onmain.zig fmt --check build.zig zigandgit diff --check: both pass.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:
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-kernelswith 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_fromis 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:
/dev/kfd.Qwen3.6-35B-A3B-MLX-4bit-MTPandNVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, each with its MTP head, andQwen3.8-27B-MLX-4bit. No drafter.main25de9d7 and 3fa055c for every line.Paths and platforms the change reaches, which I ran and which I could not:
Exactness, from
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:tf-qwen35-test hidden, 35B-A3B, 1,064, 1,080 and 1,087 tokens:mainwhole,mainat--cut 1024and this branch at--cut 1024are byte-equal (fef76e440304,3f048fc9d5a3,52c3e4dc1c55: sha256 of the.npyof final-norm rows, 2,048 wide).token_shaequal tomain'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 --serialat--parallel 4, three servers a side (and six more a side for the 35B-A3B): token hashes equal tomain's on every server; every alone reply equal to its concurrent one and the"draft": falsereplies equal, 0 failed.9f2923ac14d0(code) anda8c28b8297b4(chat).60defcdbd7ab(code) and0b14844d0632(chat).2cbda70e0639(code) andded27583c51f(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_concurrentabove, 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 ofmain's.mainThe 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 onmain'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:mainmainResumed first token, 35B-A3B, at
--context 34816 --parallel 1 --prompt-cache-gib 4,ttft_sin 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.mainmainCold 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.
mainNemotron: 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:
mainResumed first token, as the 35B-A3B's (kept at 1,024 tokens, 10 repeats):
mainmainRaw logs and summaries, with the chains that ran them: a secret gist, https://gist.github.com/AbrahamCete/69cde9feb0d6cbc96837d46647d411b0 (local paths read
$LAB,$MODELS,$WTand$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 tomain's at 40, 56 and 63-row last pieces. The served token hashes equalmain's in every cold, resumed and decode cell on the three checkpoints, a resumed prompt's hash equals its cold first request's, andbench_concurrent --alone --serialfound every alone reply and every"draft": falsereply 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
hiddenis byte-equal tomain's.)Decode and prompt processing are no slower than
mainat 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 ofmain; 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.)