Repository navigation
glm(metal): prune inactive DFlash2 rows, gate tap capture, and cut sampled transition cost - #4257
Merged
Merged
Conversation
8 tasks done
gilby
force-pushed
the
glm-metal-dflash2-w2
branch
from
November 21, 2026 06:21
190e1fe to
1d57c82
Compare
gilby
marked this pull request as ready for review
November 21, 2026 06:23
This was referenced Nov 21, 2026
…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
ashhart
force-pushed
the
glm-metal-dflash2-w2
branch
from
November 21, 2026 17:21
1d57c82 to
0081969
Compare
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Prunes inactive DFlash2 rows (
metal_dflash_encode.zig), gates tap capture when no stream is actively drawing a DFlash2 chain (Taps.setActive), scatters the four HC streams' mean directly into the tap ring without an intermediate staging buffer (glm_tap_mean_ringinglm_glue.metal), and flattens sampled trees across active prefixes (metal_dflash_rounds.zig+metal_dflash_source.zig).main(d7dc085bfcb50f5ac21271c22fd58d3de13b8ba1, after glm metal: draft GLM-5.3-Flash with published DFlash2 behind --drafter #3920 merged); rebased ontomainat1d57c823ffb7aa1ae54334d682dbe11abf9ce21e(git range-diffagainst receipted head190e1fe04f9ccd13717c98afc3db5869d57b35d3is=).atc overlap --base origin/main --json:18changed files;3clean PR overlaps (#1787,#2008,#2340),7older conflicting PRs,8unknown.Checks on this head
1d57c823ffb7aa1ae54334d682dbe11abf9ce21e(rebased cleanly withrange-diff =from190e1fe04f9ccd13717c98afc3db5869d57b35d3)python3 tools/zig/lean_check.py, on the base and on this head:168onorigin/main(d7dc085bfc),168on head (1d57c823ff),0new findings (python3 tools/pr_check.py --base origin/mainexits0;metal_main.zig595lines,metal_dflash_rounds.zig596lines).glm_tap_mean_ring,metal_dflash_encode.zig, andTaps.setActiveare absent onmain, whereTapsallocates astagebuffer and scatters every tap layer unconditionally.1d57c823ff, with the command and pass, fail and skip counts:zig fmt --check build.zig zig— passed (0exit)git diff --check origin/main..HEAD— passed (0exit)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/95steps succeeded;340/340tests passed (test-glm-metal-dflash-host15/15,test-glm-scheduling-host/test-glm-prefill-widths-host63/63,test-glm-metal-dflash-syntheticglm dflash2 follow: chains agree with today's pass on 2688 of 2688 drafts,test-kernel-contract192/192+ sub-suites)./zig-out/bin/tf-kernel-contract --only "glm tap"on Apple Metal (applegpu_g17,tensor units true) — exited0:SUMMARY 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems; gates 12 ms, limits 49 ms190e1fe04f(git range-diff =to1d57c823ff):zig build test-golden—322/335&69/69,0unexpected differencesfamilies.glm.*unit tests —All 220 tests passed../zig-out/bin/tf-kernel-contract --no-gates --only "glm tap" --offline ...— passed (PASS limits: 1 selected registered Metal launches against M1-M5, 0 problems;PASS offline glm tap glm_tap_mean_ring: 256 threads; M1 pipelines take 256, M2 256; both limit controls red)1d57c823ff(was 9/9 green on190e1fe04fprior to rebase).--offlinelimits); CUDA/ROCm paths (Metal-only DFlash2 change).Receipt
Full scrubbed receipts (taken at
190e1fe04f,git range-diff =to1d57c823ff; contract log,bench_concurrent.py,bench_openai.pyonMLX-4bit-MTP+--drafter--drafter-bits 4): https://gist.github.com/gilby/212629ac206e8ee2b64b8fb5618e68fdb9615a115aa) against190e1fe04f, same Apple M5 Ultra (256 GB) andTensorFold/GLM-5.3-Flash-MLX-4bit-MTP+--drafter zai-org/GLM-5.3-Flash-DFlash2 --drafter-bits 4,--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 everyaloneandserialcheck;timing_valid=True):#3920(b9615a115aa)D1(190e1fe04f)#3920steadyD1steadycode 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_shas bit-identical to glm metal: draft GLM-5.3-Flash with published DFlash2 behind --drafter #3920):#3920(b9615a115aa)D1(190e1fe04f)fibonacci-raw T=0.0gpu-chat-no-think T=0.0fibonacci-raw T=1.0gpu-chat-no-think T=1.0glm5_nexton Metal with--drafter(single Mac,tp == 1).1d57c823ffb7aa1ae54334d682dbe11abf9ce21e(rebased ontomaind7dc085bfc,range-diff =vs receipted190e1fe04f9ccd13717c98afc3db5869d57b35d3)0.17.0(-Dcpu=apple_m1), macOS Metalapplegpu_g17, 256 GB unified memory, tensor units true)TensorFold/GLM-5.3-Flash-MLX-4bit-MTPwith DFlash2 drafter (--drafter-bits 4)2688/2688 drafts), Metal contract + M1/M2 offline limits, unit/golden/host tests.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:bench_concurrent.py --alone --serial:0unequal and0failed across everyalone(concurrent == alone) andserial(drafted == "draft": false) comparison.bench_openai.py:12/12replytoken_shas bit-identical to glm metal: draft GLM-5.3-Flash with published DFlash2 behind --drafter #3920.4/4prompts faster inbench_openai.py,chat T=1.0 N=1 +2.18%).Taps.stageallocation and skips tap writes for capped or non-DFlash streams; full prefill benchmark not re-run.Kernel contract, only when a GPU kernel is new or changed
glm_tap_mean_ring— computes the mean of four HC streams directly into the target ring slot, removing the intermediateTaps.stagecopy (glm_stream_meanstaging pattern).zig/src/core/contract/glm_tap_records.zig,zig/src/core/contract/registry_joins.zig,zig/tests/contract/metal_glm_tap_ring.zig,zig/tests/contract/metal_limits.zig, andzig/tests/contract/metal_main.zig.glm tap control: writes into input(FAIL repeat)glm tap control: misses ring wrap(FAIL shapes)glm tap control: wrong scale 0.5(FAIL shapes)tf_row_projection_q4_f32(2 limit problems),36 KiB tf_ctl_big_tg(8 limit problems);1 selected registered Metal launches against M1-M5, 0 problemsSUMMARYline and exit status:applegpu_g17, tensor units true):SUMMARY 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems; gates 12 ms, limits 49 ms(exit0)--offline;metal_limits.zigchecks M1–M5 limits with0 problems); NVIDIA/AMD 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