Repository navigation
qwen27 metal: M5 takes TF_QWEN27_METAL_KV_PAGES; a paged prompt chunk finds its two pages once - #3180
Conversation
8935976 to
60f31ec
Compare
|
@CodingEmil the M3 Pro cells you asked for in #1293, on head Apple M3 Pro, 14-core GPU (no tensor units), 36 GB, macOS 27.2, Zig 0.17.0,
Cold prompt, A-B-B-A (main, head, head, main, two rounds; fresh server per run,
So on this M3 Pro the change is exact and within 0.3 % of main either way; I can't tell whether the M5 gain should show here. Binaries (md5): |
068cceb to
7238ed8
Compare
|
@ashhart the six M5 Ultra cells you asked for in #1293 are now in the description. They are all measured on One caveat up front: while the cells ran, main moved 17 commits to the 1.2.9 cut and renamed the changelog's Unreleased section, so the pushed head is
@jschmied's M3 Pro cells are measured on the previous head
|
7238ed8 to
eee28f1
Compare
eee28f1 to
afdb113
Compare
|
@CodingEmil, FIXES: the modified paged prompt kernels still bypass the kernel contract. Its attention fixture explicitly selects the contiguous library. The separate shuffled-page checker compares bytes and plants non-finite inputs, but has no faulted-kernel controls. Please register the paged M5 and simdgroup variants with shuffled-page replacement cases, 255/256 and 511/512 boundaries, partial final pages, non-finite cases and controls that fail their intended gates, plus the paged variants' launch limits. The two-page address calculation preserves each 32-key step's address by inspection. The 25 host tests pass, and the native binary, page checkers and contract tool compile. We will run the default-path, paged prompt, DFlash2 and resumed/fresh device checks on our side once the contract covers these kernels.
|
afdb113 to
77c408a
Compare
…unch limits Answer the requested M5 and simdgroup contract coverage with shuffled pages, page and chunk seams, partial pages, independent nonfinite and stress references, contiguous byte replacements, and real source faults for gates 1 and 3. Keep production arithmetic unchanged.
|
Thanks @CodingEmil. To get this moving, we finished our last ask ourselves, keeping your commit as it was: the paged M5 and simdgroup prompt-attention variants are now registered in the kernel contract, with shuffled-page replacement cases, the 255/256 and 511/512 boundaries, partial final pages, non-finite cases, planted controls that fail their gates, and the paged variants' launch limits. We also rebased it onto current main. What remains is ours: the contract run and the default, paged, DFlash2 and resumed checks on a Mac. Nothing is needed from you, and #3377 can follow once this lands.
|
77c408a to
975703f
Compare
…unch limits Answer the requested M5 and simdgroup contract coverage with shuffled pages, page and chunk seams, partial pages, independent nonfinite and stress references, contiguous byte replacements, and real source faults for gates 1 and 3. Keep production arithmetic unchanged.
|
@ashhart @CodingEmil I ran the new paged-prompt contract on Apple M5 Max at zig build tf-kernel-contract tf-qwen27-attention-pages tf-qwen27-pages-resume -Dcpu=apple_m1
./zig-out/bin/tf-kernel-contract --only 'qwen27 paged prompt' --no-limits
./zig-out/bin/tf-kernel-contract --no-gates --only 'qwen27 prompt m5 paged'All 49 build steps passed. The four paged prompt kernels passed gates 1–4, both planted controls failed their intended gates, and all eight M5 launch records passed. The standalone attention checker matched 6,696,960 outputs and every cache row across 21 rounds. The synthetic resume checker matched restored, moved and fresh digests. It emitted the same 190 allocator diagnostics on this head and its merge base, This covers the M5 kernels and model-free parity checks. The simdgroup limits filter selected zero launches on this machine. The served checkpoint and DFlash2 checks still need a run. Igor Lessio - AIFLOW LABS |
…nit Macs take TF_QWEN27_METAL_KV_PAGES A 512-key prompt chunk spans exactly two KV pages, so the paged prompt kernels take both page bases before their 32-key steps instead of reading the page table at every step. The M5 refusal of the flag goes, now that the paged kernels have run on an M5 Ultra (part of ashhart#1293).
…unch limits Answer the requested M5 and simdgroup contract coverage with shuffled pages, page and chunk seams, partial pages, independent nonfinite and stress references, contiguous byte replacements, and real source faults for gates 1 and 3. Keep production arithmetic unchanged.
975703f to
9f56a1f
Compare
…mits Answer the requested M5 and simdgroup contract coverage with shuffled pages, page and chunk seams, partial pages, independent nonfinite and stress references, contiguous byte replacements, and real source faults for gates 1 and 3. Keep production arithmetic unchanged.
|
Thank you @CodingEmil. 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. |
What this changes
Before:
TF_QWEN27_METAL_KV_PAGES=1refuses to start on a Mac with tensor units (M5), and a paged prompt pass reads the page table at every 32-key step. After: M5 Macs take the flag, and the paged prompt kernels (q27_attn_prompt*, both the tensor-unit and the_sgtwin) find a 512-key chunk's two pages once and pick the right base per step. Output and cache bits are unchanged; with the flag off nothing changes.Both parts in one pull request as agreed in #1293 (the refusal goes because the paged kernels now ran on an M5, and the M5 numbers are what showed the per-step cost).
7238ed8e9) on2ba55ec7d(the 1.2.9 release commit).atc overlap --json(2026-11-14 16:10 UTC, on the measured head, based6c4cce60; not rerun after the rebase onto 1.2.9): incomplete (otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit). Fiveconflicts(dsv41 metal: the vision tower's kernels under the kernel contract #1721, dsv41 metal: image prompts #1722, glm cuda: TF_GLM_GRAPHS=1 replays verify windows as CUDA graphs (#1490) #2279, hip flashnext: a shared round's streams draft in one head pass a step #2696, XPU: Qwen3.8-27B attention merge with 16 subgroups per head, bit-identical #2799), each onlyCHANGELOG.md's Unreleased list, checked withgit merge-tree. qwen27: serve the 27B pair, refuse what a pair cannot keep, and die with the peer #1434 and Implement GLP control vectors with a fused Metal kernel for Qwen3.8-27B #1835 also conflict in code files, but in the same files against main itself (inherited, not from this change). Nothing else toucheszig/kernels/metal/qwen27/paged.zig.Checks on this head
7238ed8e9fb9741d81263c5f9db5161c3d42307e, base2ba55ec7d32d0bec446bb012678550be7ef52895(Release 1.2.9).068ccebabd4340507d946c99565ff4ddf11fe389on based6c4cce602eef4aff235625a5325bb617a9674ff. Every device cell, the test suite and the kernel contract below ran there. While they ran, main moved 17 commits to the 1.2.9 cut, which renamed the changelog's Unreleased section, so the commit was rebased once more to merge.git range-diff d6c4cce60..068ccebab 2ba55ec7d..7238ed8e9shows only the changelog hunk moving;paged.zig(19b29c1d) andqwen27_served.zig(f4b1108d) are the same blobs on both heads. None of the 17 commits toucheszig/kernels/metal, a qwen27 source, the lanes, the KV pool or the prompt cache (they are tests, the Living Weights v2 tool, the Ollama-compatible API, opt-in token IDs on streams, a build check and the release). The device cells were not repeated on7238ed8e9.python3 tools/zig/lean_check.py, on the base and on this head: 341 and 341, 0 new (tools/zig/lean_new.py), rerun on7238ed8e9against2ba55ec7d; the same counts as on the measured head. Inherited and untouched, e.g.tools/zig/reuse_served.py:265(a docstring past 120 columns) andtools/zig/flashnext_hc_coalesce.py:1(a multi-line docstring).068ccebab, M5 Ultra):zig build test test-golden -Dcpu=apple_m1: 868/868 steps succeeded; 14001 of 14119 tests passed, 118 skipped, 0 failed. Goldens: 322/335 and 55/55 equal to server goldens, 0 unexpected differences (13 known, recorded separately).tf-qwen27-attention-pages: PASS, 21 rounds, 6696960 output values and every cache row the same bits, paged and contiguous. With--shared-prefixthe same. On a Mac with tensor units the tool takes the shared-prefix plan in both runs (zig/tests/qwen27/attention_pages.zig:64), so on the M5 the two runs are one case; the flag matters on Macs without tensor units.tf-qwen27-pages-resume: PASS, restored equal to fresh, and restored, moved and fresh slots the same digests as main's. It prints 190 allocator leak lines at exit, the same 190 with paging off (Metal: KV pages from the core pool #1293): they come from the harness.zig build native tf-qwen27-attention-pages tf-qwen27-pages-resume tf-kernel-contract -Dcpu=apple_m1: builds.zig fmt --check build.zig zig: clean on the measured head; the two Zig files are unchanged since.git diff --checkandtools/pr_check.py --base origin/main --pr 3180rerun on7238ed8e9: clean, 0 errors, 0 warnings.CodingEmil <116643407+CodingEmil@users.noreply.github.com>, no attribution trailers._sgtwin, because I have only an M5. jschmied's M3 Pro cells in this PR's thread cover it, measured on the previous head60f31ecb6, whose paged kernel sources are the same blobs as this head's.zig build dev-toolswas not rerun, because the change edits no API atf-*tool calls (the tools above were built and run). Sampled temperatures, 2K and 64K cold prompts, and--drafterdecode speed were not run.Receipt
Main against branch: below. Main is the measured base's binary (
d6c4cce60), the branch is the measured head's binary (068ccebab) withTF_QWEN27_METAL_KV_PAGES=1unless a cell says otherwise. Each measurement has a fresh server with--context 65536 --parallel 2 --prompt-cache-gib 0, the same checkpoint and settings, and no other model process on the machine.Boxes it reaches: Metal, Qwen3.8-27B, only with
TF_QWEN27_METAL_KV_PAGES=1. With it unset, the branch's tokens equal main's (flag off, below).New switch? No. The existing
TF_QWEN27_METAL_KV_PAGES(default off) now also starts on tensor-unit Macs.Environment: measured base
d6c4cce60and measured head068ccebab, both built from those trees with-Dcpu=apple_m1. Zig 0.17.0, Xcode 27.2 (27B52), Metal toolchain 27B47, macOS 27.2 (26B118), Apple M5 Ultra, 96 GB. CheckpointTensorFold/Qwen3.8-27B-MLX-4bitat22d8d538, drafterz-lab/Qwen3.8-27B-DFlash2at50307d4c. All cells measured on 2026-11-14 in one sitting.Paths and platforms: the paged prompt kernels (the tensor-unit
q27_attn_prompt_8path and the_sgtwin) and the start-up refusal. Ran: M5 Ultra (tensor units). Not run by me: M1 to M4 (_sg); an M3 Pro ran the previous head (see above).Exactness,
tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,2 --alone --serialwith--drafter, code and chat prompts:token_sha256are the same between main and branch (a10c9b84…4130code,a06fab34…8f52chat).token_sha(a10c9b848ed9,a06fab348fbe), so drafted equals plain.token_sha256in all runs (d2e888be…61ee,53568b8b…b7d1).Flag off equal to main: the measured head's binary without the variable, the same requests.
bench_concurrentwith--drafter: equal alone and serial, all 54token_sha256the same as main's.token_sha256as main's.bench_openaidecode: the sametoken_shaas main's, 48.05 / 48.02 t/s against main's 48.14 / 48.10 and 48.02 / 47.99.Main against this branch: posted in Metal: KV pages from the core pool #1293 on main's kernels; every row below is on the measured head, with this change's kernels.
Decode,
tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, no drafter, alternated main, branch, branch, main (median t/s,fibonacci-raw/gpu-chat-no-think):Branch 0.8% faster (each run within 0.5% of the 2026-11-13 cells on main's kernels).
Two streams,
bench_concurrent.py --levels 2(aggregate t/s, code / chat):Prompt speed,
tools/bench_cache.py --require-cold --streams 1 --tokens 64with a fixed token array, alternated main, branch, branch, main; coldttft_s,cached_tokens0 in every run:Without this change the flag's cost was +1.0% at 8K and +2.7 to 2.8% at 32K on the same machine (Metal: KV pages from the core pool #1293). The remaining cost is the flag's and opt-in; main's default path is not touched, and flag off its tokens equal main's.
Raw results: the JSON files of every cell (
bench_concurrent,bench_openai,bench_cache), the two token arrays, the server logs and the test and contract logs: https://gist.github.com/CodingEmil/02308e5f3575c1311ddc08a289e7a842Licence of any new weights or drafter: n/a, none.
Kernel contract, only when a GPU kernel is new or changed
zig/kernels/metal/qwen27/paged.zig). They are not registered with the contract;tf-qwen27-attention-pageschecks them bit for bit against main's contiguous kernels (above).SUMMARYline and exit status, M5 Ultra:zig build kernel-contract -Dcpu=apple_m1refuses before any kernel on this Xcode, on main (d6c4cce60) as on the measured head, exit 1:rotary probes refuse this deployment: run tf-rotary-sweep and pass --rotary-accuracy FILE (UnrecordedRotaryCompiler).tf-kernel-contract --only q27, measured head:SUMMARY 24 kernels: 24 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems; gates 18039 ms, limits 184 ms, exit 0.tf-kernel-contract --only q27, main:SUMMARY 24 kernels: 24 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems; gates 17853 ms, limits 29 ms, exit 0.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. (No new test; the existing
tf-qwen27-attention-pagescovers the edited kernels.)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. (Default path unchanged, flag off equal to main. With the opt-in flag: decode 0.8% faster at one stream and 0.5 to 0.6% faster at two; cold prompts 0.3% (8K) and 0.7% (32K) slower. Sampled and--drafterspeed not run.)