Skip to content

XPU Qwen27 DFlash2 through the core Drafter and Drafted (#2460 item 5) - #2672

Merged
ashhart merged 8 commits into
ashhart:mainfrom
jschmied:xpu-core-drafter
Nov 9, 2026
Merged

ashhart merged 8 commits into
ashhart:mainfrom
jschmied:xpu-core-drafter

Conversation

@jschmied

@jschmied jschmied commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

What this changes

This is the first drafting block of #2460 item 5 (P2 in the survey). On main, the XPU Qwen3.8-27B lane target drafts on
its own. native/xpu_lanes.zig calls the private xpu/drafter.zig Drafter from its draft, keep and tree. Prompt
taps are pushed into the drafter by a runner callback. The chain/tree switch (TREE_MIN) also lives in the target.

After this PR:

  • native/xpu_dflash2.zig puts that drafter behind core/lanes/drafter.zig's VTable, as minimax_m3/dflash2.zig
    does. It covers taps, facts, open, absorb, hold, held, release and tree. The chain/tree switch moves here, unchanged.
  • lanes.drafted.Drafted sits in front of the lane target. The target no longer drafts. Instead, it hands Drafted the
    taps through features (the last verify's window) and prefill_features (each prompt chunk as it runs).
  • The round facts are main's: Drafted.facts, with the target's own shared-row rule kept
    (allocate_shared_drafts false, as on main).

Two places keep main's arithmetic, and so main's drafts:

  • The prompt's last row. It is absorbed with its chunk, as main absorbs it. Drafted's prompt sink cuts that row and
    absorbs it with the first token. The adapter instead takes it with its chunk when the target says the chunk holds it,
    because the drafter's projections switch kernels at 16 rows, so a separate 1-row pass would round differently.
  • Kept rows. Each round's kept rows go in one batched absorb in request order, the batch main makes in draftFn.

The lone driver (Lanes.lone, DFlash2 trees for a single stream) still drives the drafter directly. When it hands a
stream back to the lane core, it registers the stream with Drafted through a new Drafted.adopt, which is 8 lines in
core.

A separate first commit fixes a bug: main's draftFn stored &q of a by-value loop capture. Every stream in a shared
round therefore keyed its tree noise with the last request's sampling and position, and a greedy last request left
sampled streams without noise. The loop now iterates by pointer. This changes drafts only, since verification keeps
tokens exact.

Checks

  • Host test draft sources: XPU DFlash2 through Drafted makes main's drafter calls, rows and drafts. It runs a recorded
    script through main's private path (ported as it was, against a recording fake drafter) and through Drafted plus the
    adapter. The script covers 3 prompts: one longer than the window, so rows are skipped; one whose last row sits inside
    its last chunk; one whose last row is alone in its chunk. It then runs a shared round (drafts before keep: a tree path,
    an absorb-only stream, a whole window), a lone round (keep before draft, a chain), and an all-kept round with a
    sampled and a greedy stream. Every drafter call (skip, addTaps, absorbMulti rows, lattice blocks, take, tree noise
    bits), the held drafts and the context ends must be equal.
  • Host test: the facts through Drafted equal the lane target's own facts.
  • Planted faults (in a scratch copy, not committed) each fail that test with an expectEqualSlices mismatch, not at
    compile time: the last prompt row absorbed alone dropped (tail), the chain/tree switch moved by one (treemin;
    849e24a0e adds a round of exactly TREE_MIN drafts for it), tree noise keyed one position off (noise), a kept
    tree path absorbed as a prefix (rows).
  • zig build test test-golden plus the CI set on 849e24a0e: 654/654 steps, 8205 passed, 66 skipped. Commit 1 alone passes the
    host tests too. tools/pr_check.py: 0 errors (one advisory: no --pr number yet). Lean 116 vs 116, 0 new. fmt
    and git diff --check are clean.
  • XPU build: xpu-native for bmg (ocloc + nGEN) builds on main and on this branch. test-draft-xpu-host passes 4/4 on
    this branch (main 2/2), including both new Drafted tests. The tgllp build with -Dxpu-dpas=false builds as well.
  • Served, on an Arc Pro B70 (PCIe 5.0 x16), run by @Mirrdhyn, branch ba21da223 against 006820408
    (849e24a0e after it adds only a host-test round). Setup:
    Qwen3.8-27B GPTQ 4/128 with z-lab/Qwen3.8-27B-DFlash2, 4 prompts, 256 tokens, greedy and T=0.8 with seed 7.
    Equality means the reply's tensorfold.token_sha256 matches.
    • Branch drafted == --no-drafts: 8/8. Main == branch, drafted: 8/8. 4 at once == one at a time: 8/8 on each arm.
    • A second request 2 s into a long one: both finish and equal their solo runs, on both arms.
    • Decode tok/s, main / branch / branch / main: 1 stream 120.81 / 120.83 / 120.92 / 120.92; 4 streams aggregate
      263.1 / 259.7 / 255.1 / 255.2. Within noise.
    • No DraftContextGap, FeaturesGone, BadDraftPosition, NotDrafting or DraftNotAttached in the branch's
      logs.
    • Cross-check: main's tools/conformance.py with an XPU profile gives the same result on both binaries: drafted ==
      plain 10/10, repeat 10/10, concurrent == solo 44/44, refusals 4/4, and resumed 6/6 with a 600-item chat.

Not in this PR

  • P3, XPU Nemotron MTP. The served path already drafts through Backend.draft, and the lanes Engine accepts
    (native/xpu_lane.zig draftFn → draftKept/draftFirst). nemotron/xpu_mtp.zig runSpec, with its own accept
    counter, is used only by the device test zig/tests/xpu/nem_mtp.zig. Moving to lanes.mtp_policy would change the
    depth rule, so it is not a move.

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@jschmied thanks, and thanks @Mirrdhyn for the B70 runs: tokens equal to main at greedy and seeded, 4 streams equal to solo, and the conformance set passing. The move reads faithfully: holdFn is main's loop, and the twin test against main's private path on a recording drafter is the right check. Commit 1 fixes a real bug on main, since reqs[ni] = &q kept a pointer to the loop's copy. A few things:

  1. Refusal tests: none of the new errors has an expectError yet. Could you add host tests for FeaturesGone (another slot's prompt tail), DraftContextGap, DraftNotAttached with depth > 0, and DraftHeldFewer?
  2. Drafted.adopt: a core test that it opens a missing stream, resets a present one, and that the next draft absorbs and holds.
  3. Two small ones:
    • xpu_dflash2.zig:47 repeats step_ms = 0.6; could it read the target's value?
    • Drafted.draft's features(last, 1) works only because opened runs right after each stream's own prompt pass. A one-line note there, or skipping the call when the drafter already holds the row, would keep that from breaking quietly.
  4. Device cells (yours or @Mirrdhyn's), on the head:
    • drafted against a per-request "draft": false at 1 and 4 streams, greedy and seeded (--no-drafts likely never attaches Drafted);
    • accepted drafts a round, main against branch, since the tree-keying fix can move acceptance for sampled shared rounds;
    • resumed against fresh for a drafting stream, plus one structured-output stream;
    • the token_sha table for each cell.

We'll write the CHANGELOG line.

@Mirrdhyn

Mirrdhyn commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Happy to take the device cells on the B70 once the head carries your follow-ups. Point taken on --no-drafts: I'll compare against a per-request "draft": false on the same drafting server this time.

@jschmied

jschmied commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart thanks for the review. Four commits on top, no rebase:

  • 1. Refusal tests (51496cf, 3ddfac5 pins DraftNotAttached at depth 1): host tests with expectError for FeaturesGone (the real lane target with slot 1's prompt tail in acts.taps, asked for slot 0's last row, both directly and through Drafted's first draft), DraftContextGap (a prompt chunk after a gap), DraftHeldFewer (4 drafts read when 3 were grown; 3 pass), and DraftNotAttached (the lane target alone, depth 1 refused, depth 0 passes). Each one fails when its check is removed in a scratch copy.
  • 2. Drafted.adopt (9afef33): the test lives in core, in core/lanes/drafted_adopt_test.zig next to the other Drafted tests. Nothing in it is specific to XPU. It covers a missing stream (one open), then the same stream with a past round's state (no second open, the lane back to { .rows = true }, offered 0 in the next absorb), and in both cases the next draft absorbs and holds. A prompt restored whole, once adopted, holds instead of using fillers. Three planted faults turn it red: no open, no reset, no rows.
  • 3a. step_ms (1e4397d): Lanes.draft_step_ms (0.6) is now the one value. Lanes.facts and the adapter's factsFn both read it, so behaviour is unchanged. The existing "keeps the lane target's round facts" test compares b.facts() with the facts through Drafted using expectEqualDeep, so it also shows mtp_step_ms is the same.
  • 3b. features(last, 1) (1e4397d): I added a one-line note instead of skipping the call. The XPU drafter holds the prompt's last row only when that row shared a chunk with earlier rows. When the last row is alone in its chunk (a case in the twin test), the call is needed. Core Drafted can't ask a drafter per stream without a new VTable entry, and the CUDA/Metal drafters need that absorb with the first token. If the order ever breaks, the new FeaturesGone test shows the target refusing instead of reading another stream's rows.

The twin test and its four planted faults are unchanged: green as committed, red when planted. CI set 654/654 on the Spark and 641/641 on x86, pr_check 0 errors (lean 116 vs 116, 0 new), fmt and git diff --check clean. The XPU device build (bmg) can't run here.

@Mirrdhyn thanks for taking the cells. The follow-ups are all on 3ddfac598, so that's the head to run:

  • drafted against per-request "draft": false, at 1 and 4 streams, greedy and seeded;
  • accepted drafts per round, main against this branch, for the same prompts and seeds (the tree-keying fix can move acceptance in sampled shared rounds);
  • resumed against fresh for one drafting stream, plus one structured-output stream;
  • the token_sha for each cell, in one table.

@Mirrdhyn

Mirrdhyn commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Device cells on the head 3ddfac598 (Arc Pro B70, PCIe 5.0 x16, Qwen3.8-27B GPTQ 4-bit g128 with z-lab/Qwen3.8-27B-DFlash2), against main 006820408 (md5 head a473b165…, main e61cf3ef…). One drafting server per arm (--parallel 4 --context 36864, prompt cache off); the reference is the same server with "draft": false in the request, not --no-drafts. p1–p4 from the #2460 protocol, 256 tokens, greedy and temperature 0.8, seed 7.

Equality. Every request gives one token_sha256 across its 8 replies (main/head × drafted/"draft": false × alone/among 4 concurrent streams). "draft": false replies report drafts: false with no proposals; drafted ones report drafts: true. Four concurrent sampled p3 requests with seeds 7–10 match across arms too.

request token_sha256 (first 12)
greedy p1 / p2 / p3 / p4 652e25fb171f / 5d76611bb80d / a71b16f8804b / a13b502102b7
sampled p1 / p2 / p3 / p4 203e0ad7dcbf / dcb08fbb6232 / 23d722db759a / 70a063a66184
sampled p3, seeds 8 / 9 / 10 9d226375586d / 456ba2f1e144 / d43def19fc70
structured output, greedy / sampled 8eb1c8034358 / 7e0feeffaac1
resumed chat turns 0 / 1 / 2, greedy 3ee41c98f1cf / a16c2e2703f2 / b7562d85910a
resumed chat turns 0 / 1 / 2, sampled a2418fb609a2 / d1d2440c938e / dde14cda800f

Accepted drafts per round. One stream: identical on main and head, 528 accepted over 149 rounds greedy and 520 over 145 sampled (3.54 and 3.59 a round). Four streams sharing rounds: head 2.34 greedy / 2.37 sampled against main 2.30 / 2.23 (head 471 of 1,043 over 201 rounds and 466 of 1,047 over 197; main 469 of 1,091 over 204 and 458 of 1,008 over 205); p3 on four seeds, 2.32 against 2.30. Shared-round counts move a little between runs of one binary (the same mixed cell replayed on main proposed 351 then 353 drafts for p3), so I read this as no loss of acceptance on the head rather than a measured gain.

Resumed against fresh (tools/conformance.py, the qwen27-xpu profile of #2677, --gates resumed): PASS on both arms, 6/6 equal, resumed cached_tokens [4032, 4160, 4032, 4160]; the resumed turns draft (52/180 and 53/180 accepted/proposed on the head, greedy), and the per-turn hashes match between arms.

Structured output. libtfgrammar built from xgrammar v0.2.8 next to the binary. A json_schema stream drafts (150/193 accepted on main, greedy), gives the same hash drafted and with "draft": false on both arms, alone and mixed with three drafting streams, and its content parses as JSON.

No difference anywhere. Speed was not measured in this pass.

@jschmied

jschmied commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@Mirrdhyn thank you, that covers every cell ashhart asked for on 3ddfac598: one token_sha256 per request across main/head, drafted/"draft": false, alone and among four, including structured output and resumed turns, and acceptance per round level with main. @ashhart, that's the device side of item 4 done; asks 1-3 are in the commits above.

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@jschmied thanks: the four refusals each have an expectError test, Drafted.adopt has its core test with planted faults, step_ms has one source, and the note on features(last, 1) with the FeaturesGone test covering a broken order is a fair answer. And thank you @Mirrdhyn for the B70 table on this exact head: one token hash per request across main and head, drafted and per-request "draft": false, alone and among four, with structured output and resumed turns too, and acceptance level with main. That covers everything we asked. It's ready and on the landing queue now; we'll add the CHANGELOG line there.

jschmied and others added 8 commits November 9, 2026 22:11
draftFn kept &q of a by-value loop capture, so every stream of a shared
round read the last request's sampling and position for its tree noise.
Iterate by pointer. Drafts only; the target's verify keeps tokens exact.
The draft-sources host test now references the lane backend, so its
operations compile on hosts without Level Zero.
…item 5)

native/xpu_dflash2.zig puts the private xpu/drafter.zig Drafter behind
core/lanes/drafter.zig's VTable (as minimax_m3/dflash2.zig does), with
the chain/tree switch (TREE_MIN) moved unchanged. lanes.drafted.Drafted
now sits in front of the XPU lane target, which no longer drafts: it
hands Drafted the taps through features (the last verify's window) and
prefill_features (each prompt chunk as it runs).

main's drafter arithmetic is kept: the prompt's last row is absorbed
with its chunk when the target says the chunk holds it (the drafter's
projections switch kernels at 16 rows), and a round's kept rows go in
one batched absorb in request order. The round facts are main's
(Drafted.facts with the target's own shared-row rule).

The lone driver still drives the drafter itself; a stream it hands back
to the lane core is registered with Drafted.adopt (new, core).

Host test: a recorded script through main's private path (ported) and
through Drafted + the adapter makes the same drafter calls, rows, tree
noise and drafts; the facts through Drafted equal the target's own.
… DraftNotAttached

FeaturesGone and DraftNotAttached run on the real lane target (another slot's prompt tail, a depth > 0 request); the gap and held-fewer refusals through Drafted on the recorded host.
A missing stream is opened, a present one reset without a second open, and the next draft absorbs and holds (a prompt restored whole holds instead of fillers).
…fted reads the prompt's last row

Lanes.draft_step_ms (0.6) is used by both facts; the round-facts test already compares them deep. The first draft's features(last, 1) is kept: the drafter holds that row only when it shared a chunk, and core Drafted cannot ask.
A depth-3 request also passed with the check moved to depth > 1.
@ashhart
ashhart merged commit 79d3dc6 into ashhart:main Nov 9, 2026
2 of 9 checks passed
@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. 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.

jschmied added a commit to jschmied/TensorFold that referenced this pull request Nov 9, 2026
xpu_dflash2_depth_test.zig runs lanes.drafter_depth_sweep on the XPU
DFlash2 adapter from ashhart#2672 over its recorded drafter, with main's private
drafting path (the Private copy in xpu_dflash2_test.zig) on a second
drafter as the reference: depths 1..7 and a zig-zag run, prompts 6, 40
and 2100 (rows past WIN skipped), greedy and sampled. Chain depths (below
TREE_MIN) and tree depths both meet it; trees are not a deeper chain's
prefix, so the reference is the family's own path, not a deeper twin.

The sweep's holds now carry the stream's sampling as Drafted's do; without
it the sampled XPU trees were drawn greedy and differed from the reference
at depth 5. Only wiring is in the XPU test: the fixture stays in core.

Co-authored-by: EugeneClaw <[email protected]>
@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

ashhart pushed a commit to jschmied/TensorFold that referenced this pull request Nov 11, 2026
xpu_dflash2_depth_test.zig runs lanes.drafter_depth_sweep on the XPU
DFlash2 adapter from ashhart#2672 over its recorded drafter, with main's private
drafting path (the Private copy in xpu_dflash2_test.zig) on a second
drafter as the reference: depths 1..7 and a zig-zag run, prompts 6, 40
and 2100 (rows past WIN skipped), greedy and sampled. Chain depths (below
TREE_MIN) and tree depths both meet it; trees are not a deeper chain's
prefix, so the reference is the family's own path, not a deeper twin.

The sweep's holds now carry the stream's sampling as Drafted's do; without
it the sampled XPU trees were drawn greedy and differed from the reference
at depth 5. Only wiring is in the XPU test: the fixture stays in core.

Co-authored-by: EugeneClaw <[email protected]>
ashhart pushed a commit that referenced this pull request Nov 11, 2026
xpu_dflash2_depth_test.zig runs lanes.drafter_depth_sweep on the XPU
DFlash2 adapter from #2672 over its recorded drafter, with main's private
drafting path (the Private copy in xpu_dflash2_test.zig) on a second
drafter as the reference: depths 1..7 and a zig-zag run, prompts 6, 40
and 2100 (rows past WIN skipped), greedy and sampled. Chain depths (below
TREE_MIN) and tree depths both meet it; trees are not a deeper chain's
prefix, so the reference is the family's own path, not a deeper twin.

The sweep's holds now carry the stream's sampling as Drafted's do; without
it the sampled XPU trees were drawn greedy and differed from the reference
at depth 5. Only wiring is in the XPU test: the fixture stays in core.

Co-authored-by: EugeneClaw <[email protected]>
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.

3 participants