Repository navigation
qwen27 metal pages: a stream promises its pages as its rows come and gives them back when it leaves - #3377
Conversation
|
DEVICE. @CodingEmil, the eight page-promise host cases pass, along with native builds, all 16 Qwen runtime libraries and zero new lean findings. The source waits for readers before ordinary release and preserves retained cache pages through reset and promotion. We will run the device check on our side: cancel and resume, promotion, rewind and an outstanding keep during another fill, with pages on and off. Replies and cached counts must stay exact, and promises and released leases must return to the expected census. Green zig, zig-windows, pytest and fmt CI at this head is also needed before landing.
|
864e6f1 to
c416662
Compare
|
@ashhart rebased the stack on main On the M5 Ultra at these heads: The CI runs on this PR are waiting for approval ( |
|
@CodingEmil DEVICE. On M5, all 182 full replies match main across page-on/off, greedy/seeded, plain/DFlash and four streams. An interrupted fill retained 2,048 rows and resumed them exactly; interleaved cache restores stay exact and the idle page counts balance. Page-on 32K prefill takes 0.47-0.49% longer than main. Page-off also takes 0.12-0.22% longer in the 2K start-0 and 8K cells, beyond their observed base ranges. At ready, page-on physical footprint is 39.55-39.73 GB versus main's 30.99 GB because the whole arena is reserved. This needs a performance answer and green CI before landing.
|
|
@ashhart thanks for the device run. I measured the three points on the M5 Ultra as a three-way: main Footprint (GB,
The 8.6 GB at ready is the second slot's window: the arena for every slot is one buffer made at load and joined to the residency set, which #3180 already does. Main without pages makes slot 0 at load and each further slot at its first use, and is level once both are used. This PR does not change the arena. It moves the promises from load to the rows, so it does not lower the footprint by itself (the description's "what a user of this pull request alone gets" says the same). What it gives is that a slot which cannot get a page fails cleanly before a write, which is what a smaller arena needs. I'd propose that as a follow-up after #3378. 32K cold prefill (s, order M A B B A M, 3 rounds, median of 6)
So the page-on cost is the paged prompt kernels against the contiguous ones, as in #3180's cells; this PR adds 0.03 % on top, inside the spread of the runs. Pages off, 2K and 8K cold (s, order M A B M′ M′ B A M, 3 rounds, median of 6; M′ is a second, separate build of main)
I can't reproduce a page-off difference here: both heads are within 0.02 % of main, as close as main's second build. With the flag unset this PR runs a few extra calls per stream that return at once ( The stack needs one more rebase for the changelog; I'll do it when the CI runs are approved so it doesn't go stale again. |
|
DEVICE. @CodingEmil, thanks for the three-way check. The arena allocation is already in #3180; #3377 changes the promises, so its ready footprint is not a new allocation introduced here. All 182 complete replies and the cancel/resume and page-count checks stay exact. The differing cold cells used context 40960, parallel 4, prompt rows 2048, cache 0, raw 2048/8192-token prompts at starts 0 and 5000, temperature 0, seed 1234, draft false and 64 output tokens. A drafter was attached for separate chat checks. After discarding a warm-up, the order was main/on/off/off/on/main, two measured processes per arm. Page-off start-0 2K was 1.097337 -> 1.099804 s; 8K starts 0/5000 were 4.393875 -> 4.401946 s and 4.392679 -> 4.397897 s. Please repeat those settings alongside your separate-build main control. CI is still awaiting approval at this head, so this remains DEVICE.
|
|
@ashhart repeated with your settings on the M5 Ultra, page-off on every arm:
Both heads are as close to main as main's second build (−0.08 to +0.03 % against −0.04 to +0.05 %), so the page-off difference does not show here. Two things I could not match: your prompt text (mine is a fixed synthetic token sequence, cut at offsets 0 and 5000), and the attached drafter. If you can share the prompt source or the script, I'll run exactly that. One more thought: two builds of the same main already differ in their bytes here, so a separate-build control on your side would show how much of 0.1–0.2 % is layout. CI at Rebased the stack onto main |
c416662 to
f0e5bf8
Compare
|
@CodingEmil, thank you for repeating it with our settings and a second build of main. Both heads sit as close to main as main's own second build does, and We approved the workflows at the rebased head (
|
|
I retested On that combined tree I ran the pinned Qwen3.8-27B MLX 4-bit ( python3 tools/bench_concurrent.py http://127.0.0.1:PORT local-model \
--levels 1,2 --tokens 320 --reps 1 --temperatures 0,1 --seed 1234 --alone --serialAll 12 paired full token hashes matched across page modes, with zero failed requests. The two-stream runs overlapped, and all concurrent-versus-alone and drafted-versus-plain comparisons matched. The paged server shut down with all 66 pages free. This covers the combined M5 path at the tested window; I left the parent-first landing order as noted above. Igor Lessio - AIFLOW LABS |
|
I reran the focused checks on the exact #4277 train tip zig build test-qwen27 test-qwen27-reply-cache-host test-qwen27-startup-host test-kv-pool test-prefill-service-host tf-qwen27-pages-resume -Dcpu=apple_m1 -Dversion=0.0.0 -j3 --summary all
./zig-out/bin/tf-qwen27-pages-resume342 tests passed with three skips. The resume tool exited 0 and matched the restored, moved and fresh slot digests. It printed 190 allocator diagnostics, the same count recorded on the earlier parent-only run. This verifies the exact train's host and resume paths. The earlier served-token comparison was on the earlier trial tree. 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).
…gives them back when it leaves With TF_QWEN27_METAL_KV_PAGES=1 a slot no longer holds a promise of its whole window from startup. A stream opening a slot is promised its prompt and one widest pass; a pass past that promises the rest before it takes a page, and a promise the pool cannot meet fails with LaneMemory before any page is taken or table entry written. Leaving, failing or being put back, a reset and a move to slot 0 give the pages and the promise back; a standing slot 0 keeps the pages of its committed rows. The page lifecycle is in families/qwen27/slot_pages.zig, its host tests in slot_pages_test.zig (part of ashhart#1293).
f0e5bf8 to
a82be91
Compare
|
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=1promised every slot the pages of its whole window when the model loaded (kv_pages.caches), and the promise stayed for the server's life; pages were already taken as rows came. With this change, a stream that opens a slot is promised the pages of its prompt and one widest pass. A pass past that promises the rest before it takes a page, and a promise the pool cannot meet fails withLaneMemorybefore any page is taken or any table entry written. A stream that leaves, a prompt pass that fails or goes back to the queue, a reset and a move to slot 0 give back the slot's pages and its promise; a standing slot 0 keeps the pages of its committed rows for its resume. Without the flag, nothing changes.7238ed8e9on main2ba55ec7d). This pull request adds one commit,864e6f1d5.atc overlap --json(2026-11-14 17:55 UTC,ATC_READ_ONLY=1, on864e6f1d5): 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 on one shared file. They are the same five qwen27 metal: M5 takes TF_QWEN27_METAL_KV_PAGES; a paged prompt chunk finds its two pages once #3180 lists, where each wasCHANGELOG.md's Unreleased list; I have not rechecked them withgit merge-treeon this head. The other entries are clean or only share files.Checks on this head
864e6f1d5on7238ed8e9.python3 tools/zig/lean_check.py, on the base and on this head: 341 on the base, 341 on the head, 0 new (tools/zig/lean_new.py). The 341 are inherited. No touched file is over 600 lines:decode_round.zigis at 594, because the page lifecycle is in the newfamilies/qwen27/slot_pages.zigand the runner keeps one-line aliases to it.zig build test-qwen27: base 149 passed, 2 skipped; head 183 passed, 2 skipped. The 8 new tests inslot_pages_test.zigrun in it (alone, through a test filter: 11/11). The rest of the increase iscoretests the new test file brings into the module's test binary.zig build test-qwen27 test-qwen27-reply-cache-host test-qwen27-startup-host test-lane-api-host test-lane-strand-host test-lane-halt-host test-lane-lone-host test-lane-interrupted-host test-kv-pool test-prefill-service-host test-flashnext-batch-host: 84/84 steps, 1083 passed, 2 skipped.zig build native tf-qwen27-attention-pages tf-qwen27-pages-resume -Dcpu=apple_m1: builds.zig build test test-golden -Dcpu=apple_m1 --summary all, with the GPU free: 870/870 steps succeeded, 13807 passed, 116 skipped, 0 failed. Five test steps came from the build cache, and the summary does not count their tests.zig fmt --check build.zig zigandgit diff --check: clean.python3 tools/pr_check.py: 0 errors, 1 warning (it asks for--pr NUMBERto check the Unreleased line).slot_pagesfor the base's policy: the whole window promised at the first open, a growth taking pages only, leaving and a reset touching nothing. All 8 new tests fail with it.LaneMemory, with no page taken, no table entry written and the pool's counts unchanged;promote) leaves the old slot empty and unpromised;zig build dev-tools: the runner'scover,promise,releaseandresetkeep their call shape (aliases), and the two page tools build.qwen27_slots.prefillStephas no host test, because it needs the Metal backend. On the device, the cell that cuts a stream mid-prompt ends with every page free; I have not checked that the cut takes this path rather thanunbind.Receipt
7238ed8e9(A) against864e6f1d5(B), a fresh server per cell,--context 65536 --parallel 2 --prompt-cache-gib 0. Every reply hash is equal, speed is level, and every stop with the flag readsKV pages idle, 514 of 514 freewith noLaneMemory. The cells are in the lines below.kv_pages.caches:slots × pages(capacity)).Pages.coverfrom the promise), so the pages written, the arena and the footprint are the same.qwen27_slots.opening,PromptTooLong).phys_footprintevery 0.5 s, at idle and through two parallel 30k conversations of two turns each. A: 36 GiB idle, 37 GiB peak. B: 36 GiB idle, 37 GiB peak (footprintprints whole GiB). The eight replies have the same hashes on A and B, and the times to the first token agree within 0.02 s.TF_QWEN27_METAL_KV_PAGES=1.864e6f1d5on7238ed8e9, Zig 0.17.0, Xcode 27.2 (27B52), Metal Toolchain 27B47, Apple M5 Ultra, 96 GB, macOS 27.2. Device cells:TensorFold/Qwen3.8-27B-MLX-4bit, with thez-lab/Qwen3.8-27B-DFlash2drafter where a line says so.bind, and the lone driver's slot 0); every pass's pages (Runner.coverfrom verify, a kept state's restore and a move); a stream leaving (unbind); a prompt pass that fails or is requeued (prefillStep); a reset (ready,opening,refill,costs);promote.snapshot.rewindSlotclears the DeltaNet state only).Runner.kvis null, everyslot_pagesentry returns at once, and the failed-pass release returns at once too._sgkernel, and this pull request adds none.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:--tokens 256 --reps 3 --temperatures 0 --levels 1,2 --alone --serial, with the drafter, on four servers: A and B without the flag, A and B with it. Each: alone 3/3 and 6/6 equal, serial equal, 0 failed, oncodeandchat. All 54token_sha256of a server are equal to the same 54 on each of the other three.--prompt-cache-gib 8): a 19,711-token second turn resumed from its slot (cached 19,686), resumed after two other prompts took both slots (cached 19,688), and cold on a fresh server (cached 0) gives onetoken_sha256.tf-qwen27-attention-pages(plain and--shared-prefix) andtf-qwen27-pages-resumeon B: PASS.tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, flag on, no drafter, A B B A, median tokens/s:fibonacci-raw48.33, 48.29, 48.20, 48.24;gpu-chat-no-think48.25, 48.29, 48.25, 48.26. Sametoken_shaon all four.tools/bench_cache.py --require-cold, flag on, no drafter, A B B A, time to the first token: 8k 5.292, 5.292, 5.292, 5.291 s; 32k 23.369, 23.365, 23.361, 23.362 s. Sametoken_sha256on all four,cached_tokens0.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 (host pool, no device).
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: resumed and concurrent are measured above. Drafted against"draft": falseis not run on this head; the change touches no drafting code.No precision traded for speed. No arithmetic changes.
Decode and prompt processing are no slower than main at one stream and the widest admitted (cells above; two streams through
bench_concurrent --levels 1,2).