Skip to content

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

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

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

Conversation

@jschmied

@jschmied jschmied commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

This head: a04d735 (ashhart's rebase 8d60eec, 0a123ef for review 7372969935, then a comment-only commit)

  • dflash/generation.zig: the DFlash2 fuser branch is D == Draft. DSpine's own model, which also has a graph, no longer takes it. This fixes zig-macos-dev-tools (tf-qwen27-dspine-run: no field named 'config').
  • dspine/host_test.zig: the bridge fixture is pinned by size and sha256. Planted control: one flipped byte fails the test.
  • a04d73568e: three PR comments over 120 columns shortened, no code change.
  • Checked on 0a123ef: x86 targeted green (pr_check 0 errors, lean 0 new, fmt, diff-check, 12 qwen27 host steps 41/41 with 96/96 tests, check-native-cuda-host compile-cuda-tests 17/17), and an aarch64-macos -Dcpu=apple_m1 cross-build of dev-tools test-qwen27 with 0 source errors (only the link stops, on the macOS SDK frameworks). Our Mac is offline, so this round has no device run. The device rows below are from 61b6349 and 82ae37f.

Previous 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

ashhart and others added 6 commits November 24, 2026 19:40
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.

@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The overnight A-B-B-A settles the one open cell: with the pressure gate and the excluded-and-rerun sessions, no cell is slower on the branch — agent and chat at c=1 are level to the token, and at c=2 every clean branch session is at or above every clean main session. The three review fixes are in and verified (path scores with the above-1 control, the shared drawFor rule, the residency set with its owners test and two planted controls), and the served equality rows hold for DSpine and DFlash2 against plain.

This lands with our review. Our check repeats the served equality rows and the batch-of-two on an M3 Pro-class Mac with the 27B MLX 4-bit checkpoint, DFlash2 and DSpine, and the kernel contract summary. Merge state: your rebase resolved the one conflict in the served file's host setup; main has moved under the PR since (the taps ring and the fused taps in the same files), so the landing rebase is ours.

  • Synthena

@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Performance receipt required (kind:perf)

Adds an opt-in DSpine (code-bridge block) drafter for Qwen3.8-27B on Metal beside DFlash2, with a shared drafter union, contract records, residency ownership, and served/gate/run test programs. The PR description cites speed rows measured on a previous head (82ae37f) that were not rerun on the current head (61b6349).

  • Branch currently has merge conflicts against base.
  • Failing CI check(s): zig-macos-dev-tools.
  • Performance claim detected without a verified tf-receipt-v1 receipt.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json

Findings:

  • [BLOCKER] zig/src/families/qwen27/dspine/testdata/bridge-fixture.safetensors: A binary test fixture is committed directly to the repo with no provenance or size guard; the generator (bridge_fixture.py) exists, but the checked-in .safetensors can silently drift from it and bloat the diff. Suggested fix: Either generate the fixture in CI from bridge_fixture.py, or add a documented size/hash check (e.g. a test asserting the embedded file's hash matches the generator output) so drift is caught.
  • [WARNING] zig/src/families/qwen27/residency.zig: The residency append/draftBuffers paths now branch on @Hasfield between DFlash2 and DSpine buffer shapes; a future drafter struct with an optional attention_full or head field of different semantics will silently be skipped or mis-attached rather than failing to compile. Suggested fix: Give the two drafter backends a shared named contract (e.g. a buffersFrom(list) method on each model) instead of duck-typing on field presence, so a mismatch is a compile error.
  • [WARNING] zig/src/native/qwen27_drafts.zig: asks[n] is only populated when b.draft.* == .dspine, but proposeAll passes asks[0..n] unconditionally; if the drafter is DFlash2 the asks slice is read (or at least passed) with stale/undefined entries, and any future DSpine path that ignores the .dspine guard would read uninitialized Ask values. Suggested fix: Populate asks[n] for every request (or pass an empty/undefined-safe slice for DFlash2) so the Ask array is always fully initialized for the entries handed to proposeAll.
  • [WARNING] zig/src/native/qwen27_startup_line.zig: This test only forces symbol reference of Metal hooks; it does not assert anything about the adaptive block hooks being analyzed, so it can pass while the referenced decls are removed or renamed to stubs. Suggested fix: Replace with assertions on the actual analyzed values (e.g. expected block rows/limits) or delete the test if it is only a compile-reference workaround, documenting that in a comment.
  • Synthena

@jschmied

jschmied commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

New head a04d73568e: your rebase 8d60eeca87 plus two commits. 0a123ef37d has the fixes below. a04d73568e only shortens three PR comments that were over 120 columns, with no code change. Not rebased.

Red zig-macos-dev-tools (run 45473109353): ours, fixed. tf-qwen27-dspine-run instantiates GenerationOf(dspine.runtime.Model) (dspine_run.zig:129). DSpine's model has a graph field too, so the @hasField(D, "graph") branch in dflash/generation.zig:44 took it for DFlash2's model and read graph.config, which DSpine's Graph doesn't have. Now that branch is D == Draft (DFlash2's own model), and the union branch runs only for a type with dflash(). DSpine gets no fuser, which matches what the union does for .dspine (drafter.zig:50-55).

  • Our Mac is offline. In its place, a cross-build with -Dtarget=aarch64-macos -Dcpu=apple_m1 dev-tools test-qwen27: 0 source errors, and tf-qwen27-dspine-run gets through analysis and codegen to the link, which stops on the missing macOS SDK frameworks. That exe builds all three instantiations: Generation (:114), GenerationOf(dspine Model) (:129) and the served GenerationOf(Any). On 8d60eeca87, CI stops at the same exe with the error above.

[BLOCKER] fixture provenance: fixed. The new host test DSpine host fixture: the committed file is the pinned one (dspine/host_test.zig:138) pins its size (180477 bytes) and sha256 (d56618fe…a636). The generator is beside it (testdata/bridge_fixture.py, seeded mx.random.seed(7)), and the file header names it. It needs MLX and Tencent's dspine_mlx, so CI can't run it. Planted control: one flipped byte in a copy of the fixture fails the test.

[WARNING] @hasField in residency.zig: no change. The only two types are DFlash2's backend and DSpine's model (residency.zig:157, dspine/runtime.zig:286). A field with other semantics would not compile silently: the bodies read b.head.owned.items, and fields.append takes a buffer struct. The owners test with its two planted controls (your 12-02 review) checks both sets.

[WARNING] asks for DFlash2: they are never read there. proposeAll reads asks only in its .dspine arm (qwen27_drafts.zig:122-127). It switches on the same union as the g.draft.* == .dspine guard (:91), because the generation holds &d.model (qwen27_draft.zig:36). With DSpine, asks[n] and batch[n] are filled at the same n, so asks[0..n] is always written.

[WARNING] qwen27_startup_line.zig reference test: it is your 7bd6a9297e from the rebase, kept as is. It exists only to make Zig analyze those decls in the host build. Removing or renaming one is a compile error there, not a pass.

Receipt: the claims are Metal drafting speed and memory. tools/perf_receipt.py can't run Metal on this box. The body's M3 Pro rows (A-B-B-A 11-24/25) and M3 Ultra rows cover them.

Conflict with main: ashhart rebases at landing.

x86, targeted on 0a123ef37d (a04d73568e changes comments only): green (pr_check 0 errors, lean 0 new, fmt, diff-check, 12 qwen27 host steps 41/41 with 96/96 tests, check-native-cuda-host compile-cuda-tests 17/17).

@ashhart ashhart added synthena:needs-changes Reviewed by Synthena; changes requested and removed synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 4, 2026
@jschmied

jschmied commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

This re-review is on a04d73568e. No code change.

[BLOCKER] fixture provenance: in place since 0a123ef37d. DSpine host fixture: the committed file is the pinned one (zig/src/families/qwen27/dspine/host_test.zig:138-144) checks the embedded file's size (180477 bytes) and sha256 (d56618fe…a636). A file that differs in any byte fails it. I checked that by flipping one byte in a copy. The generator is zig/src/families/qwen27/dspine/testdata/bridge_fixture.py, seeded with mx.random.seed(7). To regenerate, on an Apple silicon Mac with mlx and Tencent's dspine_mlx importable, run python3 bridge_fixture.py bridge-fixture.safetensors in that directory. Then put the new size and sha256 in the test. CI can't run it because it needs MLX on Apple silicon. That is also why the generator's dependency isn't in docs/environment.md: no CI or serving path needs it.

Speed rows: these are Metal rows from our M3 Pro, which is offline. The cells in the body were measured on 82ae37ff70. The quiet A-B-B-A (11-24/25) ran on 61b6349719. That is not just tests and comments since then: 61b6349719 added the path scores, the lone-stream draw and the residency set (now 9c751590d6), and your rebases 8d60eeca87 and earlier moved the branch onto newer main. After 8d60eeca87 the diff is only generation.zig (served instantiation GenerationOf(Any) takes the same dflash() branch as before; only the run tool's DSpine-only instantiation changed), host_test.zig and three comments. So the rows don't cover this head's served path. We'll rerun them on our Mac when it's back, and your planned M3 Pro-class check from 12-02 would cover them too.

The residency.zig and qwen27_drafts.zig warnings are the same points as last round. My previous reply (#issuecomment-7399455493) answers them with file:line: no field mismatch compiles silently, and asks is read only on the DSpine arm, which fills it.

@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner

A correction to our automated review: The fixture is already pinned by size and sha256 in host_test.zig and both warnings were answered with file:line; this is a new opt-in drafter (kind:feature, no receipt against main), and the landing rebase and Metal device rows are ours.

  • Synthena

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

kind:perf Classified by Synthena as performance improvement synthena:needs-changes Reviewed by Synthena; changes requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants