Skip to content

qwen27 Metal: DSpine drafter for Qwen3.8-27B, opt-in - #2634

Open
jschmied wants to merge 22 commits into
ashhart:mainfrom
jschmied:dspine-metal
Open

jschmied wants to merge 22 commits into
ashhart:mainfrom
jschmied:dspine-metal

Conversation

@jschmied

@jschmied jschmied commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

This head: 61b6349 (ashhart's eeeaee5 plus one commit for review 7111733774)

  • Tree scores: DSpine's Tree.scores now hold path scores (draft_tree.pathScores after grow), which is what local reads.
  • Shared rounds: DSpine takes the stream's draw only through DFlash2's rule (drawFor: a lone sampled stream, drafting from where it stands).
  • Residency: DSpine's buffers adds attention, top-k, the frame pool and the prepared and tiled weights (shared appendDraft), and hold/drop attach its follow hook (shared setDraft).
  • Linux host on 61b6349: test-lone-copy-host (path-score test; planted control: raw own log-chances read as paths give a chance above 1), test-metal-residency-owners-host (new DSpine owners test; planted controls: the old buffers leaves 9 allocations out, and with no hook a later frame buffer never joins), the qwen27/DSpine host set, zig fmt --check, git diff --check and pr_check. The macOS targets compile for aarch64-macos.
  • Mac (M3 Pro, -Dcpu=apple_m1) on 61b6349, tensorfold-native md5 aa5c55f70092d232cdee5da6b85d9904: the qwen27/DSpine build and tests 93/93 steps, 360/362 tests (2 skipped); DSpine contract 9 kernels pass, 3 controls red; served T=0 c=1/c=2 DSpine == plain and DFlash2 == plain 12/12, T=1 c=2 seed 7 DSpine == DFlash2 12/12; tf-qwen27-dspine-gate batch of 2: 30/30 proposals equal to each stream's own pass. Speed rows below were measured on 82ae37f and not rerun.

Previous head: 82ae37f, rebased onto main e6094de on the user's request

Rerun on 82ae37f:

  • Metal, M3 Pro 36 GB:
    • Build: native test-qwen27 test-qwen27-startup-host -Dcpu=apple_m1, 82/82 steps, 217/219 tests. The 2 skips are env-gated MTP tests. tensorfold-native md5 is 35cc1c84.
    • Contract --only "qwen27 dspine": SUMMARY 9 kernels: 9 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems.
    • zig build test: 965/970 steps. The 3 failing tests (DeepSeek-V4.1 vision config, persistence identity, native memcpy nm step) fail identically on main e6094de, so nothing is new against main.
    • Served --parallel 2 --context 2048 (concurrency 1 and 2), stock 8 GiB margin:
      • T=0, c=1 and c=2: DSpine == plain 24/24 and DFlash2 == plain 24/24.
      • T=1, c=2, seeded (seed 7): DSpine == DFlash2 12/12.
    • tf-qwen27-dspine-gate: a batch of 2 == each stream's own pass 30/30. The one-round gate (6/16, 149/240) is unchanged.
  • Linux host (GB10):
    • Host tests: 18 steps, test-qwen35-dspine-host and 15 test-qwen27-*-host steps among them, plus test-environment-host and test-env-defaults-host. 69/69 steps, 890/892 tests (2 skipped).
    • zig fmt --check, git diff --check, pr_check (0 errors, lean 165 vs 165, 0 new).
    • The macOS targets (native, test-qwen27, tf-kernel-contract) compile for aarch64-macos (no SDK, so no link) with 0 errors.
  • CUDA (GB10, sm_121): native test-cuda-host -Dnvcc=/usr/local/cuda/bin/nvcc -Dsm=121, 618/618 steps, 6229/6268 tests (39 skipped). cuda_dspine_weights.zig reads the shared core.dspine table, and main left it unchanged.

Carried, not rerun: the kernel-contract full sweep (546 kernels) and every speed row below, all measured on the pre-rebase head before 0445547. The speed claim's code (DSpine runtime, kernels, tree walk) did not change in the rebase. No CHANGELOG commit. Proposed CHANGELOG line: qwen27 Metal: DSpine drafter for Qwen3.8-27B behind --drafter, opt-in (#2634).

Opt-in: nothing changes unless --drafter names a DSpine folder. On main since #2633 landed; the CUDA DSpine, core.dspine and the shared tree walker it reuses are main's.

What this changes

DSpine for Qwen3.8-27B on Metal, served, in its own qwen27/dspine/ (Metal's DFlash2 body is conv-wrapped with its own tap set, so it is not reusable as a body). Reused: shared_attention, draft_ops, the affine-4 prepare, bf16_topk, the target head kernels, core.dspine (config, table walk, the checkpoint's 71-tensor table and TG's head input) and lanes.draft_tree.

  • qwen27/dspine/config + weights: the 27B checkpoint pinned (NotStockDSpine otherwise), its 71 tensors exactly, from core.dspine's table (the CUDA loader reads the same table).
  • Host reference of bridge, tables and tail, rounding where Tencent's dspine_mlx rounds.
  • Metal runtime: plain 5-layer body (block-causal + window mask; caches wrap past 8192 over ring slots), the bridge after each layer, one full-vocab head pass + top-16, the exact base term at the 240 candidates, the exact-sender table kernel, best-first trees through lanes.draft_tree.grow.
  • dflash/generation becomes GenerationOf(D); qwen27/drafter.zig Any = DFlash2 | DSpine behind one Generation, so lanes/slots/keep/residency go through it. --drafter DIR picks the kind from config.json (core.dspine.declared); DFlash2 stays the default.
  • Every admitted stream drafts, as DFlash2 and CUDA do: each drafting stream has its own DSpine context, all blocks in one pass, draft_slots = draftSlots(). TF_Q27_DRAFT_SLOTS caps it for DSpine as for DFlash2. Ring and K/V are sized to min(8192, capacity + window) rows (exact below 8192: no context wraps), 280 MiB a stream at 4096.
  • T=1: the lane's sampling and draft position go into draft_tree Candidates (the same keyed-noise path as CUDA).
  • The eight tf_dspine_* kernels are in the Metal kernel contract (zig/tests/contract/metal_qwen27_dspine.zig): served shapes (bridge at 16/32/128 rows, hidden 5120, code 1024, rank 512; senders/base/table at a stream's 15 head rows, K 16) against a float64 host reference, senders bit-exact; three planted controls go red.
  • Device memory: DSpine 2.7 GiB (copies the 3 head tensors, not the target shard), DFlash2 1.6 GiB. A stream that does not fit is refused naming the drafter and its size beside the weights and the stock 8 GiB margin; no new setting.

Checks (M3 Pro 36 GB, no tensor units)

  • test-qwen27, test-qwen27-startup-host, the environment host tests, native build, fmt, lean (no new problems), pr_check (0 errors).
  • Metal kernel contract (tf-kernel-contract from zig build, -Dcpu=apple_m1, with this Mac's --rotary-accuracy sweep file): SUMMARY 546 kernels: 546 pass gates 1-4, 0 fail, 3 known findings; 576 controls: 576 red as planted, 0 missed; 0 limit problems. DSpine alone (--only "qwen27 dspine"): SUMMARY 9 kernels: 9 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems.
  • One-round gate against dspine_mlx (its taps and anchor), 4 prompts × 4 rounds: BF16 15/16 chains, 233/240 positions; affine-4 body against an affine-4 reference 14/16, 222/240; served mode (bridge linears affine-4 too) 6/16, 149/240; control (second pass off) 3/16.
  • Served exactness on this head, --parallel 2 --context 2048, multi.py agent 4×256 and chat 8×256: at T=0, c=1 and c=2, DSpine's and DFlash2's outputs equal plain decode (24/24 each); at T=1, c=2, DSpine's equal DFlash2's (12/12). A batch of 2 is bit-identical to each stream's own pass (30/30 proposals).
  • CUDA side of the shared table (cuda_dspine_weights.zig reads core.dspine.tgInput, math unchanged): test-qwen35-dspine-host, test-cuda-host and the CUDA native build (sm_121) pass on the GB10 at this head.

Speed (M3 Pro 36 GB, qwen38-27b-mlx-4bit)

One stream, drafter loop, T=0, up to 256 tokens, 15 nodes, the prompt set from #2592, decode tok/s:

class DFlash2 tree DSpine tree change
agent (5 prompts that fit 8192) 14.61 16.29 +12 %
chat (8, ctx 4096) 17.66 15.12 −14 %
code (8, ctx 4096) 20.43 18.17 −11 %

A greedy chain instead of the tree was slower in every class (agent +0, chat −25, code −21 %), so the branch has no chain mode.

Served, --parallel 2 --context 2048, aggregate tok/s (multi.py, agent 4×256, chat 8×256):

cell plain DFlash2 DSpine, every stream DSpine, TF_Q27_DRAFT_SLOTS=1
c=1 T=0 agent 4.63 6.77 6.74 6.76
c=1 T=0 chat 7.93 18.77 16.43 16.94
c=2 T=0 agent 6.45 7.25 6.44 6.82
c=2 T=0 chat 13.52 24.06 14.56 15.11
c=2 T=1 agent – 7.12 6.00 6.55
c=2 T=1 chat – 23.81 12.84 14.15

Without tensor units every DSpine kernel is compute-bound in rows (one pass 37.8 ms for 1 stream, 68.4 ms for 2), so on the M3 Pro drafting both streams runs 4–9 % below drafting one at c=2; TF_Q27_DRAFT_SLOTS=1 gives the one-stream behaviour. The M3 Ultra cells (one stream +11..+62 % on agent) were on the earlier one-slot head; 2-stream Ultra cells on this head are the open number.

36 GB Macs: with the stock 8 GiB margin no DSpine stream fits at context 4096 (4.3 GiB needed, 3.1 GiB left beside the weights and the drafter): the server refuses by name and says how far iogpu.wired_limit_mb must rise, or to lower --context. The served M3 Pro numbers above used a test-only 4 GiB margin build, not committed. Larger Macs are not affected.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@jschmied

jschmied commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart #2634 now serves: --drafter <DSpine folder> on Metal, T=0 and T=1, trees through the walker shared with #2633. On our M3 Pro: agent +12 %, chat −14 %, code −11 % against DFlash2's 15-node tree, greedy text equal to plain decode; numbers in the body. Ready for your M5 Ultra and M3 Ultra cells. One rebase is coming to pick up #2633's block_sum fix (today's zig failure is that check, not Metal code); the Metal code won't change. Open question in the body: on a 36 GB Mac the 8 GiB working-set margin refuses DSpine.

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@jschmied, M3 Ultra cells on 71afe36d76. Qwen3.8-27B MLX 4-bit target, --context 40960, 256 tokens a reply, fresh servers in the order DFlash2, DSpine, DSpine, DFlash2, drafts off, median of two runs a side.

Exact. On every agent request, at T=0 and seeded T=1, the DSpine reply equals the DFlash2 reply and the reply with drafts off.

Agent-shaped requests, one stream (decode tok/s):

Request (prompt tokens) T DFlash2 DSpine Change
short (3,786) 0 108.9 176.3 +61.9%
short 1 102.6 156.2 +52.3%
mid (8,822) 0 89.0 112.3 +26.2%
mid 1 63.8 70.9 +11.1%
long (13,465) 0 62.4 98.1 +57.3%
long 1 53.7 70.5 +31.3%
xlong (22,719) 0 44.6 42.2 -5.2%
xlong 1 52.8 62.3 +18.1%

That's a bigger agent gain than on the GB10.

Chat and code (--parallel 2, aggregate tok/s):

Prompt T Streams DFlash2 DSpine Change
chat 0 1 82.6 72.5 -12.2%
chat 0 2 121.2 74.7 -38.3%
chat 1 1 71.8 65.1 -9.3%
chat 1 2 101.6 52.9 -47.9%
code 0 1 117.1 96.9 -17.2%
code 0 2 146.6 89.1 -39.2%
code 1 1 107.2 95.9 -10.6%
code 1 2 138.8 85.7 -38.2%

One stream matches the GB10 picture. Two streams are where Metal differs: the server says "DSpine drafts for 1 stream", against DFlash2's "drafts for 2 streams". The patch drafts slot 0 alone (the if (g.draft.* == .dspine) branch in the diff's qwen27_served window code). So at two streams the second runs plain and the pair barely beats one stream. On CUDA, #2633 drafts every stream and its two-stream cells lost no more than one stream did.

Before this lands: could DSpine draft every admitted stream on Metal, as DFlash2 does and as #2633 does on CUDA? If one slot is a deliberate first step, please say so in the body and the CHANGELOG, and refuse or warn at --parallel > 1 so nobody opts in and loses half their throughput. The M5 Ultra cells come next, on whichever head you'd like run.

@jschmied

jschmied commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart every admitted stream now drafts by default, as DFlash2 and CUDA do: ac975903e reverts the one-slot default (lb.draftSlots()), and TF_Q27_DRAFT_SLOTS=1 still gives one drafting stream.

Measured on our M3 Pro (36 GB, no tensor units), 27B MLX 4-bit, --parallel 2 --context 2048, aggregate decode tok/s, agent 4×256 and chat 8×256 tokens:

cell plain DFlash2 DSpine, all streams (new default) DSpine, TF_Q27_DRAFT_SLOTS=1
c=1 T=0 agent 4.63 6.77 6.74 6.76
c=1 T=0 chat 7.93 18.77 16.43 16.94
c=2 T=0 agent 6.45 7.25 6.44 6.82
c=2 T=0 chat 13.52 24.06 14.56 15.11
c=2 T=1 agent – 7.12 6.00 6.55
c=2 T=1 chat – 23.81 12.84 14.15

Exact: 32 of 32 comparisons byte-identical. At T=0 (c=1 and c=2), DSpine with either setting and DFlash2 equal plain decode; at T=1 c=2, DSpine equals DFlash2 and the one-stream run.

On this GPU a 2-stream pass costs about two 1-stream passes, so drafting both streams is 4-9 % slower than drafting one at c=2, and DFlash2 still leads there. Could you run the 2-stream cells (c=2, agent and chat, T=0 and T=1, TF_Q27_DRAFT_SLOTS unset and =1) on an M3 or M5 Ultra on ac975903e? With tensor units the second stream should cost much less, and that decides whether all streams stays the default on Macs.

Gates on ac975903e: test-qwen27 46/46 steps, test-qwen27-startup-host, the native build, zig fmt, lean 398 vs 398 (0 new), pr_check 0 errors.

Proposed CHANGELOG line (Unreleased): "- The 27B on Metal: DSpine drafts every admitted stream, as DFlash2 does; TF_Q27_DRAFT_SLOTS=1 keeps one (#2634)."

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, that's the change we asked for. Every admitted stream now drafts by default
(zig/src/native/qwen27_lanes.zig:566-569), TF_Q27_DRAFT_SLOTS=1 still gives one drafting stream, and all 32
replies are byte-equal. We'll run the two-stream cells on the M3 Ultra and the M5 Ultra, with the variable unset and
set to 1, to settle the Mac default.

A few things before that:

  1. Rebase. qwen CUDA: DSpine drafter for Qwen3.8-27B, opt-in by --drafter #2633 has landed, so the branch now conflicts with main in core/dspine.zig, core/dspine_test.zig,
    qwen3_5/cuda_dspine_weights.zig and native/qwen27_served.zig. Please rebase onto main, dropping qwen CUDA: DSpine drafter for Qwen3.8-27B, opt-in by --drafter #2633's commits
    and keeping 7b5f152fa's table on top, then take it out of draft. We'll run the cells on that head, plus a GB10
    check, since 7b5f152fa also touches the CUDA loader.
  2. Kernel contract. The eight tf_dspine_* kernels in zig/kernels/metal/qwen27/dspine.metal (lines 22-131) aren't
    registered with the Metal kernel contract yet. Please add their test type under zig/tests/contract/ with the
    served shapes and a planted control, and post the zig build kernel-contract -Dcpu=apple_m1 SUMMARY line.
  3. TF_DSPINE_CHAIN. It's registered and refused by name, which is right. But in your receipt the chain is slower
    than the tree in every class (agent +0 %, chat −25 %, code −21 %), and we only add a setting when it measurably
    helps. Could it go, or become a test-only path? It's also read on every tree call
    (dspine/runtime.zig:262), so if it stays, please read it once at load.
  4. docs/environment.md:23. The TF_Q27_DRAFT_SLOTS row names DFlash2 only. DSpine takes the same count now.
  5. The description. It still says DSpine drafts slot 0 only and describes the reverted one-stream default. Please
    update it for the current head.

On the 36 GB question: please keep the stock 8 GiB margin here. A Mac without the room should go on refusing DSpine by
name. We'd rather not add a setting for it in this PR.

We'll write the CHANGELOG line when it lands. Main is closed for a release right now, so landing waits until it
reopens.

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart thanks, all five done, and it is out of draft. The head is now 0349d0668.

  1. Rebased onto main 33ada77, qwen CUDA: DSpine drafter for Qwen3.8-27B, opt-in by --drafter #2633's three commits dropped (landed as 8dd1ba0, 67711a6, 7800202). The table commit applied cleanly over main's core/dspine.zig, dspine_test.zig and cuda_dspine_weights.zig, with the same patch as 7b5f152. The only conflict was qwen27_served.zig: main's startup-receipt spans plus the branch's q.drafter.Any and the drafter kind in the startup line. I also dropped the one-slot default (5be4e1d) together with its revert (ac97590): same tree, two fewer commits. GB10, on 0349d06 (CUDA-side commit 5a04498): test-qwen35-dspine-host and test-cuda-host pass, and the CUDA native build (sm_121, nvcc 13.0) builds.
  2. Kernel contract (eb5fe43): zig/tests/contract/metal_qwen27_dspine.zig registers the eight tf_dspine_* kernels (nine registrations: read's xn and rms are each checked), and core/contract/qwen27_dspine_records.zig holds their launch records.
    • Shapes: the bridge kernels run at 16, 32 and 128 rows (1, 2 and 8 drafting streams) with hidden 5120, code 1024 and rank 512. senders, base and table run at a stream's 15 head rows with K 16.
    • Each kernel is checked against a float64 host reference; senders is checked bit for bit.
    • Three planted controls go red: message reading its own row's S, read summing its squares in half, and table using the first sender's G and V for every sender.
    • tf-kernel-contract -Dcpu=apple_m1, full run on the M3 Pro: SUMMARY 546 kernels: 546 pass gates 1-4, 0 fail, 3 known findings; 576 controls: 576 red as planted, 0 missed; 0 limit problems; gates 2962177 ms, limits 5269 ms.
    • DSpine alone: SUMMARY 9 kernels: 9 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems.
    • The contract host tests (with the launch map) are 33/33 steps and 237/237 tests; the map has 708 launches, 0 missing.
    • Two notes from the specs: write's fp16 requirement is 40x, not the default 100x, because two bf16 norm nodes widen its bound. And tf_dspine_read's max(mean, tiny) turns a NaN mean into tiny, so a row holding a NaN keeps finite outputs except at the NaN. The reference matches this.
  3. TF_DSPINE_CHAIN is gone (04a60eb): the greedy-chain branch, its registry row, the two environment-test rows and its docs row.
  4. docs/environment.md TF_Q27_DRAFT_SLOTS: "DFlash2 and DSpine draft for at most the smaller of this count and the admitted streams" (04a60eb).
  5. PR description for the current head is below.

36 GB: the stock 8 GiB margin stays, with no new setting. The refusal now names the drafter (0349d06): "--parallel 1 needs 4.3 GiB for its streams and 512-row prompt scratch at a 4096-token context; 3.1 GiB remains beside the weights, the DSpine drafter (2.7 GiB) and an 8 GiB margin: Metal lets this Mac use 28.1 GiB; sudo sysctl iogpu.wired_limit_mb=29958 raises that limit enough for one stream at this context until reboot (or lower --context)". qwen27_served.zig is 595 lines.

Gates on 0349d06: test-qwen27 46/46 steps, 191/191 tests; test-qwen27-startup-host 4/4; test-environment-host 13/13; test-environment-report-host 35/35; native 66/66; zig fmt clean; lean 386 vs 386 (0 new); pr_check --base 33ada77c3 --pr 2634: 0 errors, 1 warning (his Unreleased bullet).

Served exactness on the new code (test-only 4 GiB margin build, uncommitted, --parallel 2 --context 2048; multi.py agent 4x256 and chat 8x256): at T=0, c=1 and c=2, DSpine's and DFlash2's outputs equal plain decode (24/24 each). At T=1, c=2, DSpine's equal DFlash2's (12/12). Aggregate tok/s is within noise of yesterday's receipt: DSpine c=1 6.53/16.14, c=2 6.24/13.66; DFlash2 c=1 6.87/19.22, c=2 7.65/24.85; plain c=1 4.49/7.39, c=2 6.01/13.40.

@jschmied
jschmied marked this pull request as ready for review November 10, 2026 13:13
@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The rebase is clean on main with only this PR's commits. TF_DSPINE_CHAIN is gone, the TF_Q27_DRAFT_SLOTS row names DSpine, the eight DSpine kernels are in the Metal contract with planted controls, and the 36 GB Mac keeps its stock margin.

Two things are left:

  1. The description: it still opens as a draft stacked on qwen CUDA: DSpine drafter for Qwen3.8-27B, opt-in by --drafter #2633, says DSpine drafts slot 0 only, describes TF_DSPINE_CHAIN and names older heads. Please update it for 0349d0668.
  2. Kernel contract: please post the zig build kernel-contract -Dcpu=apple_m1 SUMMARY line from this head.

We'll write the CHANGELOG line. After that we run the two-stream cells on our M3 and M5 Ultra Macs, and a GB10 check of the commit 11 CUDA loader on this head.

  • Synthena (Ash's Agent)

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart both should be in place now; our update at 13:13 may have crossed with your read:

  1. The description was replaced for 0349d0668: it opens with "On main since qwen CUDA: DSpine drafter for Qwen3.8-27B, opt-in by --drafter #2633 landed", says every admitted stream drafts (TF_Q27_DRAFT_SLOTS caps it), has no TF_DSPINE_CHAIN, and names no older head. If you still see the old text, a reload should show it.
  2. Kernel contract on 0349d0668 (zig build kernel-contract -Dcpu=apple_m1, M3 Pro): SUMMARY 546 kernels: 546 pass gates 1-4, 0 fail, 3 known findings; 576 controls: 576 red as planted, 0 missed; 0 limit problems. DSpine alone: SUMMARY 9 kernels: 9 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems.

The GB10 side is also checked on this head: test-qwen35-dspine-host, test-cuda-host and the CUDA native build (sm_121) pass.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, both are in. The description matches 0349d0668, and the kernel contract from this head passes 546 of 546 with all 576 controls red, the DSpine registrations among them. Thanks also for the GB10 host checks of the CUDA loader commit.

Nothing more is needed from you. Next we run the two-stream cells on our M3 Ultra and M5 Ultra Macs with TF_Q27_DRAFT_SLOTS unset and set to 1, plus a GB10 check of the CUDA loader on this head, and we'll write the CHANGELOG line.

  • Synthena (Ash's Agent)

jschmied added a commit to jschmied/TensorFold that referenced this pull request Nov 10, 2026
, ashhart#2464, ashhart#2375, ashhart#2634) and adds row 29, DSpine (ashhart#2633)

Rebased onto main after ashhart#2760's row 28 (Scale index), which stays as on main. DSpine is row 29 with ashhart#2633's
final GB10 ranges: agent 2-20 % faster, chat and code 10-19 % slower.
ashhart pushed a commit that referenced this pull request Nov 11, 2026
, #2634) and adds row 29, DSpine (#2633)

Rebased onto main after #2760's row 28 (Scale index), which stays as on main. DSpine is row 29 with #2633's
final GB10 ranges: agent 2-20 % faster, chat and code 10-19 % slower.
@AIFlowML

Copy link
Copy Markdown
Contributor

On exact head 0349d066, zig build test-qwen35-dspine-host -Dcpu=apple_m1 -j5 --summary all passed all 73 host tests on M5 Max with Zig 0.17.0. The trial merge into 9ba855b3 has seven conflicts. I isolated the two shared-core ones in scratch: kept main's TF_DSPINE_WINDOW narrowing helper and its regression (5602be64), then added the PR's checkpoint tensor table and its input-rounding test beside them.

With those two files combined on the PR head, the same command passed 61 freshly run tests, and the unchanged 13-test artifact was reused. The shared suite gained the narrowing test. This verifies the shared-core resolution only. The registry and four remaining serving/drafter files need integration, and I did not run a DSpine checkpoint on this Mac.

Igor Lessio - AIFLOW LABS

jschmied and others added 22 commits November 24, 2026 19:40
…t reference of bridge, tables and tail

The Metal port's first part, over core.dspine (shared with the CUDA drafter):
- config: core.dspine.parse pinned to tencent/Qwen3.8-27B-DSpine-b16 (else NotStockDSpine), bind to the target
- weights: the checkpoint's 71 names exactly, BF16 borrows; every version scalar must be 1 and out.weight zero
- host: one bridge write, TG/TSV rows, top-k (ties to the lower id) and the greedy score table, rounding where
  Tencent's dspine_mlx rounds; the kernels' contract will compare against it
- testdata/bridge-fixture.safetensors from dspine_mlx itself at small widths (bridge_fixture.py): the last write,
  TG, TSV, candidates and drafts match exactly, the early write within an ulp; the message-dropped control moves
…d the one-round gate against dspine_mlx

- runtime: the checkpoint on the target's device, body linears affine-4 (or BF16 with --mode bf16), the bridge
  BF16 as dspine_mlx keeps it; gate/predecessor_gate/prev packed; TG built at load through the target head
- forward: committed taps into 8,192-row K/V caches; the block (anchor + 15 masks) through plain layers with a
  block-causal, windowed mask, each closed by the bridge write; full-vocab head, top-16, senders, TSV rows,
  the exact-sender table; candidates sorted ascending and the chain walked by core.dspine.chain
- kernels (qwen27/dspine.metal): add, bridge read/code/message/write, senders, table
- kernels_test: on the dspine_mlx fixture the write is within 2 ulps, the table chains its drafts, and a zero
  write (message dropped) no longer matches
- tf-qwen27-dspine-gate: the MLX reference's taps and anchor in (16 rounds, 4 prompts), drafts compared.
  BF16 linears: 15/16 chains identical, 233/240 positions; control (second pass off) 3/16, 90/240.
  Affine-4 body: 8/16, 165/240.
Only an unwrapped context (below the 8,192 window) is drafted so far.
…e-4 bridge; 53 to 31 ms a proposal

- The base term (raw * norm . head row) is no longer a second full-vocab head pass: tf_dspine_base dequantizes
  the 240 candidates' rows of the target lm_head (its MLX layout read once more from the target's files) and
  sums in f32, as dspine_mlx's RefinementTail does. The head runs once, over the 15 rows past the anchor.
- --mode q4 (default) prepares the bridge's reads, writes, packed gates and the TSV pair affine-4 as well;
  q4_body keeps the bridge BF16 (as the reference); bf16 for the port check.
- TF_DSPINE_PROFILE: each layer, the head and the tail in their own command buffers with their GPU times.
  M3 Pro, q4: 3.4 ms a layer (16-row blocks are compute-bound here), head 11.3 ms, tail 2.9 ms.
- Gate against dspine_mlx: BF16 15/16 chains, 233/240 positions. Against a reference whose body linears
  carry this affine-4 exactly (same groups, scales, biases): q4_body 14/16, 222/240.
…y chains through them

- dflash/generation: GenerationOf(D) takes a drafter with binds, tapIds, tapWidth, failed, idle,
  committed_end, absorb and propose; Generation stays GenerationOf(DFlash2's Model), which gains those methods.
- dspine runtime: the same interface; absorb appends the accepted taps at once, propose returns its chain
  (at most `nodes` of the 15 greedy drafts) as a one-branch tree.
- tf-qwen27-dspine-run: plain greedy, DFlash2 trees and DSpine chains on one stream (4,096 context), the
  same four prompts. M3 Pro, qwen38-27b-mlx-4bit, 256 tokens, 15 nodes, tokens a round:
  poem 2.75 / 1.83, primes 10.75 / 10.75, code 13.38 / 12.59, agent 4.92 / 3.88 (DFlash2 / DSpine q4);
  the bridge in BF16 (q4_body) moves DSpine little (agent 4.06). A round costs about the same for both
  (the 16-row verify dominates), so chains trail DFlash2's trees until DSpine drafts trees from its table.
… the table's scores read as logits

A tree walker over the exact-sender table softmaxes each sender's row; the table holds raw * norm . head + rms * m . TG,
and times 1 / rms of the written row it is that row's logits (the sender's own refined norm differs a little).
… and the context (--context)

The CUDA runs' prompts.json (class, id, ids): every prompt of a class whose ids leave room for the reply in the
context. M3 Pro, the five agent turns under 8,192: DSpine's chain 14.65 tok/s against DFlash2's tree 14.6.
…r the exact-sender table

propose() hands grow() each row's 16 ids (ascending) and the table times each row's final-norm scale, so a
sender's row softmaxes as logits; TF_DSPINE_CHAIN keeps the greedy chain. tf-qwen27-dspine-run: --no-plain.
… DSpine behind one Generation

q.drafter.Any picks the kind from the checkpoint's config (core.dspine.declared), admits it against the target,
and gives Generation, the lane backend, keep, slots and residency one interface (ring, reset, recover, standAt).
DSpine keeps DFlash2's taps ring: absorb writes the ring, each proposal catches the K/V caches up from it,
so kept states save, restore and move slots as DFlash2's do; its caches wrap past the 8192 window.
DSpine drafts slot 0 alone; other slots keep a taps ring only. A sampled stream's tree aims at its keyed draws.
The head copy keeps the three head tensors, not the target's mapped shard: the drafter takes 3.0 GiB, not 6.5.
… in one pass

Slots past 0 hold DSpine's K/V caches beside their taps ring (a lane Context), and draft_slots
follows draftSlots() for DSpine too. One batched forward runs every drafting stream's block:
linears, bridge and head over all rows, attention per stream over its own cache and mask, the
top-k and table tail per stream. Below the 8192 window a served context sizes the ring, K/V and
attention to the rows a stream can reach (exact: nothing wraps), 560 -> 280 MiB a slot at 4096.
The gate checks a batch of two against each stream's own pass and takes --fit.
…le both loaders read

core/dspine.zig holds every tensor's name, dtype and dims in the config's terms (globals, the
code bridge, each layer's) with find, names and dims. Metal's weights.zig checks inventory,
shapes and version scalars against it; CUDA's bridge loader expects its tensors through it.
TG's device input row bf16(norm * W_write[last][:, k]) is core.dspine.tgInput, which Metal's
runtime and CUDA's table both feed to the target head. The host reference keeps dspine_mlx's
own rounding, bf16(head * norm) . W, which the fixture pins (the device form is off it by more
than its 5-ulp bound).
…t reference, with planted controls

metal_qwen27_dspine.zig runs tf_dspine_add, read (xn and rms), code, message, write, senders, base and table at the
stock 27B drafter's shapes (rows of 1, 2 and 8 streams' 16-row blocks; a stream's 15 head rows) through gates 1-4
against float64 (senders by an exact copy check); three source edits must go red: message reading its own row's S,
read's squares summed in half, table taking the first sender's message. Their launches are registered for gate 5
(M1/M2 compiled limits measured offline: 1024 each).
…r interface

ashhart#2634 moves Context.ring's config into the context, so flint's absorb call
drops the argument (X6 carried this; the X7 rebase lost it).
The MTP head's device check and load move to qwen27_mtp_flags.zig, unchanged.
The Moss image, Moss decoder and DSpine contract suites register in the same
order behind one create in metal_image_dspine_suites.zig.
Use explicit blocks for the DFlash2-only optional captures. This preserves the adaptive reset and makes the rebased source pass zig ast-check.
…as DFlash2's

- Tree.scores hold path scores (`draft_tree.pathScores` after `grow`), which `local` reads by
  subtracting the parent's; a child's chance can no longer go above one in a shared round.
- A DSpine request takes the stream's draw only through `drawFor`, DFlash2's rule (a lone sampled
  stream, drafting from where it stands); a shared round's tree keeps the drafter's own scores.
- `Model.buffers` adds attention, top-k, the frame pool and the prepared and tiled weights through
  `appendDraft`; `residency.hold`/`drop` attach and detach DSpine's follow hook (`setDraft`).
@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart the quiet rerun on our M3 Pro shows no loss. The chat c=2 drop I reported was noise from the Mac's load, so it's no reason to hold this from our side.

Setup: the same as before.

  • Arms: A = main 753fb34a28 (md5 3b2cd2ed…) and B = 61b6349719 (md5 60251e06…), the head you reviewed before your rebase onto 8d60eeca87.
  • Model and serve: the 27B MLX 4-bit with the DFlash2 drafter, --parallel 2 --context 2048 --prompt-cache-gib 0.
  • Sessions: each gets a fresh server and an unscored warm-up; prompts are 4 agent and 8 chat, 256 tokens.
  • Order: five rounds of A,B,B,A, run overnight. Before each round a gate waited until antivirus, Java, Chrome and VMs were below 10 % CPU and memory pressure was normal. It held the run from 02:50 to 04:30.
  • Exclusions: two sessions logged a pressure warning (one A, one B). They were excluded and rerun once at the end, and both reruns were clean. That leaves 10 clean sessions per arm.

Aggregate tok/s, clean sessions, mean (min–max):

cell A (main) B (branch) B−A
agent c=1 7.529 (7.52–7.53) 7.528 (7.52–7.53) 0.00
chat c=1 20.423 (20.41–20.43) 20.423 (20.40–20.43) 0.00
agent c=2 8.344 (8.04–8.48) 8.404 (8.28–8.47) +0.06 (both arms bimodal)
chat c=2 26.175 (26.13–26.22) 26.249 (26.22–26.28) +0.07

At chat c=2, every clean B session is at or above every clean A session; they touch at 26.22. No cell is slower on the branch.

What explains the earlier −0.6 %: I compared two separate builds of main, A and A'. Their binaries differ (3,060 bytes, same size), so Mac builds of one commit aren't byte-identical. That day the Mac was under load from antivirus, Java and a VM, and only 2 of 20 sessions had no warning. Tonight, with the gate, the difference is gone in both directions.

Tokens:

  • T=0: identical in all 22 sessions, A against B and c=1 against c=2 (agent a1f73845a2db, chat 837a341c07d5).
  • Seeded T=1 (seed 7): A against B at c=1 and c=2 was equal in the earlier run, agent 4/4 and chat 8/8.

DSpine on B, two sessions from the A-A' day (loaded Mac, so a floor, not a final number):

  • agent c=1 decode: 22.13 / 22.06
  • chat c=1 decode: 21.04 / 20.85
  • agent c=2 aggregate: 8.14 / 8.13
  • chat c=2 aggregate: 21.57 (no warning) / 20.72 (2 warnings)

So the earlier 20.72 came from load, not a change. Tonight's run hit its 06:00 stop before its own DSpine pass. If you want quiet DSpine rows next to these, I'll add them tonight.

All measured on 61b6349719. Your rebase 8d60eeca87 with 8410eddc52 is not measured here. Say if you want this rerun on the rebased head.

This branch has not been deployed

No deployments
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