Repository navigation
perf(hip): Qwen prompts take the policy's prompt step on a lone RDNA 3.5 iGPU - #4207
Conversation
|
I ran For a follow-up on gfx1151, the first uncovered case I see in the receipt is a resumed request whose uncached suffix itself crosses 4,096 rows. Comparing it with the same prompt served fresh under Igor Lessio - AIFLOW LABS |
|
Thanks @AIFlowML, for the host run and for naming the gap. I ran it on gfx1151: a resumed request whose uncached suffix is longer than 4,096 rows, against the same prompt served fresh, on main 4f3f564 and on this head 1e3c4ed, with both checkpoints. Every resumed reply equals its fresh one. In all eight cells, on Qwen3.6-35B-A3B and on Qwen3.8-27B, the resumed request's
The last column is from Limits: greedy, one text, 16 reply tokens, one stream, the MLX 4-bit checkpoints, gfx1151 only; one run a cell. Raw files on request. |
|
Thanks @AbrahamCete. This applies cleanly to today's main and changes no kernels. In your runs the hidden states match main at every prompt cut you tried, and the resumed-prompt case you added covers a long uncached suffix. We've queued our own paired run against main on our Strix Halo (gfx1151): cold prompt times across prompt lengths,
|
1e3c4ed to
6acf6b1
Compare
|
Rebased onto main after #3665 landed (1e3c4ed → 6acf6b1). The conflict in The description has a new section, "Rebased onto #3665", with the details and the gfx1151 evidence. On the 27B with its drafter, a cache in the band only the rings explain falls back to 1,024-row chunks and says so, and greedy replies are token-equal, drafted and plain, on main and on this head. If your paired run on the Strix Halo hasn't started yet, this is the head to run. |
…3.5 iGPU The HIP policy picks a 4,096-row prompt step on the RDNA 3.5 iGPUs at one rank, and Flash Next takes it. Qwen 3.5/3.6/3.8 kept 1,024-row chunks and 2,048-row steps a layer, so a long cold prompt read the weights several times over. The engine now opens with the policy's rows (prompt_rows.opening), a plain prompt with nothing decoding takes them, and a pass crosses a layer in them (the step forward.spanFor takes). An unquantized checkpoint on rocBLAS, a readout and a prompt beside decoding streams keep their chunks. Where the larger step is the GPU's own default, admission starts from the plain step and keeps the larger one only when its scratch still holds the streams admitted, by the rule Flash Next uses, now in hip/policy.zig. A prompt cache asked for with --prompt-cache-gib rides as that rule's slots: where it fits beside the plain step's scratch and not beside the larger one's, the engine keeps the plain step and serves the cache, as it did before; --prompt-cache-over-cap weighs nothing. With a DFlash2 drafter each step is weighed whole, its tap rings included, which grow with the step. The startup line names the rows taken and any fallback. A prefill_step given by flag or TF_POLICY is taken as given on every card. `tf-qwen35-test hidden --cut N` opens with that step, so a cut stands for a server's chunk, and the prompt tail's invariants run in the engine's step, so `--policy prefill_step=4096` checks the tail under a server's. Refs ashhart#2828
6acf6b1 to
18637c6
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 a lone RDNA 3.5 iGPU the HIP policy picks a 4,096-row prompt step (
prefill_step), and Flash Next takes it (#1651). Qwen 3.5/3.6/3.8 on HIP cut a plain prompt into 1,024-row chunks whatever the policy said, so a long cold prompt on the 35B-A3B streamed the expert weights several times over. Now the engine opens with the policy's rows and a plain prompt with nothing decoding takes them. On gfx1151 the 35B-A3B's cold first token comes 9.1% to 18.4% sooner from 2,048 to 65,536 prompt tokens; the 27B's is level; decode is level; the bytes are the same however a prompt is cut.It follows the plan on #2828:
engine/native.zig, newengine/prompt_rows.zig). The engine opens with@max(policy.prefill_step, policy.fill_rows)rows. Behind a GPU's larger default step, admission starts from the plain 1,024-row step, and the policy's rows come back only when their larger scratch still holds the streams admitted: Flash Next'snarrows, moved tohip/policy.zig. The startup line names the rows and any fallback.hip_lanes.zig,reach). A plain prompt with nothing decoding takes the engine's prompt rows. A readout, a prompt beside decoding streams (fill_rows) and an unquantized checkpoint on rocBLAS keep their chunks.forward.zig).spanFortakes the step as a parameter, at most the engine's prompt rows, so a 4,096-row chunk crosses a layer in one step.spankeepsSPAN.tf-qwen35-test hidden --cut Nopens with that step, andcheck --only invariants --policy prefill_step=4096runs HIP Qwen 3.5/3.6/3.8: a prompt chunk's last layer stops at its keys, or runs only the read row's tile #2845's tail checks under a server's step.Beyond the plan, or where it was silent; say which you want changed:
prefill_stepgiven by--policyorTF_POLICYis taken as given by Qwen on HIP on every card, with no fallback; on main Qwen's HIP engine did not read it. Left alone, gfx1100 and any group of ranks keep 1,024-row chunks.--policy prefill_step=1024gives main's chunks and plan bytes.Size: 292 lines (+268/-24) in 13 files, one commit, eleven new host tests.
mainb112ad6, which has HIP Qwen 3.5/3.6/3.8: a prompt chunk's last layer stops at its keys, or runs only the read row's tile #2845 and feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665. One commit: 6acf6b1, rebased from 1e3c4ed on 2026-11-22 (see "Rebased onto feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665").atc overlap --json(2026-11-20 13:16 UTC, on 1e3c4ed;mainhas moved 153 commits since 4f3f564, to 1ece6e6, none touching these 13 files, and the branch merges clean with it): incomplete (limitationsotherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit). Of the pull requests it read, hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight #2490 sharesengine/engine.zigandengine/native.zigand merges clean; for MoE route tap: optional TF_ROUTE_TAP trace of global top-k #1886, which shares two files, it could not tell, and bygit merge-treeMoE route tap: optional TF_ROUTE_TAP trace of global top-k #1886's one conflict with this branch isnative/metal.zig, the conflict it already has withmain. It did not read my own feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 (DFlash2 part 5) and perf(hip): DFlash2 holds run only the rows their drafts need #3918 stacked on it: bygit merge-treethey conflict with this branch inengine/native.zig, besides thenative/hip.zigconflict they already have withmain; whichever lands first, I rebase the other. The conflicts it reports with local worktrees are with my own local branches, on older bases.Rebased onto #3665
#3665 landed while this was in review and conflicted in
native.zig. The conflict was more than textual: with a DFlash2 drafter,served(e, d, ...)sizes each stream's tap ring from the prompt rows (6,144 rows at the 4,096-row step against 3,072), and the larger step's price here counted only its prompt scratch. So the prompt cache's claim is now weighed against each plan whole, at its own rows: the streams, the drafter's contexts and its rings (Plans.atinnative.zig,settledandOpened.notemoved toprompt_rows.zig). The startup line keeps #3665's drafter text and this PR's rows and fallback reason.expected 1024, found 4096) and passes here.--context 34816 --parallel 4, main b112ad6 against this head: the larger step costs 1,467,691,008 bytes more, 629,145,600 of them tap rings (4 streams × 3,072 rows × 5 taps × 5,120 × 2). A cache of 4.482 GiB, inside the band only the rings explain, falls back to 1,024-row chunks and says so; 4.382 GiB keeps 4,096. No start had less room than it needed."draft": false, on main and on this head: a short code prompt (64 tokens) and a 9,000-token prompt that crosses a 4,096-row cut with the drafter on.native-hipfor gfx1151, lean and fmt pass on the rebased commit; the two failing steps fail on main too.A prompt cache asked for by flag
The prompt cache is sized after the rows, from what they leave. Weighing the streams alone, the fallback would keep 4,096 rows and refuse a
--prompt-cache-gibthat fits beside the 1,024-row scratch and not beside the 4,096-row one, which main serves. So that cache rides in the rule as theslotsargument main gavenarrows: the engine takes 1,024 rows and serves, as main does, and the startup line says why:prompts in 1024-row chunks (4096-row chunks would leave less than the prompt cache asked for).--prompt-cache-over-capweighs nothing, and neither does the default cache.settleasksnarrowstwice: with no slots (the streams alone, the plan's rule), then with the cache asslots. One call carrying the cache stops narrowing where the larger scratch costs a stream and the cache fits beside neither, and the engine would keep a 4,096-row plan larger than the room; an assertion in the streams test pins it.On gfx1151, 35B-A3B at
serve --context 34816 --parallel 4, the room pinned at 40,036,473,344 bytes byTENSORFOLD_HIP_MEMORY_LIMIT_GB=56: 4,096 rows leave 32.7672 GiB and 1,024 rows 33.4425. The rows each server opened with:--prompt-cache-gibmain--prompt-cache-over-capAt 33.443, which fits beside neither, the refusal names what 4,096 rows leave (32.77 GiB) where main names 33.44. A
prefill_step=4096given byTF_POLICYis taken whole and refuses the 33.105 cache. On the 27B, pinned the same way, a mid-band 31.173 is served by main and by this change, at 1,024 rows; its edges were not run.Checks on this head
Head commit: 1e3c4ed, on
main4f3f564, both sides built fromgit archivetrees. The checks of this section ran on this commit before one comment line innative.zigwas reworded;zig fmt --checkand the lean checker ran again after it, on 1e3c4ed, and the Receipt's timing runs are on 1e3c4ed.Lean checker,
python3 tools/zig/lean_check.py, on the base and on this head: 168 and 168, 0 new.Tests run, with the command and pass, fail and skip counts (main -> this change):
zig build test-qwen35-hip-host -Dhip=true: 112 of 114 passed, 2 skipped -> 123 of 125 passed, 2 skipped. The 11 more are this change's.zig build test test-golden -Dhip=true: exit 1 on both, with the same counts: 819 of 823 steps, 11,423 of 11,517 tests passed, 92 skipped, 2 failed. The same two fail on main and on the branch, on this machine:cli_config_test"serve --config: expand reads the file, passes other commands through and names what it cannot read" (my shell's umask 0002 makes its temp file group-writable; under umask 022 it passes) andstage_hip_test"every staged call on HIP memory equals the reference, whole and in parts" (a real-GPU test; alone on a quiet GPU it still fails, as Timeout on main and as Aborted on the branch). Both reasons were read this morning, before the cache rule.zig build check-native-hip-host -Dhip=true: exit 0. Flash Next's host test binary, sincenarrowsmoved: 48 passed, 2 skipped, 0 failed.zig fmt --check build.zig zigandgit diff --check: clean.The new tests fail before the change. On main 4f3f564 they do not compile (
prompt_tail_test.zig:188:15: error: expected 8 argument(s), found 9). With a seam that leaves main's behavior alone (the rules file answering as main does,spanFortaking a step it ignores), 116 of 125 passed, 2 skipped, 7 failed:prefill_step=1024keep 1,024:expected 4096, found 1024expected 1024, found nullandexpected 1024, found 4096expected 1024, found 4096expected 4096, found 2048; the tail, a 4,096-row chunk as one step a layer:expected 1, found 2reach, a plain prompt alone, a readout, a decoder's neighbour:expected 4096, found 1024The other four pin what must not move and pass there: a bf16 checkpoint's chunk, no cache asked for, a cache that fits beside 4,096 rows,
--prompt-cache-over-cap. Before the cache rule, givensettle's new signature, the cache test alone failed the same way.On gfx1151, main against this change:
tf-qwen35-test check --only invariants: 35B-A3B 63 PASS, 0 FAIL, 1 SKIP; 27B 58 PASS, 0 FAIL, 6 SKIP; the same with--policy prefill_step=4096. HIP Qwen 3.5/3.6/3.8: a prompt chunk's last layer stops at its keys, or runs only the read row's tile #2845's twelveprompt taillines pass in all four runs.serve --context 34816at--parallel1 and 4, both checkpoints: the change printsprompts in 4096-row chunksand admits the streams asked for. UnderTF_POLICY=prefill_step=1024it prints 1,024-row chunks, as main does, and its plan counts main's bytes exactly in all four cells.serve --context 131072, the room pinned at 26,431,090,692 bytes byTENSORFOLD_HIP_MEMORY_LIMIT_GB=43.329:--parallel 9is refused by both with the same message; at 8 both serve 8 streams in 1,024-row chunks, the change adding(4096-row chunks would admit fewer of the streams asked for); at 7 main serves 1,024-row chunks and the change 4,096.hip-kernel-contracton gfx1151 with ROCm 10.1's hipcc: exit 1 on main and on this change alike, with the same line,SUMMARY gfx1151 181 kernels: 181 pass gates 1-4, 0 fail, 2 known findings; 50 controls: 50 red as planted, 0 missed; 26 limit problems, and the same 26FAIL limits livelines (24 relu2 stream tiles whose VGPRs differ from their records,tf_moe_combine_gate,tf_vl_resize): main's state with this toolchain. No kernel is new or changed, so the contract section is deleted.rocprofv3 --kernel-traceofhiddenat both cuts, a 4,096-row chunk launches none (symbol, threads and LDS bytes, what the launch records key on; never the grid) that 1,024-row chunks do not. On the 35B-A3B the routed products move fromaffine_wmma_item<4,4>to the recordedaffine_wmma_skew<4>; the 27B launches the same 17 shapes at both cuts.CI: runs on this pull request.
Not run, and why:
prefill_stepthere never ran on a device.hip-kernel-contract-limitsas its own step.fill_rows, by host test), and a request arriving while a lone prompt is inside a 4,096-row chunk.--prompt-cache-over-cap,prefill_stepby flag, the hidden-row and invariant checks, and timing.Receipt
The timing below is on 1e3c4ed, before the rebase, which changes only the admission rule with a drafter.
Main against branch: main 4f3f564 against this head 1e3c4ed (ReleaseFast, gfx1151), one fresh server a run, alternated: main, head, head, main, main, head for the cold cells and main, head, head, main for decode. Each server started behind a gate: no other GPU process, the GPU at most 10% busy.
Cold first token, seconds:
tools/bench_cache.py --require-cold --tokens 16at--context 66560 --parallel 1 --prompt-cache-gib 0, one cold request a size a server after an 8-token warm-up, the first N tokens of one real text. Each side's three servers in run order, their medians, and the change (from the unrounded times).mainmainThe 27B is level. The spread inside a side is 0.2% to 0.9%; the two sides' ranges overlap at 2,048 and 4,096, and from 8,192 up every server of this head reads below every server of main. With three servers a side I claim no gain there. Against the issue's estimate at 4K-8K (9-13% on the 35B-A3B, 0.5-1.5% on the 27B): the 35B-A3B gains more, on a base that already has HIP Qwen 3.5/3.6/3.8: a prompt chunk's last layer stops at its keys, or runs only the read row's tile #2845's tail.
Limits: one cold request a size a server (the client's first pass), three servers a side; greedy, one text, 16 reply tokens; every size at a 66,560-token window. On the 35B-A3B main's first server reads 0.6% to 2.3% faster than its other two at every size, so main's median is one of the slower pair. Only the first gate required a 1-minute load under 3; later gates saw up to 4.19, this run's own servers included.
Boxes it reaches: a lone RDNA 3.5 iGPU (gfx1150 to gfx1153) serving a quantized Qwen 3.5/3.6/3.8 checkpoint on HIP, by default; any HIP card where
prefill_stepis given by--policyorTF_POLICY.New switch? No.
prefill_stepis the policy key Flash Next already reads (1,024; 4,096 on a lone RDNA 3.5 iGPU); Qwen on HIP now reads it too.Environment: TensorFold 4f3f564 (main) and 1e3c4ed (this head); Zig 0.17.0; hipcc HIP 7.1.52801 (Ubuntu clang 21.1.8), and ROCm 10.1's hipcc (HIP 7.16.26385) for the contract and the trace; Ryzen AI Max+ 395 (Strix Halo, gfx1151), unified memory; Ubuntu 26.04.1, kernel 7.0.0-44;
Qwen3.6-35B-A3B-MLX-4bit-MTP(with its MTP head) andQwen3.8-27B-MLX-4bit(no head on HIP). The timing runs' binaries: main4c3ab90eeb64dd73, headccc55eabce543531(sha256 prefixes; two builds of one commit from different scratch paths differ in sha256, which I did not look into).Paths and platforms: ran HIP gfx1151 at one rank, both checkpoints (MLX 4-bit), the served default,
--parallel1 and 4, greedy. Not run: the list under Checks.Exactness:
tf-qwen35-test hiddenover real text, with the device checks above: at 8,192 and at 5,000 tokens on each checkpoint, five files are byte-equal: this change cut at 1,024, at 4,096 and whole, and main cut at 1,024 and whole.token_shaa size and checkpoint across the six servers, with 0 cached tokens in 216 of 216 rows. Main's servers printprompts in 1024-row chunks, the head's4096-row chunks.tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serialat--context 4096 --parallel 4, two servers a side: the same two hashes on all four servers of a checkpoint (35B-A3B9f2923ac14d0anda8c28b8297b4, 27B2cbda70e0639andded27583c51f), 0 failed, 0 alone or serial unequal.--prompt-cache-gib 0). The invariants above coverresumed == fresh,solo == togetherand, on the 35B-A3B,drafted == serialat both steps; the prompts resumed there are 896 to 1,132 tokens, shorter than a 4,096-row chunk.Main against this branch, same machine and checkpoint: the tables here. Scripts, token arrays and raw files: on request.
Decode speed before and after: level.
tools/bench_concurrent.pyas above, aggregate tok/s, each server's value (main's two, then the head's two), one run a server:mainPrompt speed before and after: the cold tables above.
Licence of any new weights or drafter: n/a.
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. (Host-only tests, no dependency to skip.)
Comments and docstrings are one line. No measurements or history in the source.
No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
Drafted output equals
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (No resumed prompt was served; the check'sresumed == freshlines pass at both steps.)No precision traded for speed. If the bits change, the description says which sums change and why. (The bits do not change.)
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. (Greedy, at one stream and four. Not run: sampled requests, a prompt beside decoding streams, more than four streams. With--drafter: greedy replies token-equal, drafted and plain, on main and this head; its timing was not run.)