Repository navigation
feat(hip): serve Qwen3.8-27B with its DFlash2 drafter - #3665
Conversation
|
@ashhart one question for part 6 before I open it. The 4-stream chat cell in the table above, drafted slower than plain, comes from a cost the lane core does not charge, and the fix I can see touches What is not priced. A shared round that drafts runs the drafter's hold pass. For a chain drafter without Why Two ways I see:
I'd go with 1, either as its own core change or inside part 6, whichever you prefer. Part 6 waits for your call. As it stands on its local head, it leaves chat at 4 streams 2.5% under plain (greedy) and faster than plain at temperature 0.7, with every token equal. |
|
Hi @AbrahamCete, thank you. The HIP drafter now sits behind
|
|
At On M5 Max with Zig 0.17.0, the resolved part 5 tree passed 241 tests, with two skips, plus the native HIP compile check: zig build test-native-hip-host test-qwen35-hip-host test-draft-hip-host \
hip-host-test check-native-hip-host -Dhip=true -Dcpu=apple_m1 -j5 --summary allI verified the named cases for the BF16 refusal, resumed feature positions and kept-row limits ran. This run uses host fixtures, so the existing gfx1151 receipt remains the device evidence. Igor Lessio - AIFLOW LABS |
72ef4e2 to
09bbd1f
Compare
…nly test may name its engine ashhart#3665 imports engine.zig as a module-level `engine` (for engine.tap_window); main's ed4e935 (Fixes ashhart#4061: price copies-only HIP plain rounds) added a test whose local `var engine: Engine` shadows it, which Zig refuses (hip_lanes.zig:537), so hip-host-test failed to compile. The import is renamed engine_mod; no other change.
|
The current part 5 head On M5 Max with Zig 0.17.0, this passed 247 tests with 2 skips and compiled the native HIP target: zig build test-native-hip-host test-qwen35-hip-host test-draft-hip-host hip-host-test check-native-hip-host -Dhip=true -Dcpu=apple_m1 -j4 --summary allThe gfx1151 token and timing measurements are from the author's device receipt. Igor Lessio - AIFLOW LABS |
The native HIP server wraps the qwen3_5 dense target with the lane core's Drafted over the HIP DFlash2 drafter: taps are set from the drafter's config before streams are sized, the drafter's weights and per-stream state count in the memory plan, and window costs go to the drafter. - refuse --drafter under --tp > 1, at other --drafter-bits, and for HIP families without a DFlash2 drafter; benchmark --drafter on rocm - an absorb refuses kept rows past its features; features serve only rows the ring holds for the drafter's window - docs: the 27B recipe and community benchmarks A test pins that --no-drafts with --drafter loads no drafter and is not refused.
tf-qwen35-test check takes --drafter <dir>: the lanes session opens the HIP DFlash2 drafter as the native server does and wraps the target with Drafted, so drafted == serial, solo == together and graph == eager run for Qwen3.8-27B instead of skipping. The taps invariant restores the taps it found instead of switching them off. The lanes session likewise restores the taps it found when it ends or its drafter fails to open.
A stream resumed from a kept prompt state taps no rows below the resume point, so its ring holds zeros there while features() counted them as written. features() now refuses them with RowsNotHeld, as Nemotron and Gemma4 do. Drafted already absorbs from s.cached, so no served path asks for those rows.
…a fresh one The resumed invariant compares a resumed drafted run with a serial one. This adds the drafted run of the same prompts with every kept prompt evicted first: it must resume nothing and give the resumed run's tokens, and the check prints each run's drafts kept, drafted and rounds, so a resume's effect on acceptance is visible.
main now serves some BF16 qwen3_5 checkpoints (image towers the engine reads, and joint-head decisions), but the engine times no BF16 windows, so the DFlash2 drafter would run its rounds unpriced. A BF16 checkpoint with --drafter is refused by name before any load, as the drafter's stated limit says; quantized checkpoints and serves without --drafter are unchanged. A host test pins the refusal on a BF16 chat config and its absence on the same config quantized, or without --drafter.
… (six blank lines fewer) Main's 2027e7a ("flashnext hip: one refusal test for --drafter and --mtp-drafts, so hip.zig stays within 600 lines") left hip.zig at 599 lines, and the DFlash2 drafter's group check put it at 606. Six blank lines between adjacent tests at the end of the file go; no code changes.
…calls, after main's 1a10b0b Main's 1a10b0b ("hip flashnext: opt-in --mtp-drafts up to 7 on a lone stream (ashhart#3053)") gave checkGroup a comptime family parameter. The merged --drafter test's four calls pass qwen35.native, as main's own refusal tests do; at --tp 1 that family drafts at most 3, so the test's --mtp-drafts case keeps its message.
…n's 1a10b0b (one blank line fewer) Main's 1a10b0b ("hip flashnext: opt-in --mtp-drafts up to 7 on a lone stream (ashhart#3053)") added the mtp_drafts_hip_test.zig import, and with the DFlash2 drafter hip.zig came to 601 lines. The blank line between the group-flags test and the --drafter refusal test goes; no code changes.
…nly test may name its engine ashhart#3665 imports engine.zig as a module-level `engine` (for engine.tap_window); main's ed4e935 (Fixes ashhart#4061: price copies-only HIP plain rounds) added a test whose local `var engine: Engine` shadows it, which Zig refuses (hip_lanes.zig:537), so hip-host-test failed to compile. The import is renamed engine_mod; no other change.
09bbd1f to
75d15fd
Compare
…nly test may name its engine #3665 imports engine.zig as a module-level `engine` (for engine.tap_window); main's ed4e935 (Fixes #4061: price copies-only HIP plain rounds) added a test whose local `var engine: Engine` shadows it, which Zig refuses (hip_lanes.zig:537), so hip-host-test failed to compile. The import is renamed engine_mod; no other change.
|
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
Part 5 of the six chained PRs agreed in #1563: the wiring.
serve <27B> --drafter <dir>now runs the DFlash2 drafter on the HIP engine, behind the lane core'slanes.drafted.Drafted, as the XPU engine does. Before, it was refused with "--drafter: the HIP engine runs no DFlash2 drafter yet; serve without --drafter".feat(hip): serve Qwen3.8-27B with its DFlash2 drafter(56fbd2452):Draftedover part 4's drafter (native/hip_drafter.zig'sattach).native/hip_drafter.zig(252 lines with its tests) holds the host side: the refusals, the drafter the family loads, the serving line's drafter, and attach and release.native/hip.zigstays at 600 lines. The shared serve options (hip_serve/options.zig) gaindrafter: ?[]const u8 = null.main's own family refusals:--drafter with --tp {d}: the HIP engine runs its DFlash2 drafter on one rank; serve with --tp 1, or without --drafter--drafter-bits {d}: the HIP engine runs the DFlash2 drafter at 4 bits; serve with --drafter-bits 4, for any value but 4.--drafter: <model_type> checkpoints load no DFlash2 drafter on HIP; serve without --drafter, for the other HIP families (qwen3_5_moe,qwen4_expandnemotron_hamong them).--drafter <dir> --no-draftsloads no drafter and is not refused, as on CUDA. A test pins it.drafts: DFlash2 (<dir>) + copies; without--drafterit is unchanged,drafts: copies only. A host test pins both.BadDraftRows, beside part 4'sFeaturesNotAtStart).featuresrefuses an empty span, and serves a span only while the ring still holds its newest window of rows, the only rows the drafter reads. A rewind below a context's first row starts the context at the absorb.benchmark --backend rocmpasses a named--drafterto aqwen3_5checkpoint and refuses one for other families:--drafter: the HIP engine runs a DFlash2 drafter over dense qwen3_5 checkpoints only, so a rocm run of this model takes none; --drafter none runs without it.--drafter autostill passes none on rocm; only its note changes, to "This run passes no drafter: on rocm only a named --drafter passes one."community-benchmarks.md.test(qwen35): check --drafter runs the lane invariants under DFlash2(b7c781de3):tf-qwen35-test check <model> --drafter <dir>opens the drafter as the server does, so drafted == serial, solo == together, graph == eager, resumed and radix run for the 27B instead of skipping. Thetapsinvariant (both its cases, the replayed one included) and the lanes session restore the taps they found.test(hip): pin the DFlash2 drafter's attach paths(267b8c515): a loaded drafter is served behindDraftedwith the model kept, and release frees the wrapper; a drafter that cannot attach frees the model once and says why.fix(hip): a resumed stream's DFlash2 features start at its resume point(502ba54b6), for the question in feat(hip): tap a drafter's layers into each stream's ring #2314: a stream resumed from a kept prompt state taps no rows below its resume point, sofeaturesrefuses them withRowsNotHeld, as Nemotron and Gemma4 do.Draftedabsorbs froms.cached, so no served path asks for those rows; the drafter's context starts at the resume point, as on CUDA. A host test pins it.test(qwen35): check --drafter compares a resumed drafted stream with a fresh one(683ddd16c): after the resumed invariant, the same prompts run drafted with every kept prompt evicted; the check requires equal tokens and prints each run's drafts kept, drafted and rounds.fix(hip): --drafter refuses BF16 qwen3_5 checkpoints before they load(6e3748856):mainnow serves some BF16 qwen3_5 checkpoints (image towers the engine reads, and joint-head decisions), but the engine times no BF16 windows, so the drafter's rounds would go unpriced.--drafter: the HIP engine runs its DFlash2 drafter over quantized checkpoints only; serve this BF16 checkpoint without --drafter. A host test pins it.On your part 5 note in #2726: the drafter sits behind
lanes.drafted.Drafted(native/hip_drafter.zigattach), and the cells below are the ones asked for there.Nothing changes in CUDA, Metal or
core/lanes. Without--drafter,serveis unchanged; a test pins that a plain serve and--drafter <dir> --no-draftsload no drafter, and the decode logits and served replies below equalmain's.servewithout--drafteron a HIP build still pairs no drafter by itself (server/drafter.zigskips rocm), so the default serve keeps its behaviour; whether rocm should pair the cached DFlash2 by itself once this lands is your call, and would be a one-line change there. I left the CHANGELOG line to you, as with parts 3 and 4.Size: 770 lines (+711/-59) in 18 files over six commits. #1563 sized it at about 450. The difference is
native/hip_drafter.zig, which keeps the drafter's host rules and their tests out ofnative/hip.zig(600-line limit), the attach-path tests, the resume handling asked for in #2314, and the BF16 refusal.Limits, as stated in #1563 and for this PR:
Chains only. Tree drafts come later.
--tp > 1with--drafteris refused: the drafter and its taps run on one rank.--drafter-bitsother than 4, such as 0, is refused: the HIP drafter quantizes its weights to 4 bits.HIP families other than the dense qwen3_5 refuse
--drafterby name; so do BF16 checkpoints.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.
A resumed stream's drafter starts its context at the resume point, as on CUDA, so it drafts with less context until it has absorbed enough rows past it: -5.7% to -11.5% decode with an 840-token shared system prompt restored (receipt below). Keeping the drafter window's tap rows with the kept state would remove that for CUDA and HIP alike; I can propose it separately.
With this PR alone, four drafted streams decode slower than plain in chat (-4.4% greedy, -6.2% at temperature 0.7, below); part 6 prices a hold by the rows it runs (-2.5% greedy, level at temperature 0.7 on its local head), and I am adding the hold pass's own cost to it through the core's
hold_costsbefore it opens. The cells you asked for, 1 and 2 streams, are all faster with the drafter.Nothing changes without
--drafter.Issue: Refs Proposal: DFlash2 on HIP for Qwen3.8-27B (gfx1151: 2.0-2.5x one stream, same tokens) #1563. This is part 5 of 6. Parts 1 to 4 are 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 and feat(hip): DFlash2 Draft engine for the qwen3_5 target #2726 (merged); part 6 follows on top of this one once it prices the hold pass with the core's
hold_costs.Stacked on:
mainf0a54bd, which includes parts 1 to 4. This PR adds six commits,56fbd2452to6e3748856.atc overlap --json(2026-11-17 07:45Z, 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 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 (clean), 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 and hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight #2490, whose one conflicting file each (docs/recipes/qwen3.8-27b.md, andzig/src/hip/ops/project.zig, which this PR does not touch) already conflicts withmain.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 ofmainand this head):zig build test test-golden -Dhip=true --summary all:main10565/10646 passed, 79 skipped, 2 failed; this head 10575/10657 passed, 79 skipped, 2 failed, 1 crashed. The two failures aremain's own and fail the same way there:cli_config_test"serve --config: expand reads the file, passes other commands through and names what it cannot read" andstage_hip_test"every staged call on HIP memory equals the reference, whole and in parts". The crash wassessions/store_test.zig's "two split ranks make the same decisions on the same calls and each restores its own rows", which sat in a futex wait for 31 min and was stopped; it is not code this PR touches, and the suite run again passed it, with the same two failures and nothing else.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.test-qwen35-hip-hostfails "an absorb's kept rows pick from its features' rows; a row past them is refused" (108/111, 1 failed); with the BF16 refusal removed, it fails "--drafter is refused over a BF16 checkpoint before it loads; a quantized one, or no --drafter, is not" (108/111, 1 failed). Both pass on this head. With the replayed taps case switching taps off again,check --draftergives 31 passed, 6 failed (error.TapsMismatchin every lane check after it).hip-kernel-testbinary (zig build hip-kernel-build, run directly): 219 passed, 6 skipped, 0 failed of 225, onmainand at part 6's local head 5098bd3, which includes this PR. 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 check <27B> --drafter <DFlash2> --only invariants: 51 passed, 0 failed, 2 skipped. The skips areradix memory: too few idsandhead batches replayed: the model has no draft head, as without the drafter. The four drafted == serial checks (short and long prompts, greedy and seeded t=1) accept 126, 73, 88 and 72 drafts. Resumed drafted == fresh drafted: resumed 35/343 drafts kept in 153 rounds (1.25 tokens a round), fresh 122/197 in 66 (2.91); its resumed prompts restore all but their last rows.tf-qwen35-test drafter <DFlash2> <27B>, which this PR extends: 12 PASS, 0 FAIL. Part 4's lines are unchanged: the first draft right 0.862 of 94 rounds, 4.98 tokens a round; seeded sampled 0.847 and 4.82, chain hashes3361f284bee96ea8,ebde2d262ffde126,88a8f3346c53861a. New: the refusals of features at another position and of a kept row past them; kept rows { 0, 5, 10, 15 } of 16 draft as those rows in order, not as the first rows, and a prefix as whole rows; a 3328-token prompt served through the lanes backend andDrafted, whosefeaturesserve the drafter window and refuse rows out of the ring, unwritten or none.--drafter,tf-qwen35-test check --only invariants: the 27B 46 passed, 0 failed, 7 skipped (main46/0/6; the extra skip is this PR's resumed drafted check, which needs a draft head), and the 35B-A3B 52/0/1 (main51/0/1; the new check runs on its MTP head and passes). Run at part 6's local head 5098bd3, which includes this PR.--drafter, byte-identical tomainat part 6's local head 5098bd3: 27B 64-step decode2b324aca4048, 27B 2,048-token prompt22c3a0307913, 35B-A3B 64-step decode994218009b56.serverefusals on this head's build: the 35B-A3B with--draftergets theqwen3_5_moerefusal;--drafter --tp 2and--drafter-bits 0are refused before any load, each with exit 1 and the messages above.zig fmt --check build.zig zigandgit diff --check: clean.tf-qwen35-test check <27B> --drafter <dir>is the check to run.benchmark --backend rocmwith a named--drafteron this base; its host test pins the pass and the refusal. On the host, a rocm run stops when it parses the serve arguments, so no stand-in child starts.--drafterserved on the GPU: I have none here; the refusal is pinned by its host test.hip-kernel-contractat this head, which adds no kernel and no record.Receipt
Main against branch: the cells asked for in feat(hip): DFlash2 Draft engine for the qwen3_5 target #2726, on gfx1151 with Qwen3.8-27B and its DFlash2 drafter, greedy and at temperature 0.7, at 1 and 2 streams, plus 4. Arms
main(M), this head without--drafter(P) and with it (D), each from a fresh server, alternated with part 6's drafted arm (local head 5098bd3) in the order M P D D6 D6 D 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 the two runs an arm (their spread at most 1.4%, and 5.9% in one drafted cell):main--draftertoken_sha256is the same in all four arms and all eight runs (main, plain, drafted and part 6's drafted), greedy and seeded; every alone and serial check (each concurrent reply against its request alone, the alone runs against"draft": false) is equal, 0 unequal and 0 failed.--drafterthis head is within 0.7% ofmainin every cell.Boxes it reaches: the HIP
servewith--drafteron the dense qwen3_5 family;benchmark --backend rocmwith a named--drafter.New switch? No new switch.
--drafter,--drafter-bitsand--no-draftsalready exist; this PR makes--drafterrun on HIP for the dense qwen3_5 family and refuses it elsewhere by name.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, head 6e37488; part 6's local head 5098bd3 (its code commit 13b3874) where a line says so.--draftermodel 14.10 GiB; 4 streams at once, 0.40 GiB each at a 4096-token window, as onmain, loaded in 15.3-15.4 s; with itmodel 15.12 GiB with its DFlash2 drafter; 4 streams at once, 0.59 GiB each at a 4096-token window, loaded in 18.3-18.5 s, servingdrafts: DFlash2 (<dir>) + copies.Paths and platforms the change reaches, which I ran and which I could not:
serve: the drafter's refusals run aftermain's family refusals, and every HIP family's options carry the newdrafterfield, null by default.--drafter: load, memory plan, taps,Draftedand the serving line.benchmark --backend rocm: a named--drafter, and the auto note (host tests).tf-qwen35-test check --drafter.--drafter, the family loads no drafter, and attach serves the backend as it loaded.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 and drafted; every alone and serial check equal, as above.--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: a secret gist, https://gist.github.com/AbrahamCete/2de8efdc2df4a7df2d5b7b4120e9d1a2 (local paths read
$LAB,$MODELS,$WTand$SCRATCH).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.Resumed against fresh, the drafted cells asked for in feat(hip): tap a drafter's layers into each stream's ring #2314 (script and raw files in the same gist): chat requests at temperature 0, 256 tokens, one stream; fresh runs at
--prompt-cache-gib 0, resumed at 4 GiB after a request that leaves the shared part kept. The text is the same fresh and resumed, and the same inmain, plain and drafted, for every request. Decode tok/s (tensorfold.tokens_per_second), with tokens a round:main, fresh / resumed--drafter, fresh--drafter, resumedPrompt speed before and after: the drafter absorbs the prompt inside the prompt pass, before the first token. Cold first request
ttft_s,lc-client.py cold(the request and clock oftools/bench_cache.py), 3 cold requests a server, two servers an arm in the order M P D D P M,--context 16384 --parallel 1 --prompt-cache-gib 0, every request with 0 cached tokens; medians of six: 2,048 tokensmain4.76 s, plain 4.77 (+0.2%), drafted 4.92 (+3.2%); 8,192 tokens 19.93, 19.92 (-0.1%), 19.99 (+0.3%).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 kept-row, BF16 and taps-restore rules each fail their test or check when removed, as above;
check --drafterruns only when 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. (
Draftedhands the drafter's chains to the round loop, and the target verifies every token.)Drafted output equals
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (check --drafterpasses drafted == serial, solo == together, resumed == fresh, resumed drafted == fresh drafted and radix; served, one token hash set a cell acrossmain, plain and drafted, 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.)
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 by this PR alone: at 4 streams, chat with the drafter is 4.4% (greedy) and 6.2% (t=0.7) slower than without it; part 6 changes that. At 1 and 2 streams the drafter is faster in every cell, and without--drafterthis head matchesmainin every cell.