Repository navigation
perf(hip): score the planned decode walk at d = 256 without element tests - #3508
Conversation
|
@AbrahamCete, thank you for this. The d=256 score path keeps the product and fold order, NaN operand order included, and the new NaN pin is useful. One gap needs fixing first: the specialization is the Please add d=256 short and long cases to that contract, covering the Qwen head groups, causal boundaries and partial vector-store tails, with the repeat and input guards, the sum check, and a planted step or stride fault that its gate catches. The score entry points also serve Nemotron at d=128, and their long-span register count rises from 48 to 107 VGPRs, because the old branch shares that allocation. Please include a long-context Nemotron control before calling the other head sizes unaffected. On our side we'll repeat the contract, both Qwen models and that control on a Strix Halo, with drafts on and off and several streams. Other AMD architectures stay unchecked.
|
b9e9d4b to
c6ef570
Compare
|
@ashhart thanks for the review. Your Nemotron question found a real cost, so the branch changed. The description is refreshed for the new head with every table; here is the short version, point by point. What changed. The d = 256 path no longer lives inside the score kernels Nemotron uses. It has its own four entry points, 1. The contract enters the d = 256 path. 2. The Nemotron control (d = 128). On the first head your concern held: the shared allocation took the long-span score from 47 to 106 VGPRs, the walk was 3-5% slower and served decode 1-3% slower at 131K-258K. On this head that path is main's code at 47 VGPRs, and both are level:
The kernel walk is -0.4% to +0.7% across 12 cells (64K-256K, 1 and 2 rows, q fp32 and bf16), inside batch noise, and every byte it writes equals main's (36 of 36 cells). 18 of 18 served replies have main's hash. 3. The Qwen cells on this head. The split keeps the gain: one layer's walk is 23-26% faster at 131K-262K, byte-equal to main in 72 of 72 finite and 72 of 72 NaN-poisoned cells. Served decode:
4. The cells the description promised. Four streams with 32,768-token prompts ( 108 of 108 served replies have main's hash (Qwen turns, Nemotron, four streams, sampled). Environment: gfx1151 (Ryzen AI Max+ 395), Zig 0.17.0, served builds with hipcc HIP 7.1.52801, contract and limits with ROCm 10.1's hipcc; base main 9e00f2c, head c6ef570. Scripts, summaries and raw logs: https://gist.github.com/AbrahamCete/ce1427657bf7bba5e51db013dc200e4c. |
|
Thanks @AbrahamCete. The split addresses the Nemotron cost, and the new contract and posted hashes answer our requests. We will repeat the checks on Strix Halo and handle the changelog and CI. The other AMD cards remain unqualified; if you have runs from those cards, please share them. We will keep the dispatch scope explicit until those checks are available.
|
|
Thanks @AbrahamCete. We repeated the check on Strix Halo (gfx1151) with Qwen3.8-27B on this head (c6ef570) against its base, in base, new, new, base order: the prompt-pass tokens are equal on every row, and prompt speed and decode are level within run-to-run noise at 2,048 and 8,192 tokens. That was the device check this change needed, CI is green, and we've written its changelog line, so it goes into our next landing train. The other AMD cards stay unqualified until someone runs them.
|
…ests The planned decode walk's score kernels (tf_plan_score*, the long-span and the short-span ones, q fp32 and in the cache's kind) take a path for head size 256, the Qwen3.6-35B-A3B and Qwen3.8-27B attention: - every lane takes its eight elements without the `lane + 32 i < d` test, so a key's products form one plain chain; - a wave's keys are scored in one basic block (no branch per key on `visible`), so their chains and folds interleave; - lane 0 writes a head's scores of the wave in one 16-byte (long) or 8-byte (short) store when the rows are aligned and the span is a multiple of the wave's keys, else one at a time; - keys are read through global, not flat, pointers, so LDS waits do not also wait on the cache loads; - a long-span block walks eight steps of its warps' keys and loads the next step's keys while the step before is summed; launches/plan.zig divides the score grid by the steps. Stats, apply and the partial sums are unchanged, and other head sizes keep the current path. Why the bits hold: each score is the same sum in the same order. Lane l adds its eight products in element order from 0.f, then the folds run at xor 16, 8, 4, 2, 1 with each lane's own value as the first operand, as before. Keys past the row's position are not loaded (their registers hold zeros) and their scores are still -inf. A fused v_add_f32_dpp fold (partner + x) was tried and dropped: on gfx1151 it keeps the other operand's payload when both are NaN. kernel_tests/plan_pin.zig pins every byte the walk writes (scores, stats, partials, output) on keys and queries poisoned with NaNs of distinct payloads and signs and with infinities, long and short spans, q fp32 and bf16, by a digest recorded on the kernels this replaces. The eight score records take the registers ROCm 10.1's hipcc reports for each served chip, updated in place. Refs ashhart#3429
…el contract The contract's walk fixed d = 128, so it never entered the score's d == 256 path. It now registers that path for both Qwen head groups (16 query heads over 2 KV heads and 24 over 4), on short spans (two keys a wave) and long ones (four keys, eight steps a block), with q fp32 and in the cache's kind: eight kernels through gates 1-4. - Rows end at causal cuts: inside a wave's keys, on a wave's, a step's and a block's edge, at the span's end, one key and all but the last; the float64 reference sums each row over the keys it sees. - Spans past the 8- and 16-byte score stores (1023, 4093, 16386, 16387, 16511, 16513) take the scalar tail, and served[0] of the 24-head cases is one, so gate 2's guard bytes cover that tail. - Gate 4's rows see every key, so its weights stay 1 / keys. - A control launches the walk with the long-span score grid counted for 16 steps a block where the kernel walks 8; gate 3 must go red. Refs ashhart#3429
The d == 256 branch inside plan_score_body shared the register
allocation of tf_plan_score_*, so Nemotron's d = 128 walk ran at 107
VGPRs where main runs 48. The branch moves into its own entry points,
and every existing score kernel is main's source again.
- plan.hip: tf_plan_score256_{f16,bf16,act_f16,act_bf16} run
plan_score256_body, which holds plan_score_d256's walk verbatim
(eight steps of four keys a warp a block, keys loaded a step early,
no element tests). plan_score_body and the eight tf_plan_score*
kernels equal main's byte for byte; the file only adds lines.
- launches/plan.zig dispatches d == 256 on long spans to the new
kernels and divides their grid by score_steps; other head sizes and
short spans launch main's kernels, as on main.
- Records: hip_records.zig is main's again (in place, 600 lines); the
four new kernels get records in hip_records_score.zig.
- Contract: the planted grid fault now targets tf_plan_score256_*,
with a control for q fp32 and one for q in the cache's kind.
- plan_pin.zig pins Nemotron's shape too (32 heads over 2, d 128, a
long span), with its own digest beside the d = 256 one.
Refs ashhart#3429
c6ef570 to
ff3d4b4
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. |
|
Thanks @AbrahamCete! This is in TensorFold 1.2.10, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.10
|
What this changes
At head size 256 on long spans (16,384 keys or more), the planned decode walk's score runs in its own kernels,
tf_plan_score256_{f16,bf16,act_f16,act_bf16}. That's the attention of Qwen3.6-35B-A3B and Qwen3.8-27B at long context. Every other size and span keeps main'stf_plan_score*kernels, byte for byte. Score only, as agreed on #3429; apply, stats and the partial sums are unchanged.lane + 32 i < delement tests: a key's eight products are one plain chain.visible: a wave's keys are scored in one block, so their chains and folds interleave. Keys past the row's position are not loaded, and their scores are still-inf.launches/plan.zigpicks these kernels ford == 256on long spans and divides their grid by the steps.Why the bits hold. Each score is the same sum in the same order: lane
ladds its eight products in element order from0.f, then the folds run at xor 16, 8, 4, 2, 1 with the lane's own value as the first operand, asscoreBitsinkernel_tests/attention.zigpins.-ffp-contract=offstays.Why separate kernels. The first version put this path in a
d == 256branch ofplan_score_body. That shared the register allocation of the kernels Nemotron uses at d = 128 (48 -> 107 VGPRs), and its d = 128 walk ran 3% to 5% slower. Nowplan_score_bodyand the eighttf_plan_score*kernels are main's source again (same sha256), andplan.hiponly adds lines. Nemotron's walk and served decode are level with main (below).The fused fold is not in this pull request. #3429's candidate fused the xor 8, 4, 2, 1 folds into
v_add_f32_dpp, which computespartner + xwhere main computesx + partner. A poisoned-NaN case shows the payload moves on gfx1151 when both operands are NaNs with different payloads. So these kernels keep main'sv_mov_b32_dpp+v_add_f32folds, operands in main's order.Size: 558 lines (+539/-19) in 9 files, in three commits: the score change, the contract cases, and the split into its own kernels.
main9e00f2c. Commits: 160d771, 1cadf51, c6ef570.atc overlap --json(2026-11-16 19:05Z, basemain9e00f2c): 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.zig,zig/src/hip/launches.zigandzig/tests/hip/contract_main.zig; it merges clean with this branch.Exactness
Byte comparison against main. A scratch test (not in this pull request) appends main's score and apply kernels verbatim under other names to the head's
plan.hip, launches them with a copy of main'splanCausalAs, and compares every byte of out, scores, stats and partials from poisoned (0xff) buffers.+infbeside-infacross the xor-16 fold (soinf - infNaNs meet payload NaNs), one lane's NaN, or signaling NaNs everywhere; half the queries hold payload NaNs,+infbeside0, or NaNs in every fourth lane. f16 and bf16 caches, q fp32 and in the kind, spans 1K, 16K and 128K, both shapes: 72 of 72 byte-equal. Main's own score with the fused folds differs from main in 12 of 12 long-span cells.Committed test.
kernel_tests/plan_pin.zigpins every byte the walk writes on keys and queries poisoned with NaNs of distinct payloads and signs, infinities of both signs and signaling NaNs, by one FNV-1a digest per head size and architecture (gfx1151), in the style ofattention_pin.zig. d 256: the long span (16 over 2 heads, 16,384 keys,tf_plan_score256_*) and the short one (24 over 4, 1,024 keys,tf_plan_score2_*). d 128: Nemotron's 32 over 2 heads at 16,384 keys (tf_plan_score_*). Each with q fp32 and bf16. It also requires at least 64 distinct NaN patterns in the scores (145 here).0x0adb33378a143b95(the value pinned on main d2b3722 before), d 1280xd551aaf3c605ae2f.Checks on this head
main9e00f2c. Every line below was built fromgit archivetrees.python3 tools/zig/lean_check.py, on the base and on this head: 221 and 221, 0 new (tools/zig/lean_new.py).tools/pr_check.py --base origin/main --pr 3508: 0 errors, 1 advisory warning (no Unreleased line). No touched file passes 600 lines:plan.hip498 -> 599,hip_records.zig600 (main's file),hip_records_score.zig38 -> 68,launches.zig451 -> 455.zig build hip-kernel-test -Dhip=true -Dhip-arch=gfx1151(system hipcc, HIP 7.1.52801): 22 of 22 steps, 220 of 227 tests passed, 7 skipped, 0 failed. Main with only the pin test added: 219 passed, 7 skipped, and the pin itself, which printed the d 128 digest to record.-Dhipcc=<ROCm 10.1>/bin/hipcc): 22 of 22 steps, 220 of 227 passed, 7 skipped, 0 failed.zig build test test-golden -Dhip=true --summary all: 772 of 776 steps and 10,517 of 10,598 tests (79 skipped) on both main and this head. The same 2 tests fail on both, and they fail on main on this machine too:cli_config_test"serve --config: expand reads the file..." andstage_hip_test"every staged call on HIP memory equals the reference...".zig fmt --checkon the changed Zig files,zig ast-checkandgit diff --check: clean.Kernel contract, only when a GPU kernel is new or changed
tf_plan_score256_{f16,bf16,act_f16,act_bf16}, reached by eight new d = 256 registrations throughplanCausalandplanCausalAs(16 query heads over 2 and 24 over 4; short spans reach main'stf_plan_score2_*, long spans the new kernels). The q-in-kind ones replacetf_cast, planCausal and tf_castbit for bit. The rows end at causal cuts inside a wave's keys and on wave, step and block edges; spans of 1,023 to 16,513 keys take the scalar store tail; gate 4 runs at 8,192 and 32,768 keys.tf_plan_score256_*grid counted for 16 steps a block where the kernel walks 8, so half the keys are never scored. On gfx1151 (bf16): q fp32 red at gate 3 (19.26 of its bound), q and rows bf16 red at gate 3 (its bytes differ ... from byte 0). The f16 kernels take the same controls on fp16 chips.tf_plan_score256_*108 VGPRs, 77 SGPRs on all four chips, 128 threads,16 * 256 * 4dynamic LDS at most, no scratch (hip_records_score.zig).hip_records.zigis main's file.SUMMARYline and exit status (ROCm 10.1's hipcc, gfx1151):SUMMARY gfx1151 169 kernels: 169 pass gates 1-4, 0 fail, 2 known findings; 44 controls: 44 red as planted, 0 missed; 2 limit problems, exit 1.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, exit 1. The head's FAIL lines are main's 46 plus the two new controls' lines, numbers aside: main's are the 42 controls' lines, the known findings, and two records main already holds stale (tf_moe_combine_gate,tf_vl_resize).zig build hip-kernel-contract-limits(ROCm 10.1, gfx1030, gfx1100, gfx1151, gfx1201): the same 7 problems on main and this head, all main's own stale records; the score entries readcurrent.Receipt
git archivetrees with the system hipcc, ReleaseFast, base then head in each cell on the same machine, a fresh server a run. Every timed phase started only after the GPU read 0% busy for 10 s with no other/dev/kfdholder.Served decode tok/s, main against this head. The token hashes are the same request by request: 36 of 36 replies (9 a cell), the same hashes the first head gave. Within each build, each text stretch gives one hash across drafts on and off.
Each value is the mean of four requests (two text stretches, two runs each), and the two runs of one stretch and setting are within 0.14 tok/s of each other. The first token on a resumed turn is unchanged (-0.2% to +0.3%), and so is the cold first request's (-0.1% to +0.3%): the change does not reach prompt processing.
Token hashes, request by request (base and head identical)
Each cell: the cold first request, then stretch 1 with drafts on, off, off, on, then stretch 2 the same. Base 9e00f2c and head c6ef570 give these same 9 hashes in each cell.
One layer's walk (score, stats, apply and sum), µs, one row at the span's end, main's kernels and the head's alternated in one binary (B H H B ...), median of 7 batches:
Batch noise is 0.4% to 4.5% (Nemotron's one-row cells up to 2.6%). The Nemotron rows above are q fp32 at one row; its twelve cells (64K-256K, 1 and 2 rows, q fp32 and bf16) are all -0.4% to +0.7%.
Nemotron served (d = 128, main's kernels on both sides).
NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, same turn client and settings as below: 131,072 tokens drafts off 38.89 -> 38.80 (-0.3%), on 37.09 -> 37.19 (+0.3%); 258,048 tokens off 24.95 -> 25.04 (+0.4%), on 20.92 -> 21.15 (+1.1%). Token hashes 18 of 18 the same.Four streams at once (
--parallel 4, the widest I ran; both checkpoints admitted 4 streams at their whole 262,144-token window on an earlier main, f8dacd7). Four distinct prompts of 32,768 tokens (long spans),--context 36864,--prompt-cache-gib 12. The four go in cold together, the first runs again alone, then all four together with 256 reply tokens, resumed, so every stream decodes at once:The cold fill of the four prompts is unchanged (98.8 -> 98.8, 99.9 -> 100.0, 386.5 -> 386.8, 385.8 -> 384.8 s). Every reply's hash is main's, stream by stream: 9 of 9 in each cell.
Sampled (temperature 0.7, seed 1234, the turn client with drafts on, off, off, on over two stretches). Qwen3.6-35B-A3B at 131,072 kept tokens: drafts off 28.95 -> 35.16 tok/s (+21.4%), on 20.44 -> 26.17 (+28.0%). Qwen3.8-27B at 32,768: off 11.61 -> 12.26 (+5.6%), on 10.87 -> 11.68 (+7.5%). Hashes 9 of 9 the same in each cell, drafts on and off give one hash a stretch, and the resumed first token is level (+0.2%, -0.1%).
--drafter: not runnable on HIP.serve Qwen3.8-27B-MLX-4bit --drafter Qwen3.8-27B-DFlash2stops on main and on this head with--drafter: the HIP engine runs no DFlash2 drafter yet; serve without --drafter.Qwen3.6-35B-A3B-MLX-4bit-MTP,Qwen3.8-27B-MLX-4bitandNVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit. Binaries: base tensorfold-natived820369e92e3, headbd308e0a5e47(sha256 prefixes).blockIdx.z). Ran: gfx1151, both Qwen checkpoints, one stream and four, drafts on and off, greedy and sampled; Nemotron as the d = 128 control. Not run: gfx1030, gfx1100 and gfx1201 (no cards), and--drafter(the HIP server refuses it on main and on this head).token_shaequal main's request by request (108 of 108: 36 in the Qwen cells, 18 Nemotron, 36 in the four-stream cells, 18 sampled), and drafted replies equal"draft": falsewithin each build; the kernel-level byte comparisons and the pin are under Exactness above.--parallel 1,--prompt-cache-gib 18, the request'sdraftfield on, off, off, on over two text stretches) rather thantools/bench_openai.py, because the point is the decode step at a 131K-258K context; client and raw files: a secret gist, https://gist.github.com/AbrahamCete/ce1427657bf7bba5e51db013dc200e4c (scripts, summaries and every run's log; local paths read$LAB,$MODELSand$SCRATCH).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 pin cannot fail before the change, since the change keeps the bits; the first head with the fused fold put back failed it, and it was the only test that failed. The contract's two new controls go red as planted.)
Comments and docstrings are one line. No measurements or history in the source. (Lean checker: 0 new problems.)
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 kernel change inside the same launch.)
Drafted output equals
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Served hashes equal main's and equal across drafts on and off; four streams at once give main's hashes stream by stream; every byte of the walk equals main's at 1, 2 and 4 rows. Concurrent against solo was not compared by hash: the streams client asks the alone and together replies at different lengths.)No precision traded for speed. If the bits change, the description says which sums change and why. (The bits do not change, NaN payloads included.)
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. (One stream and four, greedy and sampled, drafts on and off: faster at d 256, level at Nemotron's d 128, prompt level.--drafteris n/a: the HIP server refuses it on main and on this head.)