Repository navigation
glm metal: draft GLM-5.3-Flash with published DFlash2 behind --drafter - #3920
Conversation
d72554f to
157075f
Compare
|
Thanks @gilby for the GLM DFlash2 implementation and the detailed Metal performance and exactness evidence. The supplied diff applies cleanly to current main. Three items remain on the reviewed head:
The earlier head's zero-unequal results and M5/M3 controls are useful evidence, but they do not directly certify the diff under review. I found no application conflict or additional default-path token change.
|
|
I trial-merged zig build test-glm-metal-dflash-host test-glm-metal-dflash-synthetic tf-kernel-contract \
-Dcpu=apple_m1 -j6 --summary all
for scope in 'block attention' 'top-k' 'accept' 'follow'; do
./zig-out/bin/tf-kernel-contract --only "glm dflash2 $scope"
doneThe build passed 51/51 steps and 11/11 host tests. The synthetic follow fixture agreed on all 2,688 drafts. Across the four focused Metal contract runs, all eight entries passed gates 1–4, all seven functional controls went red at their intended gates and no limit problems were reported. I stopped the broader filter while it was still in the head-projection cases. This receipt covers the four scopes above, with the M3 and served I also reproduced the tap-stage accounting gap with the generated 64×512 BF16 buffer. A synthetic drafter with 1,024 bytes of model storage reported 1,024 bytes instead of 66,560. The fixture passed after I added The latest M5 Max check with Zig 0.17.0, In scratch, giving the tap-capture fixture a stable state and registering it with I resolved the remaining overflow in the scratch #4285 trial against The fixture also needs three setup corrections: register the tap-capture stream, give the no-drafter test an initialized model, and use separate initialized input buffers for both ring-absorb checks. With those changes and the depth comparison, Post-merge verification at Igor Lessio - AIFLOW LABS |
157075f to
b9615a1
Compare
|
Thanks for the review @ashhart and @AIFlowML — pushed updated head
|
A new Qwen3.5-2B Metal prompt is filled a chunk at a time between other streams' decode rounds, at the whole pass's cuts, so replies are unchanged. Note it under Unreleased (ashhart#3090, part of ashhart#3021). # Conflicts: # CHANGELOG.md
Add opt-in Metal DFlash2 drafting for GLM-5.3-Flash behind --drafter with --drafter-bits 4 (quantized at load) or 0 (bf16). Captures the target's five tapped layers into per-stream ring buffers, runs same-buffer GPU accept/follow and shared multi-stream draft passes in the target residency set, falls back to the target's MTP head past the context cap or when MTP outperforms DFlash2, and refuses --drafter beside --speed-up or unsupported --drafter-bits. Register the five new DFlash2 GPU kernels and controls in the Metal kernel contract, document TF_GLM_DRAFT_CONFIDENCE's 0.5 Metal default, and update the optimization ledger. Refs ashhart#3152
…and b4d4795 Main's cc17776 left zig/src/families/glm/forward.zig at 600 lines and b4d4795 (ashhart#2761) left zig/src/native/metal.zig at 597, so this PR's DFlash2 taps and drafter wiring took them to 603 and 602. Three blank lines after one-line declarations in forward.zig and two in metal.zig go; nothing else changes.
…t, trim comments Count the tap-stage buffer beside drafter model bytes in heldBytes and load accounting, wire the self-referential core module into the GLM scheduling and restore host build steps so macOS/Linux host compile checks succeed, add heldBytes coverage to the DFlash2 host suite, and wrap comments to 120 columns. Refs ashhart#3152
b9615a1 to
ed7192c
Compare
|
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. |
…fter main's ashhart#3920 Format only: the unabsorb strides go back inline and the limits gate is one line. Nothing else changes.
…mpled transition cost Prune inactive DFlash2 sequence rows, skip tap writes when no stream draws a DFlash2 chain (scattering stream means directly via glm_tap_mean_ring without the extra staging copy), and flatten sampled chains across active prefixes on top of PR ashhart#3920. Stacked on ashhart#3920. Refs ashhart#3152
…fter main's ashhart#3920 Format only: the unabsorb strides go back inline and the limits gate is one line. Nothing else changes.
…fter main's ashhart#3920 Format only: the unabsorb strides go back inline and the limits gate is one line. Nothing else changes.
#3920 added Engine.dflash (default null). The residency-owner and draft-source fixtures build the engine as undefined and set fields one by one, so dflash held the undefined pattern: Backend.facts() and Engine.ctx() read it as a drafter and crashed (the macOS nightly's native and deferred host checks on main). Set it to null in all three fixtures.
#3920 added Engine.dflash (default null). The residency-owner and draft-source fixtures build the engine as undefined and set fields one by one, so dflash held the undefined pattern: Backend.facts() and Engine.ctx() read it as a drafter and crashed (the macOS nightly's native and deferred host checks on main). Set it to null in all three fixtures.
…fter main's ashhart#3920 Format only: the unabsorb strides go back inline and the limits gate is one line. Nothing else changes.
…fter main's #3920 Format only: the unabsorb strides go back inline and the limits gate is one line. Nothing else changes.
…mpled transition cost Prune inactive DFlash2 sequence rows, skip tap writes when no stream draws a DFlash2 chain (scattering stream means directly via glm_tap_mean_ring without the extra staging copy), and flatten sampled chains across active prefixes on top of PR ashhart#3920. Stacked on ashhart#3920. Refs ashhart#3152
…mpled transition cost Prune inactive DFlash2 sequence rows, skip tap writes when no stream draws a DFlash2 chain (scattering stream means directly via glm_tap_mean_ring without the extra staging copy), and flatten sampled chains across active prefixes on top of PR #3920. Stacked on #3920. Refs #3152
Main's cf37b2a (glm metal: prompt.zig and the Metal contract main back to 600 lines after main's #3920) already has the supplied one-line limits gate. Keep that gate, put the three H3 suites and their defers on one source line, and join the limits accumulator to the gate so the suite registrations preserve main's 600-line ceiling.
Main's cf37b2a (glm metal: prompt.zig and the Metal contract main back to 600 lines after main's #3920) already has the supplied one-line limits gate. Keep that gate, put the three H3 suites and their defers on one source line, and join the limits accumulator to the gate so the suite registrations preserve main's 600-line ceiling.
What this changes
Adds opt-in Metal speculative decoding for GLM-5.3-Flash using published DFlash2 drafter checkpoints behind
--drafter DIRand--drafter-bits {0,4}(defaulting to MTP when--drafteris omitted, and refusing--drafteralongside--speed-up). Implements dedicated Metal DFlash2 kernels (glm_draft_attend,glm_draft_attend_merge,glm_draft_topk,glm_draft_accept,glm_draft_follow), same-buffer inline draft rounds with target-joined residency (includingtaps.stage.length()in initial load andheldBytesaccounting), an adaptive per-stream yield chooser (keeping sampled multi-stream shared rounds on MTP), and registersTF_GLM_DRAFT_CONFIDENCE(0.7CUDA,0.5Metal).main(4c616e63d57204cd8395dc3af9b572d9ec49626b)atc overlap --base origin/main --json:64changed files;6clean overlaps against open PRs,4older conflicting PRs (#1835,#2273,#2464,#2634),14unknown.Checks on this head
b9615a115aa2e50f6d096416da5f7c04c76ef17cpython3 tools/zig/lean_check.py, on the base and on this head:168on base (4c616e63d),168on head (b9615a115aa),0new findings (python3 tools/pr_check.py --base origin/main --pr 3920exits0).b9615a115aa, with the command and pass, fail and skip counts:zig fmt --check build.zig zig— passed (0exit)git diff --check— passed (0exit)zig build test-glm-scheduling-host test-glm-prefill-widths-host— passed (63/63)zig build check-glm-restore-host— passed (0exit)zig build test-glm-metal-dflash-host— passed (12/12, including directheldBytestap-stage accounting test)zig build test-glm-metal-dflash-synthetic— passed (2688/2688drafts match)zig build test-kernel-contract test-golden— passed (test-golden322/335&69/69,0unexpected differences)python3 -m unittest test/host_tests_test.py(13 skipped) andpython3 -m unittest tools/build_options_test.py(5/5passed)./zig-out/bin/tf-kernel-contract --no-gates --only "glm dflash2" --offline ...— passed (5selected registered Metal launches against M1–M2 limits,0problems; controls red)./zig-out/bin/tf-glm-dflash-speed --overlap --resident-gib 2 --resident-buffers 4 --window-mb 128on Apple M5 Ultra (therm=0) — passed (3.634 mshost-between ->3.390 mscommitted-behind,-0.244 ms/round; same-buffer3.477 ms,-0.158 ms/round)./zig-out/bin/tf-kernel-contract --only "glm dflash2"on Apple M5 Ultra (applegpu_g17,therm=0) — exited0(details below)b9615a115aa:fmt,release-paths (ubuntu-24.04),pytest,benchmark-clients (ubuntu-latest),benchmark-clients (windows-latest),zig-macos-dev-toolspassed;zig,zig-b,zig-windowscurrently running.b9615a115aa, and why: live Apple M3 Ultra, M1, M2, M4 runs (M1/M2 checked offline via--offline+metal_limits.zigM1–M5 limits); CUDA/ROCm paths (macOS build hosts, Metal-only change); full unfiltered Metal contract.Receipt
Full scrubbed receipts (contract/speed log,
bench_concurrent.py,bench_openai.pywith and without--drafter): https://gist.github.com/gilby/af9959cf5d8fa4acd79dce36c6d43b5b4c616e63d) against branch (b9615a115aa,--drafter GLM-5.3-Flash-DFlash2-6cc6c481 --drafter-bits 4), same Apple M5 Ultra (256 GB) andTensorFold/GLM-5.3-Flash-MLX-4bit-MTPcheckpoint,--prompt-cache-gib 0 --profile stable,therm=0,tools/bench_concurrent.py --alone --serial --tokens 256 --reps 3 --temperatures 0,1.0 --levels 1,3(0unequal /0failed across every cell):main(MTP)#3920(DFlash2)mainsteady#3920steadymaintpc#3920tpccode T=0.0 N=1code T=0.0 N=3chat T=0.0 N=1chat T=0.0 N=3code T=1.0 N=1code T=1.0 N=3chat T=1.0 N=1chat T=1.0 N=3tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0,1.0(--prompt-cache-gib 0, median tok/s;12/12replytoken_sha256s bit-identical acrossmain,#3920MTP without--drafter, and#3920 --drafter):--no-drafts(main)main(MTP)#3920(MTP, no--drafter)#3920(--drafter)mainfibonacci-raw T=0.0gpu-chat-no-think T=0.0fibonacci-raw T=1.0gpu-chat-no-think T=1.0glm5_nexton Metal (--drafter,--drafter-bits {0,4});--no-drafts, default MTP (without--drafter), and--speed-uppaths unchanged (CLI refuses--speed-up ... --drafterand--drafter-bits 8).--drafter PATHand--drafter-bits {0,4}wired into GLM Metal host (opt-in; off by default;--profile stable).TF_GLM_DRAFT_CONFIDENCE: float confidence gate (0.7default on CUDA,0.5default on Metal), registered inzig/src/platform/environment.zigand documented indocs/environment.md.b9615a115aa2e50f6d096416da5f7c04c76ef17catopmain4c616e63d57204cd8395dc3af9b572d9ec49626b0.17.0(-Dcpu=apple_m1), macOS Metalapplegpu_g17, 256 GB unified memory, tensor units true)TensorFold/GLM-5.3-Flash-MLX-4bit-MTP+incoai/GLM-5.3-Flash-DFlash2(rev 6cc6c481)--drafter --drafter-bits 4, default MTP, host/synthetic suite, and Metal kernel contract + M1/M2 offline limit check.b9615a115aa: live M3/M1/M2/M4 silicon, Linux/CUDA/ROCm.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:tools/bench_concurrent.py --alone --serial:0unequal and0failed across allalone(concurrent == alone) andserial(drafted == "draft": false) comparisons.tools/bench_openai.py:12/12replytoken_sha256s bit-identical acrossmain,#3920default MTP, and#3920 --drafter.TensorFold/GLM-5.3-Flash-MLX-4bit-MTPcheckpoint, paired receipts in Gist above.--drafteropt-in boundary (coldbench_cache.pybaseline was captured on4c616e63d; cold cache not re-measured onb9615a115aa).incoai/GLM-5.3-Flash-DFlash2(rev 6cc6c481) is Apache-2.0; user-supplied at runtime behind--drafter(not bundled).Kernel contract, only when a GPU kernel is new or changed
glm_draft_attend+glm_draft_attend_merge(zig/kernels/metal/glm_draft_attention.metal) — replaces plainkv_cachescalar/ring attention on the drafter's ring K/V cacheglm_draft_topk(zig/kernels/metal/glm_draft_topk.metal) — replacestf_bf16_topk(its spans and merge) for drafter logitsglm_draft_accept(zig/kernels/metal/glm_draft_accept.metal) — replaces lane core host chain acceptance for same-buffer GPU acceptanceglm_draft_follow(zig/kernels/metal/glm_draft_follow.metal) — replaces host-planned block ids, positions, and mask for sliding-window DFlash2 contextzig/src/core/contract/glm_dflash_records.zig,zig/src/core/contract.zig,zig/src/core/contract/registry_joins.zig,zig/tests/contract/metal_limits.zig,zig/tests/contract/metal_main.zig, andzig/tests/contract/metal_glm_dflash_*.zig.glm_draft_attend: ring slots read one past (FAIL shapes), masked key's value enters sums (FAIL nonfinite), every stream reads stream 0's ring (FAIL shapes)glm_draft_topk: tie broken toward higher token (FAIL shapes), k-th key's tokens left out (FAIL shapes)glm_draft_accept: draft compared with its own row's pick (FAIL shapes)glm_draft_follow: sliding window one key too long (FAIL shapes)tf_row_projection_q4_f32(2 limit problems),36 KiB tf_ctl_big_tg(8 limit problems);5 selected registered Metal launches against M1-M5, 0 problemsSUMMARYline and exit status:applegpu_g17, tensor units true,b9615a115aa):SUMMARY 10 kernels: 10 pass gates 1-4, 0 fail, 1 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problems; gates 772888 ms, limits 416 ms(exit0)b9615a115aa(M1/M2 checked offline via--offline;zig/tests/contract/metal_limits.zigchecks M1–M5 limits with0 problems); NVIDIA/AMD backends untouched (Metal-only change).Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.--drafter, no slower than without it, greedy and sampled