Skip to content

glm(metal): fuse DFlash2 Q4 decode kernels and pack batch heads - #4258

Merged
ashhart merged 2 commits into
ashhart:mainfrom
gilby:glm-metal-dflash2-w3-opt
Nov 25, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
gilby:glm-metal-dflash2-w3-opt

Conversation

@gilby

@gilby gilby commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Stacks on #4257 (after #3920 merged) to fuse the hot GLM-5.3-Flash DFlash2 Q4 decode path on Metal (glm_dflash_kv_append, glm_dflash_qkv_prep, and glm_dflash_conv_norm with stacked KV/QKV/gate+up lane adapters in metal_dflash_opt.zig), pack active batch mask rows before final RMSNorm and head projection (metal_dflash_same.zig), prefer target.w.draft_head when present (metal_dflash_backend.zig), and ignore prefill-only rounds (decode_n == 0) in Shared.step decode timing (metal_dflash_source.zig).

Checks on this head

  • Head commit: 002e8a353644a11450d2f055777af3676c1e684d (rebased cleanly with range-diff = from f29859f39ebc081e84056a7ed70b7cd1ba5d1d35)
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 168 on glm(metal): prune inactive DFlash2 rows, gate tap capture, and cut sampled transition cost #4257 (1d57c823ff) and origin/main (d7dc085bfc), 168 on head (002e8a3536), 0 new findings (python3 tools/pr_check.py --base 1d57c823ff and python3 tools/pr_check.py --base origin/main both exit 0; metal_main.zig 597 lines).
  • Pre-fix check on glm(metal): prune inactive DFlash2 rows, gate tap capture, and cut sampled transition cost #4257: glm_dflash_opt.metal, metal_dflash_opt.zig, Copies.opt, packed multi-stream mask-row projection in metal_dflash_same.zig, and draft_head orelse head in metal_dflash_backend.zig are absent on glm(metal): prune inactive DFlash2 rows, gate tap capture, and cut sampled transition cost #4257, while Shared.step sets s.last = t when decode_n == 0 (prefill-only rounds in Shared do not pollute the next decode round's timing fails on glm(metal): prune inactive DFlash2 rows, gate tap capture, and cut sampled transition cost #4257 and passes on head).
  • Tests run on rebased head 002e8a3536, with the command and pass, fail and skip counts:
    • zig fmt --check build.zig zig — passed (0 exit)
    • git diff --check 1d57c823ff..HEAD — passed (0 exit)
    • zig build test-glm-metal-dflash-host test-glm-metal-dflash-synthetic test-glm-scheduling-host test-glm-prefill-widths-host check-glm-restore-host test-kernel-contract tf-kernel-contract --summary all — 95/95 steps succeeded; 340/340 tests passed (test-glm-metal-dflash-host 15/15, test-glm-scheduling-host / test-glm-prefill-widths-host 63/63, test-glm-metal-dflash-synthetic glm dflash2 follow: chains agree with today's pass on 2688 of 2688 drafts, test-kernel-contract 192/192 + sub-suites)
    • ./zig-out/bin/tf-kernel-contract --only "glm dflash2 opt" on Apple Metal (applegpu_g17, tensor units true) — exited 0: SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 112 ms, limits 26 ms
  • Additional checks on receipted commit f29859f39e (git range-diff = to 002e8a3536):
    • zig build test-golden — 322/335 & 69/69, 0 unexpected differences
    • ./zig-out/bin/tf-kernel-contract --no-gates --only "glm dflash2 opt" --offline <dir> — exited 0 (PASS limits: 3 selected registered Metal launches against M1-M5, 0 problems; glm_dflash_kv_append: 32 threads; M1 256, M2 256; glm_dflash_qkv_prep: 32 threads; M1 256, M2 256; glm_dflash_conv_norm: 1024 threads; M1 1024, M2 1024; both offline controls RED)
    • ./zig-out/bin/tf-kernel-contract --only "glm dflash2 opt" on Apple M5 Ultra (applegpu_g17, therm=0) — exited 0 (SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 129 ms, limits 4 ms)
  • CI: Rerunning on 002e8a3536 (was 8/9 green prior to rebase, with the 1 failure being the pre-existing hosted-Windows timing flake in test_a_healthy_server_proves_both).
  • Not run, and why: live M1/M2/M3/M4 silicon runs (M1/M2 compiled and verified via --offline limits); CUDA/ROCm paths (Metal-only DFlash2 change).

Receipt

Full scrubbed receipts (taken at f29859f39e, git range-diff = to 002e8a3536; contract log, offline M1–M5 limits log, bench_concurrent.py, bench_openai.py on MLX-4bit-MTP + --drafter --drafter-bits 4): https://gist.github.com/gilby/7da62c9634c7092c44e1ee36ea6d0e1e

Cell #3920 (b9615a115aa) #4257 (190e1fe04f) D2 (f29859f39e) D2 vs #4257 D2 vs #3920 #4257 steady D2 steady Steady vs #4257
code T=0.0 N=1 161.8 162.0 163.7 +1.05% +1.17% — — —
code T=0.0 N=3 183.8 181.1 183.3 +1.21% -0.27% 188.8 189.8 +0.53%
chat T=0.0 N=1 97.2 97.0 97.2 +0.21% +0.00% — — —
chat T=0.0 N=3 155.3 154.2 155.0 +0.52% -0.19% 163.4 163.9 +0.31%
code T=1.0 N=1 128.5 128.2 128.8 +0.47% +0.23% — — —
code T=1.0 N=3 133.6 133.4 132.3 -0.82% -0.97% 139.2 139.7 +0.36%
chat T=1.0 N=1 87.2 89.1 90.0 +1.01% +3.21% — — —
chat T=1.0 N=3 120.5 121.2 120.7 -0.41% +0.17% 126.9 126.0 -0.71%
  • Decode speed before and after, from tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0,1.0 (--prompt-cache-gib 0, median tok/s, 12/12 token_sha and 12/12 output_sha256 bit-identical to #4257 and #3920):
Prompt / Temp #3920 (b9615a115aa) #4257 (190e1fe04f) D2 (f29859f39e) D2 vs #4257 D2 vs #3920
fibonacci-raw T=0.0 161.19 161.73 163.24 +0.93% +1.27%
gpu-chat-no-think T=0.0 97.09 97.14 97.13 -0.02% +0.04%
fibonacci-raw T=1.0 121.08 121.47 123.04 +1.29% +1.61%
gpu-chat-no-think T=1.0 89.17 90.61 90.71 +0.11% +1.73%
  • Boxes it reaches: glm5_next on Metal with Q4 --drafter when device.tensorUnits() holds (tp == 1).
  • New switch? Default, accepted values, profile row: None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision:
    • TensorFold commit: 002e8a353644a11450d2f055777af3676c1e684d stacked on #4257 (1d57c823ffb7aa1ae54334d682dbe11abf9ce21e) and main (d7dc085bfc), range-diff = vs receipted f29859f39ebc081e84056a7ed70b7cd1ba5d1d35
    • Toolchain: Zig 0.17.0 (-Dcpu=apple_m1), macOS Metal
    • Machine / GPU: Apple M5 Ultra (applegpu_g17, 256 GB unified memory, tensor units true)
    • Checkpoint / drafter: TensorFold/GLM-5.3-Flash-MLX-4bit-MTP with DFlash2 drafter (--drafter-bits 4)
  • Paths and platforms the change reaches, which I ran and which I could not:
    • Ran: macOS Apple M5 Ultra (256 GB) DFlash2 Q4 decode/absorb, synthetic DFlash2 tests (2688/2688 drafts), Metal kernel contract (gates 1–4 + M1–M5 limits + M1/M2 offline limits), host/golden tests.
    • Could not run: live M1/M2/M3/M4 silicon, CUDA/ROCm (Metal-only change).
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false:
    • bench_concurrent.py --alone --serial: 0 unequal and 0 failed across every alone (concurrent == alone) and serial (drafted == "draft": false) comparison.
    • bench_openai.py: 12/12 token_sha and 12/12 output_sha256 bit-identical to #4257 and #3920.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): Yes — same Apple M5 Ultra (256 GB), paired receipts against parent glm(metal): prune inactive DFlash2 rows, gate tap capture, and cut sampled transition cost #4257 and glm metal: draft GLM-5.3-Flash with published DFlash2 behind --drafter #3920 in Gist above.
  • Decode speed before and after: see tables above (+0.93% greedy / +1.29% sampled on fibonacci-raw, +1.21% on code T=0.0 N=3, +1.01% on chat T=1.0 N=1 over #4257).
  • Prompt speed before and after: only DFlash2 decode/absorb kernels (glm_dflash_kv_append, glm_dflash_qkv_prep, glm_dflash_conv_norm, packed batch head projection) and Shared.step decode_n == 0 guard change; full long-prompt prefill benchmark not re-run.
  • Licence of any new weights or drafter, or "n/a": uses existing DFlash2 drafter from glm metal: draft GLM-5.3-Flash with published DFlash2 behind --drafter #3920.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces:
    • glm_dflash_kv_append — replaces per-layer draft_ops norm+rope + shared_attention.appendKv during DFlash2 ahead/catchup absorb.
    • glm_dflash_qkv_prep — replaces per-head draft_ops q/k_norm+rope + v copy inside DFlash2 attention layers.
    • glm_dflash_conv_norm — replaces draft_ops dynamic_conv2 + draft_rms for branch == 1.
    • Registered in zig/src/core/contract/glm_dflash_records.zig, zig/tests/contract/metal_glm_dflash_opt.zig, zig/tests/contract/metal_limits.zig, and zig/tests/contract/metal_main.zig.
  • A planted control for each new kernel, and each one fails as planted:
    • control: glm dflash2 opt kv_append writes into input (FAIL repeat)
    • control: glm dflash2 opt kv_append drops last RoPE pair (FAIL shapes)
    • control: glm dflash2 opt qkv_prep writes into input (FAIL repeat)
    • control: glm dflash2 opt qkv_prep drops last RoPE pair (FAIL shapes)
    • control: glm dflash2 opt conv_norm writes into input (FAIL repeat)
    • control: glm dflash2 opt conv_norm drops tail cols (FAIL shapes)
    • Limit controls: tf_row_projection_q4_f32 (2 limit problems), 36 KiB tf_ctl_big_tg (8 limit problems); 3 selected registered Metal launches against M1-M5, 0 problems (plus M1/M2 offline limits pass with 0 problems).
  • Each backend's SUMMARY line and exit status:
    • Apple M5 Ultra / M5 Max (applegpu_g17, tensor units true): SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 112 ms, limits 26 ms on 002e8a3536 (gates 129 ms, limits 4 ms on f29859f39e) (exit 0).
  • Chips I could not run: Apple M1/M2/M3/M4 silicon (M1/M2 verified offline via --offline; metal_limits.zig checks M1–M5 limits with 0 problems); NVIDIA/AMD untouched (Metal-only change).

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

@gilby
gilby force-pushed the glm-metal-dflash2-w3-opt branch from f29859f to 002e8a3 Compare November 21, 2026 06:24
@gilby
gilby marked this pull request as ready for review November 21, 2026 06:24
@ashhart
ashhart force-pushed the glm-metal-dflash2-w3-opt branch from 002e8a3 to 07695ce Compare November 21, 2026 23:08
@AIFlowML

Copy link
Copy Markdown
Contributor

I verified published head 07695ceae in a clean trial merge into main 2ce240cf0 on M5 Max (macOS 27.2, Zig 0.17.0). The landed #4257 parent is present in that main, and git diff --cached --check passed.

  • zig build test-glm-metal-dflash-host test-glm-metal-dflash-synthetic test-glm-scheduling-host test-glm-prefill-widths-host tf-kernel-contract -Dcpu=apple_m1 -j4 --summary all passed 55/55 steps and 79/79 tests. The synthetic follow test matched 2,688 of 2,688 drafts.
  • zig-out/bin/tf-kernel-contract --only 'glm dflash2 opt' exited 0. SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 115 ms, limits 6 ms

This checks the current head's synthetic path and the three Metal kernels. Full-checkpoint serving and performance were outside this run.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I traced the red pytest check on 07695ceae68de3d89582d34dd4f53b3494c78f1b to test collection. The job installs pytest and then cannot import yaml in tools/test_ci_workflow_conditions.py. I reproduced that failure on the published head:

uv run --no-project --with pytest -- pytest -q tools/test_ci_workflow_conditions.py

Adding --with PyYAML to the same command passes the test and all four subtests. Neither the workflow nor that test is changed by this PR. The branch trial-merges cleanly into 34af03a12, whose workflow already installs PyYAML through merged #4469. An updated run on that base should clear this specific collection blocker. I ran the focused collection check locally.

Failed GitHub Actions job

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. The fused kernels keep the existing rounding steps, and the packed batch rows, replacement tests and planted controls are useful. This head merges cleanly with current main.

Before landing, we need full-model checks on that combined tree: drafted versus plain and concurrent versus solo token equality, plus before/after timings and peak memory. Please include the exact target and drafter revisions and cover both tensor-unit Metal and the older Metal fallback, since the draft-head choice changes there too. The current-head synthetic receipt helps; the older full-model receipt does not yet cover this tree.

  • Synthena

@gilby

gilby commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Verified the combined origin/main (ef0ecb9a6d) + #4258 (07695ceae6) tree (local trial merge sources.zig keeping both glm_dflash_opt and inkling2_runtime) across local unit/contract checks and full-model A-B-B-A served runs on both tensor-unit Metal (Apple M5 Ultra) and older Metal fallback (Apple M3 Ultra, tensorUnits() == false -> .rows draft-head fallback).

Checkpoint & Serving Configuration

  • Target: GLM-5.3-Flash-MLX-4bit-MTP, revision d2b17f5253440224422b150705c1109a9a3a0368 (config.json sha256 f80682bcc8ba5fc6ecdc5ce553700b02befe999bc4a6ba6fd47f644df4864adf)
  • Drafter: GLM-5.3-Flash-DFlash2-6cc6c481, revision 6cc6c481eee930a5139619ed919f78726371adbc (config.json sha256 c4aeac0101196a6e26705b34c45230bcd0c7c68ee2d2d1efdb242087f3712573), --drafter-bits 4
  • Server / Client: tensorfold-native serve ... --drafter ... --drafter-bits 4 --parallel 3 --context 131072 --prompt-cache-gib 0 --profile stable --no-update-check; tools/bench_concurrent.py --alone --serial --tokens 256 --reps 3 --temperatures 0,1.0 --levels 1,3 --seed 1234

Local Unit & Kernel Contract Checks (Combined Tree, Apple M5 Max)

  • zig build tf-kernel-contract test-glm-metal-dflash-host test-glm-metal-dflash-synthetic test-kernel-contract --summary all: 94/94 steps succeeded; 328/328 tests passed.
  • ./zig-out/bin/tf-kernel-contract --only "glm dflash2 opt": SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 233 ms, limits 675 ms.

1. Apple M5 Ultra, 512 GiB (tensor_units = true) — Paired A-B-B-A (main_1, pr_1, pr_2, main_2)

  • Token equality: 0 failed, 0 unmeasured across all 4 passes × 8 cells; --alone (concurrent vs solo) 0 unequal/0 failed; --serial (drafted vs "draft": false) 0 unequal/0 failed (plain_drafted = 0); cross-binary main vs main + #4258: 48/48 exact token_sha256 match (0 diffs).
  • Peak memory (/usr/bin/time -l): main 188.18 GB max RSS / 189.09 GB peak footprint (188.17 GB / 189.09 GB run 2); main + #4258 188.55 GB max RSS / 189.46 GB peak footprint (188.55 GB / 189.46 GB run 2).
  • Thermals (pmset -g therm before/after every pass): no thermal or performance warnings recorded.
Cell (N, T) Main agg tok/s (main_1 / main_2) PR agg tok/s (pr_1 / pr_2) Agg Δ Main per-stream (mean) PR per-stream (mean) Per-stream Δ Paired makespan (main vs PR, s)
code N=1, T=0 152.80 (153.3 / 152.3) 152.15 (152.2 / 152.1) -0.43% 152.80 152.15 -0.43% 1.742 vs 1.750
code N=3, T=0 183.05 (183.7 / 182.4) 182.35 (182.6 / 182.1) -0.38% 62.15 61.90 -0.40% 4.253 vs 4.269
chat N=1, T=0 88.55 (88.9 / 88.2) 89.90 (89.9 / 89.9) +1.52% 88.55 89.90 +1.52% 3.013 vs 2.971
chat N=3, T=0 151.15 (151.4 / 150.9) 150.90 (150.9 / 150.9) -0.17% 51.75 51.70 -0.10% 5.196 vs 5.204
code N=1, T=1 117.95 (118.1 / 117.8) 118.10 (118.1 / 118.1) +0.13% 117.95 118.10 +0.13% 2.235 vs 2.233
code N=3, T=1 122.50 (123.0 / 122.0) 122.35 (122.5 / 122.2) -0.12% 47.95 49.75 +3.75% 6.319 vs 6.326
chat N=1, T=1 81.00 (81.1 / 80.9) 81.90 (81.9 / 81.9) +1.11% 81.00 81.90 +1.11% 3.281 vs 3.247
chat N=3, T=1 110.85 (111.0 / 110.7) 110.80 (110.5 / 111.1) -0.05% 38.95 39.65 +1.80% 7.034 vs 7.038

(Accepted drafts under --serial on M5 Ultra: chat T=0 rose from 119 on main to 139 on main + #4258, code T=1 from 471 to 493/492, code T=0 208/209 vs 208, chat T=1 391 vs 390.)

2. Apple M3 Ultra, 512 GiB (apple-m3, older Metal fallback, tensorUnits() == false) — Paired A-B-B-A (main_1, pr_1, pr_2, main_2)

  • Token equality: 0 failed, 0 unmeasured across all 4 passes × 8 cells; --alone 0 unequal/0 failed; --serial 0 unequal/0 failed (plain_drafted = 0); cross-binary main vs main + #4258: 48/48 exact token_sha256 match (0 diffs).
  • Peak memory (/usr/bin/time -l): main 188.17 GB max RSS / 189.18 GB peak footprint; main + #4258 188.17 GB max RSS / 189.18 GB peak footprint.
  • Thermals (pmset -g therm before/after every pass): no thermal or performance warnings recorded (sequential sustained load drifted downward across the 4 passes main_1 -> pr_1 -> pr_2 -> main_2, reflected in both arms of the A-B-B-A pair).
Cell (N, T) Main agg tok/s (main_1 / main_2) PR agg tok/s (pr_1 / pr_2) Agg Δ Main per-stream (mean) PR per-stream (mean) Per-stream Δ Paired makespan (main vs PR, s)
code N=1, T=0 69.50 (73.5 / 65.5) 70.90 (73.4 / 68.4) +2.01% 69.50 70.90 +2.01% 3.794 vs 3.711
code N=3, T=0 101.90 (107.7 / 96.1) 104.25 (107.8 / 100.7) +2.31% 34.30 35.10 +2.33% 7.645 vs 7.454
chat N=1, T=0 63.35 (65.2 / 61.5) 63.40 (65.1 / 61.7) +0.08% 63.35 63.40 +0.08% 4.373 vs 4.350
chat N=3, T=0 92.35 (96.9 / 87.8) 93.90 (96.8 / 91.0) +1.68% 32.05 32.60 +1.72% 8.631 vs 8.472
code N=1, T=1 74.75 (78.7 / 70.8) 74.55 (77.1 / 72.0) -0.27% 74.75 74.55 -0.27% 3.541 vs 3.541
code N=3, T=1 78.25 (82.2 / 74.3) 77.75 (80.2 / 75.3) -0.64% 30.35 30.55 +0.66% 9.911 vs 9.968
chat N=1, T=1 57.70 (60.6 / 54.8) 56.30 (58.0 / 54.6) -2.43% 57.70 56.30 -2.43% 4.768 vs 4.892
chat N=3, T=1 70.95 (74.3 / 67.6) 69.40 (70.9 / 67.9) -2.18% 26.60 25.35 -4.70% 11.161 vs 11.388

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The pinned M3 and M5 combined-tree runs answer the remaining model checks: drafted equals plain, concurrent equals solo, the cross-binary hashes match, and the paired timings and peak memory are reported. The changed runtime and shader files match the receipted integration.

One thing before it lands: on M3, chat at one stream reads 2.43% slower, and the report notes some downward drift under sustained load. Since a change can't land slower in any cell, could you re-run just that cell with the builds alternated (base, new, new, base, after one warm run) so we can tell drift from a real cost? If it holds, we'd look for where the time goes before landing.

The remaining merge work (the source registry and keeping the contract runner within its line cap) is ours.

  • Synthena

@gilby

gilby commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Re-ran the isolated chat N=1 cell on Apple M3 Ultra, 512 GiB (-Dcpu=apple_m1, tensorUnits() == false -> .rows fallback) with builds alternated (warm discarded, then base, new, new, base) to separate sustained-load drift from any per-binary cost:

Setup

  • Base (base): origin/main (0652b7907b)
  • Candidate (new): origin/main (0652b7907b) + #4258 (07695ceae6), resolving zig/kernels/metal/sources.zig to keep both glm_dflash_opt and inkling2_runtime (zig fmt --check build.zig zig and git diff --check pass; ./zig-out/bin/tf-kernel-contract --only "glm dflash2 opt" on Apple M5 Max passed 3/3 kernels gates 1–4, 6/6 planted controls red, 0 limit problems)
  • Models & serving flags: GLM-5.3-Flash-MLX-4bit-MTP (config.json sha256 f80682bcc8ba5fc6ecdc5ce553700b02befe999bc4a6ba6fd47f644df4864adf) with GLM-5.3-Flash-DFlash2-6cc6c481 (config.json sha256 c4aeac0101196a6e26705b34c45230bcd0c7c68ee2d2d1efdb242087f3712573), --drafter-bits 4 --parallel 3 --context 131072 --prompt-cache-gib 0 --profile stable --no-update-check
  • Client: tools/bench_concurrent.py --prompts <single chat item> --alone --serial --tokens 256 --reps 3 --levels 1 --seed 1234 (identical request payload and bench_thinking handling to the default chat cell)

1. chat N=1, T=1.0 (the cell that read -2.43% in the 8-cell run)

  • Order: warm (base, discarded) -> base_1 -> new_1 -> new_2 -> base_2
  • Results:
    • warm (base): median 60.655 tok/s (reps 60.725 / 60.655 / 60.648), agg 60.7, makespan 4.506 s
    • base_1: median 60.506 tok/s (reps 60.595 / 60.506 / 60.501), agg 60.5, makespan 4.517 s
    • new_1: median 60.479 tok/s (reps 60.517 / 60.454 / 60.479), agg 60.5, makespan 4.519 s
    • new_2: median 60.441 tok/s (reps 60.523 / 60.441 / 60.370), agg 60.4, makespan 4.522 s
    • base_2: median 60.330 tok/s (reps 60.373 / 60.330 / 60.321), agg 60.3, makespan 4.529 s
  • Paired comparison (base vs new): 60.418 vs 60.460 tok/s (+0.07%; agg 60.40 vs 60.45), tracking the smooth monotonic per-pass drift (60.655 -> 60.506 -> 60.479 -> 60.441 -> 60.330).
  • Exactness: 0 failed/unmeasured; 3/3 --alone equal and 1/1 --serial equal (accepted: 138, plain_drafted: 0) on every pass; all 5 runs × 3 reps + --alone + --serial produced identical token_sha256 d771c6f27670d0afdb4e72a3563bbbbf41a1d506788b75bbf6e91d552f4a019f.

2. chat N=1, T=0.0 (confirmation)

  • Order: warm (base, discarded) -> base_1 -> new_1 -> new_2 -> base_2
  • Results:
    • warm (base): median 65.130 tok/s (reps 65.054 / 65.130 / 65.226), agg 65.1, makespan 4.217 s
    • base_1: median 65.073 tok/s (reps 65.175 / 65.073 / 65.063), agg 65.1, makespan 4.221 s
    • new_1: median 65.144 tok/s (reps 65.145 / 65.144 / 65.122), agg 65.1, makespan 4.216 s
    • new_2: median 65.302 tok/s (reps 65.317 / 65.255 / 65.302), agg 65.3, makespan 4.207 s
    • base_2: median 65.137 tok/s (reps 65.191 / 65.137 / 65.122), agg 65.1, makespan 4.217 s
  • Paired comparison (base vs new): 65.105 vs 65.223 tok/s (+0.18%; agg 65.10 vs 65.20).
  • Exactness: 0 failed/unmeasured; 3/3 --alone equal and 1/1 --serial equal (accepted: 128, plain_drafted: 0) on every pass; all 5 runs × 3 reps + --alone + --serial produced identical token_sha256 76725be128c427c546d822ed5bef40b0c4c1e92f95f6e0a2a14925b432c35fcc.

Memory, Thermals & Code-Path Note

  • Peak memory (/usr/bin/time -l): 188.17 GB (175.25 GiB) max RSS / 189.14 GB (176.15 GiB) peak memory footprint on both base and new across all 10 runs (0 delta).
  • Thermals (pmset -g therm): no thermal or performance warnings recorded before or after any pass.
  • Why the prior 8-cell pass read -2.43%: in Opt.init, !device.tensorUnits() returns null, and GLM-5.3-Flash-MLX-4bit-MTP has no draft_head tensor, so single-stream decode on M3 runs the same kernel path as main; the -2.43% in the prior full-suite run came from non-linear sustained-load drift (60.6 -> 58.0 -> 54.6 -> 54.8) when chat N=1, T=1.0 ran late inside each multi-cell pass. Under isolated warm + base, new, new, base, there is no slowdown (+0.07% at T=1.0, +0.18% at T=0.0).

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The isolated alternating M3 runs answer the remaining chat-cell request: the paired results are +0.07% and +0.18%, with matching token hashes and memory in those runs. The changed runtime and shader files also match that receipted integration.

This is ready to land through the normal final-tree checks. The one remaining merge conflict, in the kernel source list, is ours to resolve; the contract runner is now within its line cap. No additional device rerun is needed for this unchanged head.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I tested the exact #5013 train tip 613ce5ca23 on M5 Max. Outside the changelog it matches merging this head (17b7fa3955) and #4809 (7ad3b9626b) into 4beda42498 in that order. Both source merges were clean in that trial, including the Metal source list.

zig build test-glm-metal-dflash-host test-glm-metal-dflash-synthetic test-glm-keep-seqs-host test-glm-dflash-host tf-kernel-contract -Dfixed-cpu -j2 --summary all
./zig-out/bin/tf-kernel-contract --only 'glm dflash2 opt'

All 58 build steps and 35 tests passed, and the synthetic Metal drafter executable succeeded. The device filter passed all three optimized kernels, caught all six planted controls and found zero launch-limit problems. This adds an independent check of the final train source. The earlier model-backed and timing receipts remain separate.

Igor Lessio - AIFLOW LABS

gilby and others added 2 commits November 25, 2026 09:21
Add fused DFlash2 Q4 Metal decode kernels (glm_dflash_kv_append,
glm_dflash_qkv_prep, and glm_dflash_conv_norm) with stacked KV/QKV/
gate+up projections in metal_dflash_opt.zig, pack active batch mask rows
before final norm and head projection in metal_dflash_same.zig, route
draft_head ahead of target head in metal_dflash_backend.zig, and exclude
prefill-only rounds from Shared.step decode timing in metal_dflash_source.zig.

Refs ashhart#3152
@ashhart
ashhart force-pushed the glm-metal-dflash2-w3-opt branch from 17b7fa3 to fe2a37e Compare November 25, 2026 09:21
@ashhart
ashhart merged commit b9dbd37 into ashhart:main Nov 25, 2026
1 check failed
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

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

ashhart added a commit to BadAd84/TensorFold that referenced this pull request Nov 25, 2026
ashhart added a commit that referenced this pull request Nov 25, 2026
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