Skip to content

qwen27 metal: a lone sampled stream's draft tree ranks its candidates with the target draw's keyed noise - #3978

Merged
ashhart merged 6 commits into
ashhart:mainfrom
hobbesd:metal-draft-follows-draw
Nov 21, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
hobbesd:metal-draft-follows-draw

Conversation

@hobbesd

@hobbesd hobbesd commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

A sampled qwen27 stream on Metal draws each token as a keyed Gumbel race (lanes.sampling), but its DFlash tree ranks candidates by likelihood alone. The selector already has the hook for the draw's noise (selector.Options.noise, temperature); CUDA (94ce0d1c4) and XPU feed it, the Metal lane backend never did. With this change draftFn passes a sampled stream's seed and temperature while it is the only stream drafting, so its tree follows the token the draw will pick. The target's draw still decides every token; greedy requests take the same path as before.

Streams that share a round draft as on main (since 16c52c4de). The first head passed the noise there too, and the device check on an M3 Ultra (comment of 2026-11-20) found sampled code 6.4% faster at two streams but 3.2% slower at four and 3.8% slower at eight. A shared round reads each node's chance as e^own from the tree's scores (landing.chanceFor), which then carry the noise term; a lone round reads its landing counts. Whether that is the cause is not shown.

The change, the measurements and this text were made by a coding agent (an LLM); none of it is written by hand.

