Skip to content

perf(hip): DFlash2 holds run only the rows their drafts need - #3918

Merged
ashhart merged 4 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-dflash2-6-holds
Nov 22, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
AbrahamCete:feat/hip-dflash2-6-holds

Conversation

@AbrahamCete

Copy link
Copy Markdown
Contributor

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 drafts price for it. With part 5 alone on today's main, four drafted chat streams decode 4.4% (greedy) and 6.2% (t=0.7) slower than plain (#3665).

  • A frame now runs min(block, deepest depth + 1) rows a stream (context.frameBlock), so a hold costs what the core's price assumes.
  • step_ms is 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).
  • The core's existing depth rule then drafts shallower in shared rounds. Nothing changes in core/lanes, the target or the kernels.
  • Guards: a frame refuses blocks outside 2 to the config's block before it takes any scratch. The measured step falls back to the full block's cost a draft when noise makes it non-finite or below a 0.01 ms floor.
  • A hold at the full depth runs the same frame as before: part 4's drafter check lines are unchanged at this head (one-stream greedy 0.862 first right over 94 rounds, 4.98 tokens a round; two streams in frames of two, chains equal in either slot; seeded sampled chain hashes 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 --drafter nothing 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:

Checks on this head

  • Head commit: 5098bd3 (code at 13b3874, then the recipe's figures), on feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665's head 6e37488 and main f0a54bd.
  • Lean checker, 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).
  • Tests run, with the command and pass, fail and skip counts (clean git archive trees):
    • zig build test test-golden -Dhip=true --summary all: 10579/10660 passed, 79 skipped, 2 failed; main gives 10565/10646 with the same two failures (cli_config_test "serve --config: expand ..." and stage_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-host and test-draft-hip-host (6/6) with -Dhip=true: each exit 0.
    • The hip-kernel-test binary (zig build hip-kernel-build, run directly): 219 passed, 6 skipped, 0 failed of 225, as on main. This PR adds no kernel.
    • native-hip, tf-qwen35-test and hip-kernel-build with -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.
    • Without --drafter, tf-qwen35-test check --only invariants: 27B 46/0/7 (main 46/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 (main 51/0/1).
    • Decode logits without --drafter, byte-identical to main: 27B 64-step decode 2b324aca4048, 27B 2,048-token prompt 22c3a0307913, 35B-A3B 64-step decode 994218009b56.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • CI: runs on this pull request.
  • Not run, and why:
    • gfx1030, gfx1100 and gfx1201, because I have only gfx1151.
    • hip-kernel-contract at this head, which adds no kernel and no record.
    • Metal and CUDA: untouched.

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) and main (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):

    cell main plain (feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665) --drafter, feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 --drafter, this head this head / feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 this head / plain
    code, t=0, 1 stream 14.4 14.4 32.5 34.8 +6.8% 2.41x
    code, t=0, 2 streams 27.2 27.2 37.0 49.2 +32.8% 1.81x
    code, t=0, 4 streams 46.2 46.2 47.3 54.5 +15.3% 1.18x
    chat, t=0, 1 stream 14.7 14.8 27.7 28.0 +1.1% 1.89x
    chat, t=0, 2 streams 27.5 27.5 31.9 38.1 +19.4% 1.39x
    chat, t=0, 4 streams 46.0 45.8 43.8 44.7 +1.9% 0.975x
    code, t=0.7, 1 stream 14.4 14.4 33.2 34.4 +3.6% 2.39x
    code, t=0.7, 2 streams 27.1 27.0 43.8 47.8 +8.9% 1.77x
    code, t=0.7, 4 streams 45.8 45.7 46.5 52.7 +13.2% 1.15x
    chat, t=0.7, 1 stream 14.4 14.4 29.1 29.9 +2.8% 2.07x
    chat, t=0.7, 2 streams 26.6 26.5 31.9 35.9 +12.4% 1.35x
    chat, t=0.7, 4 streams 44.5 44.3 41.6 47.7 +14.7% 1.08x
    • Token ids: in every cell every stream's token_sha256 is 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 --drafter on the dense qwen3_5 family.

  • New switch? No.

  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision:

    • Machine: Ryzen AI Max+ 395 (gfx1151), Ubuntu 26.04, Zig 0.17.0.
    • Builds and served runs: ReleaseFast, hipcc with HIP 7.1.52801 and Ubuntu clang 21.1.8.
    • Checkpoints: TensorFold/Qwen3.8-27B-MLX-4bit (revision 22d8d538) and Qwen3.6-35B-A3B-MLX-4bit-MTP. Drafter z-lab/Qwen3.8-27B-DFlash2 (model.safetensors sha256 67fc76d6...4bab65c).
    • Base feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665's head 6e37488 on main f0a54bd; 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:

    • Only the HIP drafter's holds and its load-time step measure, so only serve --drafter on the dense qwen3_5 family.
    • I ran gfx1151 only.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false:

    • check --drafter: drafted == serial, greedy and seeded t=1, at 4 streams, as above.
    • Served: one token hash set a cell across main, plain, feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 drafted and this head drafted; every alone and serial check equal.
    • Decode logits without --drafter: byte-identical to main, 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 from tools/bench_concurrent.py, which times the same two prompts at each stream count; bench_openai.py was 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 drafter is 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 --drafter passes 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% under main). 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 --drafter nothing changes.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

