Repository navigation
perf(hip): DFlash2 holds run only the rows their drafts need - #3918
Conversation
|
Thank you @AbrahamCete. Holding only the rows the drafts need is the right shape, the frame and step guards are covered by the inline tests, and your gfx1151 receipt shows the drafted path is bit-exact and no longer pays the full block. Nothing further is needed from you on this PR.
|
|
I trial-merged part 5 (#3665) and this head ( On M5 Max with Zig 0.17.0, the resolved stack passed 159 host tests with two skips: zig build test-qwen35-hip-host test-native-hip-host test-draft-hip-host \
-Dhip=true -Dcpu=apple_m1 -j5 --summary allI confirmed by name that the deepest-hold frame truncation and hold-cost fallback tests both ran and passed. This was a host run with inert kernels. The gfx1151 device evidence remains the author's receipt, and #3665 is still open. Rechecked Igor Lessio - AIFLOW LABS |
5098bd3 to
0f3715e
Compare
a03f970 to
2a62668
Compare
|
I checked the current zig build test-qwen35-hip-host test-native-hip-host test-draft-hip-host \
check-native-hip-host -Dhip=true -Dcpu=apple_m1 -j4 --summary allOn M5 Max with Zig 0.17.0, all 18 build steps passed, with 162 tests and two skips. That verifies the restack at host and native-build level. The gfx1151 timing and bit-exact device receipt is separate. Igor Lessio - AIFLOW LABS |
|
I ran the official combined landing train #4477 at zig build tf-h3-image-server test-h3-image-server test-h3-image-prompt test-h3-geometry test-h3-boundaries test-qwen35-hip-host test-native-hip-host test-draft-hip-host check-native-hip-host -Dhip=true -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j4 --summary allThis checks the published train without scratch edits. The four-stream throughput numbers remain the author's device measurements. Igor Lessio - AIFLOW LABS |
|
@AbrahamCete, #3665 landed this morning in its rebased form, so this branch's copy of its commits now conflicts with main (in
|
2a62668 to
f961063
Compare
A frame now runs min(block, deepest depth + 1) rows a stream, so a hold costs what the lane core's step_ms x drafts price assumes, and step_ms is measured as the marginal cost of a draft past a one-draft hold. The core's existing depth rule then drafts shallower in shared rounds. Tests pin that truncated frames keep acceptance within 0.05 of the full block at depths 1 and 3, that a frame refuses blocks outside 2 to the config's before it takes any scratch, and that the measured draft step falls back to the full block's cost a draft when noise makes it non-finite or below a 0.01 ms floor. (cherry picked from commit 9365191)
The recipe's plain and drafted decode figures on gfx1151 came from the proposal branch's base. They are now the medians of this branch's served runs on main f0a54bd (bench_concurrent, 256 tokens, 3 reps, two fresh servers an arm), with two streams added; four chat streams decode below plain, and the recipe says so. (cherry picked from commit 081a375)
(cherry picked from commit 2a62668)
f961063 to
300cac5
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
The last of the six chained PRs agreed in #1563: depth control for shared rounds. Stacked on part 5 (#3665) as a draft until it lands.
Before this, a hold ran the drafter's whole block for every stream, so it cost more than the lane core's
step_ms x draftsprice for it. With part 5 alone on today'smain, four drafted chat streams decode 4.4% (greedy) and 6.2% (t=0.7) slower than plain (#3665).context.frameBlock), so a hold costs what the core's price assumes.step_msis measured at load as the marginal cost of a draft past a one-draft hold (0.56 ms on gfx1151, against 1.73 ms as the full block's cost a draft).core/lanes, the target or the kernels.3361f284bee96ea8,ebde2d262ffde126,88a8f3346c53861a).docs(hip): the 27B recipe's DFlash2 figures on current main(5098bd3d8): the recipe's plain and drafted speeds on gfx1151 from the runs below.Without
--drafternothing runs this code.Size: 196 lines (+165/-31) in 5 files over two commits: the drafter's source with its inline host tests,
tf-qwen35-test drafter, and the recipe. #1563 sized it at about 60; the tests for this PR's behaviour (truncated frames, the step floor and the frame guard) came from review of the proposal and are folded in here.Limits of the whole chain, as stated in #1563 and #3665:
Chains only. Tree drafts come later. CUDA controls depth with trees and per-node chances, which a chain-only drafter cannot use, so this PR prices the chain hold instead.
--tp > 1with--drafteris refused: the drafter and its taps run on one rank.--drafter-bitsother than 4, such as 0, is refused.HIP families other than the dense qwen3_5, and BF16 checkpoints, refuse
--drafterby name.On rocm,
benchmarktakes a drafter only by name;--drafter autopasses none.Prompts reach the drafter whole, because HIP's prefill step does not report fill yet.
Four greedy chat streams still decode 2.5% under plain (44.7 against 45.8 tok/s; every other cell is faster, below). With
TF_SHARED_PRICE_LOG=1the four-stream rounds there draft none in 207 of 356 rounds, one a stream in 118 and three in 23; the shared forward is priced 82.4 ms at 4 rows, 112.4 ms at 5-8 and 178.8 ms at 9-16, and the hold's own pass is not priced, only its marginal drafts. This is the question from feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 that you said you would answer here (comment). Supplyinghold_costs(core/lanes/hold_price.zig) from the HIP drafter changes nothing: the core reads it only under granted depth, whichDraftedturns on only for a drafter that reportschances. Two ways: (1) a small core change, where the allocator's cost record takeshold_costsand a drafted option addsholdMs(hold_costs, drafting streams, deepest)(core/lanes/allocate.zig:20-29and:77), with lone rounds unchanged; or (2) the HIP drafter opts intochances, after which granted depth governs every round and the 1- and 2-stream cells need measuring again. I would go with 1, in this PR or as its own core change, whichever you prefer.Nothing changes without
--drafter.Issue: Fixes Proposal: DFlash2 on HIP for Qwen3.8-27B (gfx1151: 2.0-2.5x one stream, same tokens) #1563. This is the last of the six; with feat(hip): tap a drafter's layers into each stream's ring #2314, feat(hip): DFlash2 drafter config and affine-4 weights for qwen3_5 #2477, feat(hip): DFlash2 drafter kernels for qwen3_5 #2545, feat(hip): DFlash2 Draft engine for the qwen3_5 target #2726 and feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665, it completes the proposal for chains. Trees and
--tp > 1would be separate proposals.Stacked on: feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 (
6e3748856), onmainf0a54bd. This PR adds two commits,13b387424and5098bd3d8; please review6e3748856..5098bd3d8. It comes from a fork, so it targetsmain, and until feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 merges GitHub lists its commits too.atc overlap --json(2026-11-19 05:14Z, basemainf0a54bd): incomplete (the repository's pull-request limits). It reports qwen27: serve the 27B pair, refuse what a pair cannot keep, and die with the peer #1434 and Qwen3.8-27B on Macs without tensor units: --mtp-drafts drafts with the checkpoint's MTP head, through the lane core's drafter as on CUDA #2464, one shared file each, both clean.Checks on this head
mainf0a54bd.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).git archivetrees):zig build test test-golden -Dhip=true --summary all: 10579/10660 passed, 79 skipped, 2 failed;maingives 10565/10646 with the same two failures (cli_config_test"serve --config: expand ..." andstage_hip_test"every staged call on HIP memory ..."), which fail there the same way. This PR adds 3 tests over feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665: the frame's rows, the step floor and the frame guard.test-qwen35-hip-host,test-native-hip-host,hip-host-test,check-native-hip-hostandtest-draft-hip-host(6/6) with-Dhip=true: each exit 0.hip-kernel-testbinary (zig build hip-kernel-build, run directly): 219 passed, 6 skipped, 0 failed of 225, as onmain. This PR adds no kernel.native-hip,tf-qwen35-testandhip-kernel-buildwith-Dhip=true -Dhip-arch=gfx1151 -Doptimize=ReleaseFast: each exit 0 (28/28 steps).tf-qwen35-test drafter <DFlash2> <27B>, which holds this PR's truncated-frame tests: 14 PASS, 0 FAIL. Truncated frames keep acceptance within the 0.05 bound: 1.865 against the full block's 1.885 at depth 1 (234 of 244 chains as the full block's), and 3.229 against 3.222 at depth 3 (127 of 144). A draft step past a one-draft hold takes 0.56 ms, and a full hold 13.5 to 13.9 ms.tf-qwen35-test check <27B> --drafter <DFlash2> --only invariants: 51 passed, 0 failed, 2 skipped (radix memory: too few ids;head batches replayed: the model has no draft head). The four drafted == serial checks accept 96, 75, 83 and 61 drafts.--drafter,tf-qwen35-test check --only invariants: 27B 46/0/7 (main46/0/6; the extra skip is feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665's resumed drafted check, which needs a draft head), 35B-A3B 52/0/1 (main51/0/1).--drafter, byte-identical tomain: 27B 64-step decode2b324aca4048, 27B 2,048-token prompt22c3a0307913, 35B-A3B 64-step decode994218009b56.zig fmt --check build.zig zigandgit diff --check: clean.hip-kernel-contractat this head, which adds no kernel and no record.Receipt
Main against branch: decode with
--drafter, this head (D6) against feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665's head (D5), and both against feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 without--drafter(P) andmain(M), each from a fresh server, in the order M P D5 D6 D6 D5 P M.tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0,0.7 --levels 1,2,4 --alone --serial, server--context 4096 --parallel 4 --prompt-cache-gib 0 --snapshot-dir none --max-snapshots 0. Aggregate tok/s, the median of two runs an arm (spread at most 1.4%, and 5.9% in one D5 cell):main--drafter, feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665--drafter, this headtoken_sha256is the same in all four arms and all eight runs, greedy and seeded; every alone and serial check is equal, 0 unequal and 0 failed.Boxes it reaches: the HIP drafter's holds and its load-time step measure, so only
serve --drafteron the dense qwen3_5 family.New switch? No.
Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision:
TensorFold/Qwen3.8-27B-MLX-4bit(revision22d8d538) andQwen3.6-35B-A3B-MLX-4bit-MTP. Drafterz-lab/Qwen3.8-27B-DFlash2(model.safetensorssha25667fc76d6...4bab65c).mainf0a54bd; this head's code 13b3874 (the recipe commit after it changes no code).Paths and platforms the change reaches, which I ran and which I could not:
serve --drafteron the dense qwen3_5 family.Exactness, from
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:check --drafter: drafted == serial, greedy and seeded t=1, at 4 streams, as above.main, plain, feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 drafted and this head drafted; every alone and serial check equal.--drafter: byte-identical tomain, as above.Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): the table above; raw files on request.
Decode speed before and after, from
tools/bench_openai.py: the decode cells above come fromtools/bench_concurrent.py, which times the same two prompts at each stream count;bench_openai.pywas not run separately.Prompt speed before and after: n/a. Holds run only in decode rounds; the prompt's absorb and the target are unchanged. The first-token cost of the absorb is in feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665.
Licence of any new weights or drafter: n/a. No new weights; the drafter's licence (Apache-2.0) is in feat(hip): DFlash2 drafter config and affine-4 weights for qwen3_5 #2477.
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 truncated-frame tests failed at zero tolerance, the step-floor test failed on the old formula, and the frame guard test aborted without the guard, on the proposal branch. The truncated-frame tests run only when
drafteris given a drafter.)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. (The core's depth rule still picks the drafts; a hold just stops paying for rows no draft uses.)
Drafted output equals
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (check --drafterpasses drafted == serial, solo == together, resumed == fresh and radix at this head; served, one token hash set a cell across all arms, with every alone and serial check equal.)No precision traded for speed. If the bits change, the description says which sums change and why. (The target's bits do not change. A truncated frame's drafts can differ from a full block's, because a chain hold's rows attend each other; tests pin acceptance within 0.05 of the full block at depths 1 and 3.)
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. Not in one cell: four greedy chat streams are 2.5% under plain (2.7% undermain). Every other cell, at 1, 2 and 4 streams, greedy and at t=0.7, is faster with the drafter, by 1.08x to 2.41x; without--drafternothing changes.