Repository navigation
perf(hip): on gfx1151 a plain prompt of 1 or 2 rows takes the 2-row K-parallel tile - #3273
Conversation
|
Thanks @AbrahamCete. The two-commit split, the planted faults and the 207M-point selection probe made this easy to review. I went through the full base..head diff and ran the host checks. Host review is clean: The selection change reads correctly. The Must-fixes: none. We haven't run the gfx1151 tile byte comparison, the token-hash comparisons or the prefill speed numbers ourselves yet, so those rest on your posted runs (Ryzen AI Max+ 395, HIP 7.1.52801, the two Qwen checkpoints). If you can, keep the gfx1151 kernel-test output and the B C C B B C token-hash table attached here. That is the last piece before merge.
|
|
Thanks. Here are the two pieces, from the runs in the description ( The gfx1151 kernel-test output on this head: t5f-ktest.log, the whole run: 219 passed, 6 skipped, 0 failed. The new test's line is Token hashes, B C C B B C. Three servers a side; each cell's hash is the same on all six:
A resumed prompt's hash also equals its own first, cold request's, on both trees. The per-run lines are in t5-35-summary.txt and t5-27-summary.txt in the same gist, and the byte comparison of the hidden states (1,025, 1,026 and 130 tokens, whole and cut) in t5x.out. |
A row said which products its entry takes by rows, items and pairs, and nothing about the weights' width. Timings on gfx1151 show a choice that turns with it: of the two K-parallel tiles a plain prompt of 1 row can run on, one is ahead on 2-bit and 3-bit codes and the other from 4-bit up. `max_bits` is the most bits a weight code holds for the row to take a product (0, the default: any). The registry's cost check refuses wider codes for plain products and plans alike. A bound that does not parse refuses its row instead of being ignored: - a bound that is no code width (2, 3, 4, 5, 6 or 8) stops the build of the table that writes it, naming the entry and the bound, where 7 or 9 would have read as "up to 6" or "any"; a row made by hand with such a bound takes no product. The registry and the kernel cases read the widths from one list, beside the row type; - `tuning.build` copies an entry's fields by name and dropped the ones the row type lacks, so a misspelled bound left its row taking every product. Such a field now stops the build, naming the entry and the field. Every field the four tables carry is the row type's. `hip-affine-tune` prints the bound with a row it proposes. No table sets the bound yet, so no choice changes. Refs ashhart#2923
…-parallel tile A plain prompt product of 1 or 2 rows ran on `kp0` (8 columns a lane set, 1 row a pass) on every card. On gfx1151 `kp3` (4 columns, 2 rows a pass) is ahead at 2 rows at every width, and at 1 row from 4-bit codes up; at 1 row of 2-bit or 3-bit codes `kp0` stays ahead. A resumed prompt ends in such a piece whenever 1 or 2 tokens follow the kept state. gfx1151's table now gives `kp0` one row of codes of at most 3 bits and `kp3` the other plain products of up to 2 rows. Costs stay as they were, so `kp0` keeps the products its row still takes and no row is shadowed. Nothing else is chosen differently: products of 3 rows and more, routed plans, decode and the other three tables keep their tiles. Both tiles are one template and write the 128-row tile's bytes. Tests: - launches: at every width gfx1151 picks `kp3` at 2 rows and, at 1 row, `kp0` for 2-bit and 3-bit codes and `kp3` from 4-bit up, with the matrix cores on or off; it keeps `kp1` and `kp2` past 2 rows and the reference tile with the dot2 GEMM tiles off; gfx1030, gfx1100 and gfx1201 still pick `kp0`. - tuning: gfx1151's bound is set, so a table that lost it fails. - kernel suite: `kp0`, `kp3` and the 128-row dot2 tile, launched by id whatever the card's table picks, write the same bytes at 1 and 2 rows, every width and group, fp32 and rounded into out16; an output left unwritten fails too. Refs ashhart#2923
7fb753d to
94d9906
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
On gfx1151 a plain prompt-path product of 1 or 2 rows ran on
kp0(8 columns a lane set, 1 row a pass), as on every card.kp3(4 columns, 2 rows a pass) is ahead there at 2 rows at every width and at 1 row from 4-bit codes up (#2923). gfx1151's table now sends those products tokp3; 1 row of 2-bit or 3-bit codes stays onkp0, which is ahead there. The bytes are the same.A prompt ends in such a piece whenever 1 or 2 rows are left after its last full chunk, and a resumed prompt whenever 1 or 2 tokens follow the kept state.
Two commits, as agreed on #2923:
feat(hip): a tuning row can bound the width of the codes it takes.max_bitson the tuning row: the most bits a weight code holds for the row to take a product (0, the default: any). The registry's cost check refuses wider codes, for plain products and plans alike. No table sets it in this commit, so no choice changes.tuning.buildstops the build on such a bound, naming the entry, so a table reports it where it is written; a row made by hand with one takes no product.tuning.buildcopied an entry's fields by name and dropped the ones the row type lacks, so a misspelled bound would have left its row taking every product. Such a field now stops the build, naming the entry and the field. This is a behavior change of the parser:mainbuilds with a stray field. Every field the four tables carry is the row type's.hip-affine-tuneprints the bound with a row it proposes.perf(hip): on gfx1151 a plain prompt of 1 or 2 rows takes the 2-row K-parallel tile. Two rows ofgfx1151.zon:kp0at.rows = 1, .max_bits = 3andkp3at.rows = 2, .items = 300, plain products allowed. Costs stay as they were, so no row is shadowed. The other three tables are untouched.Size: 187 lines (+183/-4) in 11 files.
kp0; onkp3a resumed first token is 18-24% sooner on Qwen3.6-35B-A3B and 48-64% on Qwen3.8-27B, same bytes #2923.mainf8dacd7, which has perf(hip): the routed prompt tile takes K-parallel passes for an item of few rows #2878. Two commits: 3efa029 (the bound) and 7fb753d (the rows).atc overlap --json(2026-11-13 23:05 UTC, on 7fb753d): incomplete (limitationsotherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), with no overlap among the pull requests it read. Its one conflict is with my own local branch for HIP: on gfx1151 the matrix-core prompt tiles are up to 2.9x slower on short passes when a weight row is 1,024, 2,048 or 4,096 bytes (K 2048, 4096, 8192 at 4-bit); 64 bytes of padding a row removes it #3001 (three files of the tuning tables), which rebases onto this one.mainhas moved 3 commits since (93d77e5); none touches these 11 files and the branch merges clean bygit merge-tree.The asks on #2923
kp3row only. Thekp2arm at 3-4 rows is out, with numbers: againstkp1there it reads 1.19 to 2.10 on 8-bit codes (slower in all 12 cells) and over 1.02 on 2-bit codes in 9 of 12.kernel_tests/affine/rows.zig) launcheskp0,kp3and the 128-row dot2 tile by id, whatever the card's table picks, and compares bytes at 1 and 2 rows: every width of the registry's own list, groups of 32, 64 and 128, two shapes, fp32 and rounded into out16; an output left unwritten fails too. 72 products on gfx1151.launches/mlx_entries.zig) pins the selection, below.affine_gemm_kp(about 170 lines, with records for four chips), I can add it here or after.main's on both checkpoints (Receipt).Registry.selecton the base and on the head: 207,028,224 points (every op and path;project prefillfully crossed over rows, widths, groups, alignments, items, pairs and all 32 environments).project prefill, plain,kp0tokp3: 2 rows at each of the six widths, and 1 row at 4, 5, 6 and 8 bits.tf-qwen35-test check --explain-kernelsdiffers in one line on both checkpoints:project prefill: 1-2 kp0 3-4 kp1 5-32 kp2 33-256 skewbecomes1-2 kp3 ....kp0and 1 row of 4-bit codes pickskp3, and walks every width.Checks on this head
mainf8dacd7. Both sides of every line below were built fromgit archivetrees.python3 tools/zig/lean_check.py, on the base and on this head: 341 on the base and 341 on this head, 0 new (tools/zig/lean_new.py).zig build test test-golden -Dhip=true --summary all: 754 of 754 steps, 10,048 tests passed, 79 skipped, 0 failed.zig build hip-kernel-build -Dhip=true -Dhip-arch=gfx1151and its test binary on gfx1151: 219 passed, 6 skipped, 0 failed. The new test is among the passed, at 72 products.zig build hip-host-test -Dhip=true: 80 of 80.an entry bounded by the codes' width takes no wider product, and none when its bound is no code width, and tuning,a field the row type lacks is found in an entry, so a misspelled bound stops the build instead of being dropped: both fail with only the declarations in place and pass with the check.gfx1151 takes the 2-row K-parallel tile for a plain prompt of 1 or 2 rows, the 1-row tile for 1 row of 2-bit or 3-bit codes, and the table test's line that gfx1151's bound is set: both fail on the bound commit and pass with the rows.a width bound that is no code width is told apart, so a table that writes one stops the build instead of taking nothing: it fails while the check accepts every bound and passes with it..max_bit = 3ingfx1151.zonstops the build:error: tuning: mlx.project.prefill.kp0 has a field no row has: max_bit..max_bits = 7there stops it too:error: tuning: mlx.project.prefill.kp0 bounds its codes at 7 bits, which is no width they come in.tiles/gemm_kp.hpp, every row of a pass reading the pass's first row: the kernel test fails at 2 rows namingkp3, fp32 and rounded.kp3in fp32 only; the rounded output hides it at that shape, which is why both are compared.hip-kernel-contracton gfx1151 with ROCm 10.1's hipcc: the sameSUMMARYon the base and on this head (161 kernels pass gates 1-4, 2 known findings, 42 controls red as planted, 2 limit problems). No kernel changes, so the contract section is deleted.zig fmt --check build.zig zigandgit diff --check: both pass.fmt,zig,zig-windows,zig-macos-dev-tools,release-paths,pytest,benchmark-clientson Ubuntu and Windows; the two nightly host jobs skip).--drafter: prompt processing is the only caller of the changed rows. Decode ran greedy, with the checkpoint's MTP drafts on.Receipt
Main against branch: the tables under "Prompt speed" below.
Boxes it reaches: gfx1151 (Strix Halo) serving any model on HIP whose prompt pass runs plain products: Qwen3.5, 3.6 and 3.8 (q/k/v, out, DeltaNet, the dense MLP, the MoE shared expert), Nemotron and Flash Next.
New switch? Default, accepted values, profile row: no switch.
max_bitsis a field of a tuning row (0 by default, 3 on gfx1151'skp0row), not a setting.Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision:
Qwen3.6-35B-A3B-MLX-4bit-MTP, with its MTP head, andQwen3.8-27B-MLX-4bit. No drafter.mainf8dacd7 and 7fb753d for every line.Paths and platforms the change reaches, which I ran and which I could not:
Ops.affineon the prompt path. I ran both Qwen checkpoints, 4-bit.Exactness, from
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:tf-qwen35-test hiddenover real text, both checkpoints: byte-equal tomain's at 1,025 and 1,026 tokens (whole, and cut at 1,024 so the last chunk is 1 and 2 rows) and at 130 tokens (whole, and cut at 64, 2 and 1 rows, so every row goes through the changed products).token_shaequal tomain's in every cell.tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 0 --alone --serialat--parallel 4, 3 servers a side: token hashes equal on every server (35B-A3B9f2923ac14d0anda8c28b8297b4, 27B2cbda70e0639andded27583c51f); 0 failed.Main against this branch, same machine and checkpoint: all of it, below.
Decode speed before and after: decode picks no prompt entry.
bench_concurrentabove, tok/s, B C C B B C, median of 3:mainPrompt speed before and after. Runs alternate B C C B B C, one fresh process or server a run; each cell is the median of 3.
Whole prompt pass,
tf-qwen35-test prefill <model> 1 2 3 4 64, ms:mainmainCold first token,
tools/bench_cache.py --require-cold --tokens 16at--context 34816 --parallel 1 --prompt-cache-gib 0,ttft_sin ms. 1,025 and 1,026 tokens leave a last chunk of 1 and 2 rows; 1,024 and 2,048 leave none.mainmainResumed first token at
--parallel 1 --prompt-cache-gib 4,ttft_sin ms. A prompt is sent once, its state is kept at 1,024 tokens, and it is sent 10 times more; each cell is the median over those repeats, then over the servers. 3 and 64 rows left are controls. The client is resume.py (it usestools/bench_concurrent.py'sstream); raw summaries, with the kernel sweep's: the same gist.mainmainKernel level, every width. A scratch probe (not committed) takes the tuner's place and times as it does: us a launch, the weight tables rotated over copies so every launch reads them from DRAM.
kp3againstkp0, least / median / most over the cells (the two Qwen checkpoints', Nemotron's and Flash Next's shapes, and 4096 x 2048 at groups of 32, 64 and 128):kp0)kp0)Where the margin is thin: 7 cells moved to
kp3read 0.95 to 0.98 with noise up to 3.9%, at 2 rows of 3-bit codes and on 8-bit codes; 5-bit and 6-bit rest on one cell each. None reads over 1.Licence of any new weights or drafter: n/a.
Notes for review
kp0. The alternative is a lower bound (min_bits) onkp3's row. An upper bound on the tile that keeps the narrow codes needs one field and leaves every other row as it reads today.main, so nothing new is launched.Registry.verifydoes not look at bounds.tuning.builddoes: a bound that is no code width stops the build. The table test pins that gfx1151's bound is set.Not in this PR
kp2at 3-4 rows (point 1).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 host tests fail before their change. The kernel test launches the tiles by id whatever the table picks, so it does not depend on the rows; it fails by name with each planted fault and runs only in the GPU suite.)
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 plain prompt product changes tile inside the same launch, not the engine's path.)
Drafted output equals
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Hidden states are byte-equal tomain's. The served token hashes equalmain's in every cold, resumed and decode cell, and a resumed prompt's hash equals its first, cold request's. Decode picks none of these rows; its hashes equalmain's at 1 and 4 streams with the MTP drafts on.)No precision traded for speed. If the bits change, the description says which sums change and why. (The bits do not change: both tiles are one template and write the 128-row tile's bytes, and a kernel test compares them byte for byte.)
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. (Prompts are level or faster in every cell measured. Decode is level at 1 and 4 streams, greedy, with the MTP drafts on; it picks none of these rows, so I did not run sampled decode or a separate drafter.)