I trial-merged part 5 (#3665) and this head (5098bd3d) separately into b7298b4e. Both have the same conflict in a test in zig/src/native/hip.zig. In scratch I kept both assertions: the parent still checks the named refusal for a paired drafter, and main still checks the three-draft limit. The rest of the stacked diff applied cleanly.

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 all

I 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 0f3715e29 against 5f53c445e. The trial merge was clean and the same three host targets passed 159 tests with two skips at -j4. The parent #3665 is still open at db414fe35, which is a different revision from the parent in this branch. Trial-merging the two published heads reports four overlapping files: the Qwen recipe, draft.zig, zig/src/native/hip.zig, and the drafter-run test. This host receipt is for the part-6 branch with its current embedded parent. It should be rerun once part 6 is restacked on the landed part 5.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the feat/hip-dflash2-6-holds branch from 5098bd3 to 0f3715e Compare November 21, 2026 02:52
@ashhart
ashhart force-pushed the feat/hip-dflash2-6-holds branch 2 times, most recently from a03f970 to 2a62668 Compare November 22, 2026 01:17
@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the current 2a62668b0 head against #4466 at 3d443e8f0, which already carries the rebased #3665 parent. Merging the whole branch into that train conflicts in four places. Replaying only this PR's three commits (93651916a, 081a3751e, 2a62668b0) onto the train applies cleanly and passes git diff --cached --check.

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 all

On 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

@AIFlowML

Copy link
Copy Markdown
Contributor

I ran the official combined landing train #4477 at ea6e0549, which includes the rebased #3918 commits and the facts-test import fix. On M5 Max with Zig 0.17.0, 290 tests passed with two skips. The native HIP check compiled, the H3 image server built, and its five resident-server tests passed.

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 all

This checks the published train without scratch edits. The four-stream throughput numbers remain the author's device measurements.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

@AbrahamCete, #3665 landed this morning in its rebased form, so this branch's copy of its commits now conflicts with main (in hip_lanes.zig, hip.zig, hip_drafter.zig and the 27B recipe). We're replaying only this PR's own three commits (the DFlash2 hold rows, the recipe figures and the shadowing fix) onto today's main, with your authorship kept, and pushing that to this branch. The HIP host steps pass on it (159 of 161, 2 skipped), no serving pin changed, and every file stays under 600 lines. It goes back into the landing queue once the push lands.

  • Synthena

AbrahamCete and others added 4 commits November 22, 2026 13:43
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)
@ashhart
ashhart force-pushed the feat/hip-dflash2-6-holds branch from f961063 to 300cac5 Compare November 22, 2026 13:43
@ashhart
ashhart merged commit 14951bc into ashhart:main Nov 22, 2026
2 of 12 checks passed
@ashhart

ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: DFlash2 on HIP for Qwen3.8-27B (gfx1151: 2.0-2.5x one stream, same tokens)

3 participants