Checks on this head

  • Head commit: 51ea8f737ee723b4f11f1beb40d11753f35a30ee
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head (51ea8f737): 189 and 189, 0 new. tools/pr_check.py --base origin/main --pr 3978 on this head: 0 errors, 0 warnings.
  • Tests run, with the command and pass, fail and skip counts: zig build test test-golden -Dcpu=apple_m1 --summary all: on 3441a9e96 904/904 steps, 15,268 of 15,382 tests passed, 114 skipped, 0 failed; again with 16c52c4de's changes over the same cache 904/904 steps, the rerun steps' 689 of 719 tests passed, 30 skipped, 0 failed. zig fmt --check build.zig zig and git diff --check: clean. 16c52c4de's test (qwen27 grants: a shared round's sampled proposals keep the drafter's scores free of the draw's noise, reached by zig build test-qwen27-grants-host) fails when followsDraw ignores lone. The new test (qwen27 window: a sampled proposal's selection ranks its roots with the draw's noise, reached by zig build test-qwen27) fails without the two pass-through lines in selection() (expected 0.5, found 1) and with a planted wrong expectation.
  • CI: not run before opening.
  • Not run, and why: any server run on 16c52c4de or later (for a lone stream it passes the same options as 3441a9e96; shared rounds get main's), more than one stream on my side, thinking on, vision, long histories, tools/bench_cache.py, any chip other than the M4 Max. The 8-bit checkpoint with a drafter does not start on main's defaults with 48 GB. No optimization-ledger row, as 94ce0d1c4 added none.

Receipt

  • Main against branch: cells and numbers, or why they can't be run: tools/bench_openai.py BASE local-model --tokens 256 --reps 3 --temperatures 0,1, a fresh server per run (--parallel 1 --context 65536 --drafter z-lab/Qwen3.8-27B-DFlash2 --prompt-cache-gib 0), order main, branch, branch, main, branch, main, main, branch, one start of each binary before the first run. Rounds and tok/s are from the server's done lines; bench_openai.py's decode_tps agrees within 0.1.

    Prompt Seed token_sha (all runs) Rounds, main Rounds, branch tok/s, main (4 runs) tok/s, branch (4 runs)
    fibonacci-raw greedy 2b28aa2108de 53 53 83.8, 83.8, 83.7, 84.1 83.7, 84.1, 83.9, 83.6
    gpu-chat-no-think greedy a06fab348fbe 75 75 55.5, 56.5, 56.8, 56.4 56.7, 56.5, 56.3, 56.3
    fibonacci-raw 1234 94624c419588 55 49 to 50 69.2, 75.1, 76.1, 70.2 82.8, 78.3, 78.1, 78.5
    fibonacci-raw 1235 5382fb88a1ad 46 to 47 43 to 44 82.5, 89.0, 88.5, 82.7 95.1, 89.0, 88.7, 89.3
    fibonacci-raw 1236 ed99f8b35926 43 to 44 44 87.4, 93.9, 95.5, 86.7 95.2, 87.5, 87.5, 88.2
    gpu-chat-no-think 1234 5f06a0a9e145 79 73 49.5, 53.2, 52.6, 49.0 55.9, 53.1, 53.1, 53.1
    gpu-chat-no-think 1235 cf662c261c86 88 82 44.7, 46.8, 46.9, 43.9 50.9, 47.5, 47.6, 47.5
    gpu-chat-no-think 1236 90c51adfddcc 83 78 47.5, 49.5, 47.7, 47.1 53.0, 50.1, 50.2, 50.2

    Over the six sampled cells: 394 to 396 rounds on main, 369 to 371 on the branch; 41.0 to 41.2% of the offered rows accepted on main, 45.0 to 45.1% on the branch. Decode time of the six cells: main 25.9, 24.5, 24.6, 26.1 s; branch 22.8, 24.3, 24.3, 24.2 s.

  • How to read the times: the runs fall into two round speeds that follow the machine, not the binary. Five runs stayed at thermal state nominal (main 1 and 4, branch 2, 3 and 4 in the table) at 65.7 to 66.2 ms a round; three reported fair at their start or end (main 2 and 3, branch 1) at 61.4 to 62.0 ms. Like against like the branch's sampled decode time is 6.6% lower (nominal) and 7.1% lower (fair). One cell gains nothing: fibonacci-raw with seed 1236 takes 44 rounds on the branch against 43 to 44.

  • One branch run is left out and was repeated: its greedy cells ran at 50.4 and 40.0 tok/s against 83.6 to 84.1 and 55.5 to 56.8 in the other eight runs, so the machine was disturbed. Its token hashes equal the others too.

  • Boxes it reaches: every Mac serving a qwen27 Metal checkpoint with a DFlash drafter, sampled requests only, one stream (proposeOptions). Two to eight streams (proposeBatch) get no noise since 16c52c4de. Ran: M4 Max, one stream, the 27B 4-bit with DFlash2, on 3441a9e96.

  • New switch? Default, accepted values, profile row: none.

  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: 3441a9e96 against 517a44563; Zig 0.17.0, zig build native -Dcpu=apple_m1; Apple metal version 32023.922; Apple M4 Max, 48 GB, macOS 27.2.1 (26B131); TensorFold/Qwen3.8-27B-MLX-4bit@22d8d538154e0e5b6f8dcb1fcc74a60a0798104c with z-lab/Qwen3.8-27B-DFlash2@50307d4c4cde6860d4eee73e2547cd786fe8e8a4.

  • Paths and platforms the change reaches, which I ran and which I could not: the Metal lane backend's draft proposals for a sampled stream drafting alone. Ran: M4 Max (no tensor units). Could not: M1 to M3, M5. Not run by me: two or more streams, thinking, vision, the 9B and MoE checkpoints.

  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: on the branch, --tokens 256 --reps 1 --temperatures 0,1 --levels 1 --alone --serial: four cells, each alone 1 equal, 0 unequal and serial 1 equal, 0 unequal. Main and branch give the same token_sha in all eight cells of every run (table).

  • 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.

  • Decode speed before and after, from tools/bench_openai.py: the table above.

  • Prompt speed before and after: n/a, the change is in the draft proposal after a round and cannot reach prompt processing.

  • Licence of any new weights or drafter, or "n/a": n/a.

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.

  • 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.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted against "draft": false at one stream: yes, greedy and sampled, on 3441a9e96. A resumed prompt and concurrent streams: not run by me; your M3 Ultra check on 7fd027ed1 reports no token differences. Nothing run on 51ea8f737.)

  • No precision traded for speed. If the bits change, the description says which sums change and why.

  • 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. (One stream with the drafter, greedy and sampled: yes, table, on 3441a9e96. Two to eight streams take main's proposal path since 16c52c4de; not measured on this head. Without the drafter: not run.)

hobbesd added a commit to hobbesd/TensorFold that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @hobbesd. Reviewed as a first review: the two pass-through lines wire the selector noise the way the CUDA path does, greedy keeps main's path, and your receipt shows main and the branch agree on every token hash in all eight cells, so the replies stand unchanged while acceptance rises.

What is still open before this lands:

  • the multi-stream path: proposeBatch also reads selection(), and the two-stream and up cells, a resumed prompt against a fresh one, and the widest admitted width are unrun (your checklist names them).
  • we have not seen CI on the head.

We will run the device check on our side: an M3 Ultra serving the 27B with the DFlash2 drafter, sampled, at 2, 4 and 8 streams plus a resumed turn. We were unable to run any Mac cell here.

  • Synthena

@hobbesd

hobbesd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Agreed on both open points: nothing beyond one stream has been run on my side, so proposeBatch, a resumed prompt against a fresh one and the widest admitted width are unmeasured, and the head has no CI run yet.

Your M3 Ultra check at 2, 4 and 8 streams plus a resumed turn covers what the checklist leaves open.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @hobbesd for the reply and for agreeing on the two open points.

Neither point is settled at this head yet. Your new test pins the noise pass-through in selection(), and your table shows main and the branch agreeing on every token hash in all eight cells at one stream. But proposeBatch also reads selection(), and nothing beyond one stream has been measured: two, four and eight streams, a resumed turn against a fresh one, and the widest admitted width.

We will run that check on our side: an M3 Ultra serving the 27B 4-bit checkpoint with DFlash2, sampled, at two, four and eight streams plus a resumed turn. GitHub's runners are backed up tonight, so no checks have reported on this head yet; we will read them when they do.

  • Synthena

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @hobbesd. We ran the device check we promised on an M3 Ultra: Qwen3.8-27B 4-bit with DFlash2, main against this head, two runs each in the order base, new, new, base, at two, four and eight streams, greedy and sampled, plus resumed against fresh chats.

  • Exactness: no token differences, and resumed and fresh chats qualify with thinking on and off.
  • Sampled code (temperature 1.0): two streams gain 6.4% (111.5 to 118.6 tok/s), but four streams lose 3.2% (125.5 to 121.5) and eight streams lose 3.8% (143.2 to 137.8). Both runs of each arm agree within 0.2 tok/s, so these are real.
  • Chat at temperature 0 and 1, and greedy code, stay within the noise band at every width.

So the losses sit exactly where our earlier ask pointed: proposeBatch also reads selection(), and at four and eight streams the sampled draft tree now costs more than it saves. We cannot land a slowdown at those widths. Could you look at what the batched proposal does with the noise pass-through when several streams share a round, and either keep the gain at two streams without the loss at four and eight, or limit the change to the widths where it wins? We will rerun the same cells on the next head.

  • Synthena

@hobbesd

hobbesd commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for running the cells. I have measured nothing past one stream, so what follows is from reading the code, not from a run.

The tree is ranked the same way in both cases: proposeBatch calls selector.propose with selection(en) for each entry, as the lone path does. What differs is what happens to the scores afterwards. probabilitiesFn gives each held node's chance as landing.chanceFor(shared, keyed, own): a lone round reads its landing counts, a shared round takes e^own as it is (qwen27_landing.zig, since cfcff4cbd). own is the selector's score difference, and with the pass-through that score carries the noise term (noise_weight times the keyed Gumbel value) and the division by the temperature. So in a shared round the chances that windows.allocate reads through nodeChances are no longer the drafter's likelihood alone, and nothing corrects them; in a lone round the counts do. That is the one place I can find where the pass-through reaches a shared round beyond the ranking. I can't show from here that it causes the loss at four and eight streams, nor why two streams still gain.

Proposal for the next head: pass the noise only for a lone stream (lone in draftFn, one condition). Every proposeBatch entry then has noise == null, so a shared round builds the same selector options as main at every width. That gives up the 6.4% at two streams. I would rather not tie the change to a stream count taken from one machine's cells; if you prefer the limit at two streams, say so and I will make it that.

Keeping the gain in shared rounds would mean giving a shared round's chance a score without the noise, or counts of its own. That goes against what cfcff4cbd set up and needs multi-stream cells, so I would leave it for a separate change if you want it at all.

hobbesd added a commit to hobbesd/TensorFold that referenced this pull request Nov 20, 2026
@hobbesd hobbesd changed the title qwen27 metal: a sampled stream's draft tree ranks its candidates with the target draw's keyed noise qwen27 metal: a lone sampled stream's draft tree ranks its candidates with the target draw's keyed noise Nov 20, 2026
@AIFlowML

Copy link
Copy Markdown
Contributor

I ran the current 51ea8f737 head on M5 Max against its merge base, 517a44563, in base/head/head/base order. All 60 paired full token-ID hashes matched with zero failed or unmeasured requests. That covers code and chat at 1, 2, 4 and 8 simultaneous streams. I used Zig 0.17.0 and the same pinned 27B 4-bit (22d8d538) and DFlash2 (50307d4c) revisions as the PR, serving with --parallel 8 --context 65536 --prompt-cache-gib 0. The workload was:

python3 tools/bench_concurrent.py http://127.0.0.1:PORT local-model \
  --levels 1,2,4,8 --tokens 160 --reps 1 --temperatures 1 --seed 1234

For timing, the two- and four-stream cells were slower on the head in both pairs. Sampled code at four streams was 214.0/190.3 tok/s on base versus 194.2/184.1 on head. At eight streams the base varied from 166.7 to 224.0 while the head gave 231.0/222.4. I would keep the original M3 Ultra paired run as the performance gate, especially at two and four streams. This check used fresh requests only.

zig build test-qwen27 test-qwen27-grants-host -Dcpu=apple_m1 -j6 --summary all passed 215 tests with three skips. CI for this exact head now reports success, and the head trial-merges cleanly into 124052c97.

Igor Lessio - AIFLOW LABS

@hobbesd

hobbesd commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for running this on an M5 Max, and for the exactness cells at all four widths.

On the timing, from reading the code, not from a run (I have still measured nothing past one stream): on this head draftFn passes the noise only while a single slot drafts (followsDraw(lone, stream), lone being live(b) == 1). While two or more streams draft, every proposal has noise == null and the selector gets the options it gets on main. The exception is a round in which one stream of the cell drafts alone, for instance after the others have finished; it then takes the one-stream path. So I have no mechanism in the diff for a loss at two and four streams. With one repetition per cell, your base runs at four streams are 214.0 and 190.3 tok/s, further apart than base and head are in either pair, and at eight streams the base spans 166.7 to 224.0. I can't tell a difference between the binaries from these cells.

Agreed that the M3 Ultra paired run should be the gate.

@ashhart
ashhart force-pushed the metal-draft-follows-draw branch from 51ea8f7 to 87e5c1f Compare November 21, 2026 12:17
@ashhart
ashhart merged commit 4d8f680 into ashhart:main Nov 21, 2026
3 of 12 checks passed
ashhart pushed a commit that referenced this pull request Nov 21, 2026
ashhart pushed a commit that referenced this pull request Nov 21, 2026
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

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

3 participants