Skip to content

kv classes (#2444 C1): admission by owner class, the owner chosen once inside the reservation - #3676

Open
jschmied wants to merge 27 commits into
ashhart:mainfrom
jschmied:kv-c1-classes
Open

jschmied wants to merge 27 commits into
ashhart:mainfrom
jschmied:kv-c1-classes

Conversation

@jschmied

@jschmied jschmied commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Roadmap #2444, P1 item C1, as agreed in issuecomment-6936659313. Base: #2415 (wojo's up-kvsplit2, now at 5af6a50f86, carried here as rebased onto main). This PR is the top six commits: C1, the review fixes, ashhart's three rebase commits and the retire→settle regression. Head 706ae4ba6563cbe7c6f657048d45dbc7211e1d9d. It lands after #2415. Design: issuecomment-6928646545.

Review (2026-11-24): retire→settle by owner class

Head 706ae4ba6563cbe7c6f657048d45dbc7211e1d9d, one test-only commit on ashhart's ec4aea0f43. That head is his rebase plus "rebase: keep no-hook admission cheap". No runtime change.

  • kv_pool_class_test.zig:240 runs through Pool.initClasses at one and two classes; with two, the page belongs to class 1. The test reserves and takes one page, retires it at reader token 18, and settles 17, then 18. After 18, the owner class has one more free page, the lease and the class each hold one promise again, and the next take returns the same id from that class. A second retire after 18 covers the immediate freeOrPend path.
  • Planted controls (kv_pool_retire.zig settle and freeOrPend), each red, then green once restored:
    • the original total-only free-stack write in settle: 6 fail, including the new test;
    • a class-blind write to class 0's stack in settle: only the new test fails;
    • the same class-blind write in freeOrPend: 7 fail, including the new test.
  • Results on this head: test-kv-pool 124/124; zig fmt --check and git diff --check clean; tools/pr_check.py 0 errors, lean 165 = 165. Full x86 CI set: green (test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 2455/2455 steps, 24966 passed, 157 skipped; check-native-cuda-host compile-cuda-tests 17/17; lean 0 new).
  • The head conflicts with current main in GLM disk files (cuda_disk_image.zig and others) that landed after the rebase. It has not been rebased; that waits for your ask.

Rebase (2026-11-22)

Head 00fb1516d2ceb61236186e6f9c55133c622a1af9, rebased onto main e6094de132 on the user's request. Before that, ashhart rebased it to fb13fdde6d for train #4479, which is now closed. Both of ashhart's commits are kept: "rebase: adapt admission and launch recording hooks" and "rebase: keep lane_host at 600 lines". The whole stack moved as one: #1411's and #2415's commits as #2415 carries them (#2415 head 5af6a50f86), then C1.

  • One conflict, the one AIFlowML found (issuecomment-7076532350), in families/glm/cuda_env_test.zig. Main's TF_GLM_INDEX_SPLIT stays in added, and this stack's TF_GLM_KV_SPLIT keeps its own splits row beside it. Both have their tests, and the count test adds both lists.
  • Did main change code that C1 calls? Since fb13fdde6d's base, main touched one file of C1's diff, native/cuda.zig. Those changes are the load-time pool read (poolCached, no page drop before a GB10 load) and do not touch the Admit wiring. No admission, pool or ledger file moved, and no .cu changed. Because the only conflict is in a test list, the host tests below are the evidence for this head. The device and served rows below are carried.
  • Rerun on 00fb1516d2 (GB10 host, Zig 0.17.0): test-kv-pool test-kv-safety-host test-glm-ring-host test-glm-regions-host test-glm-pages-host test-gradient-serving check-native-cuda-host test-glm-rev25-host test-glm-admission-host test-glm-snapshots-host gave 45/45 steps and 271/271 tests. Also clean: zig fmt --check, git diff --check, and tools/pr_check.py --base origin/main (0 errors, lean 165 = 165, 0 new).
  • Carried: the served tables and fatbin equality below were measured on a203fd1af0 (base GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415 af17f6c8fc). AIFlowML checked fb13fdde6d on M5 Max (issuecomment-7076532350): 183/183 tests and the ARM64 CUDA server compiled. The planted-control logs and the full CI set (golden, cuda-host, x86) are also from a203fd1af0. GLM TP=2 still needs your pair.

Review fixes (a203fd1af0, a new commit on top of 3c648fed3c)

Each finding was first shown by a test that fails on 3c648fed3c (red-c1/r2-confirm-3c648fed3c.log). Each fix is then green, and each new test is red again against its planted control (rows r1-r3 below).

  1. An oversized request waited while every lane was busy. pick returned null once the lanes were full, so never was not asked. With one lane and one long stream, one(9) on classes of 8 stayed queued until that stream ended. Now takeJob first asks admit.refused (lane_host_admit.zig:26) under the host lock, whether or not a lane is free. That pass skips requests that wait for a disk read or a prefix cut, and requests already named in cancels. The refusal is the same too_big_class path as before, before any promise or copy. Without Admit.need, pastClass is false at once, so every family except GLM, and GLM at one class, answers as before. Test: kv_classes_host_test.zig:172.
  2. A missing class hook read the whole pool as each class. Ledger.ofPages now returns NoClassHook for a pool of several classes without the hook (kv_ledger.zig:36; countPool names it too), and kv_classes.class has no whole-pool fallback. A one.in past the pool's classes (kv_classes.zig:40) never fits, and neverNeed names it, so it is refused, not indexed. Test: kv_classes_test.zig:298.
  3. A failed reservation could notify with the failed owner. reserve set l.owner and called promise. That call is a whole pool change, so its notice fired before the owner was restored. reserve is now one outer pool change (kv_pool_classes.zig:61), and the notice fires once, after the rollback. Test: kv_classes_test.zig:272, an observer that records l.owner at notice time.

What it does

  • core/kv_classes.zig (new, 86 lines): Need = one{n, in} (all n pages from one class; in set when a resumed prefix fixed the class) or spread{k0, k1} (logical page k in class k mod W, DeepSeek's span). spread is admission-only in P1: a lease still holds one owner and take pops from it. Also wantIn, fitsNeed, neverNeed, all read through the ledger.
  • Gate.want takes (class, n) (kv_pool.zig:210, :305). promise makes one test, its class's, with the pool's bytes inside it (kv_pool.zig:379). hold does the same (:391). null is the whole pool, which fits and reclaimFor use as before.
  • Single-owner reservation: Pool.reserve (kv_pool_classes.zig:56) chooses the owner inside the reservation, once. It takes the class of the pages the lease already holds, else the resumed prefix's class (in), else roomiest. It then promises in the same call. If that fails, the owner and every count stay as they were, and the whole reservation is one pool change, so the change notice fires once, after the promise or the rollback. A lease never moves class (BadClass). GLM's openOwned (families/glm/cuda_pages.zig:223-234) now passes null instead of choosing roomiest() before promise. A resume's adopted pages fix the class, and adopted pages from two classes are refused with ResidueMismatch. Before, adopting into a roomiest lease of another class hit owned()'s panic.
  • Per-class limits: the ledger reads each class's cap/available through a new Counted.class hook (kv_ledger.zig:22). The hook is null at one class, and lane_host_ledger.count sets it above one class (lane_host_ledger.zig:36); Ledger.ofPages refuses several classes without it (NoClassHook, kv_ledger.zig:36). Admit.need is optional (engine_api.zig:251). When set, admission asks fitsNeed beside the family's fits (lane_host_admit.zig:69, lane_host_ledger.zig:105). GLM sets it (kvNeed, families/glm/cuda_native.zig:124, wired at native/cuda.zig:442). No other family does.
  • Refusal by name, while others run: never (lane_host_ledger.zig:85) now returns why. A need larger than a whole class is refused with too_big_class ("…exceed one whole KV owner class (TF_GLM_KV_SPLIT)…") at lane_host.zig:360. It fires even while other jobs hold pages and every lane is busy (lane_host_admit.zig:26, asked before pick at lane_host.zig:356); before, never fired only with nothing outstanding. GLM's Pages.fits (cuda_pages.zig:196) no longer answers true for such a request; the lane host refuses it before any promise. GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415's cuda_pages_split_test.zig:278 asserted the old fits == true, so it now asserts !fits. open still returns ClassTooSmall for it.
  • Reclaim restriction kept: joinReclaim still refuses above one class (kv_pool.zig:400-401, unchanged). Above one class, fitsNeed counts no reclaimable pages, so admission's answer is exactly what reserve will do. The interleaved test checks this at every step.

Not here, as agreed: rank classes (DeepSeek's per-rank usable) and host frames (#1501/#1522) wait for their first user. HIP's pages.Ids waits for P7. No kernel, Metal or HIP change. kv_pool.zig stays at 600 lines.

Host tests, each red against a planted control

All in zig build test-kv-pool (80/80 green on the head). Tests 1, 2, 4, 6, inv and rb are in the pool+ledger module; 3 and 5 run through a real LaneHost over the fake target, with the pool counted in its ledger. The control is the fault planted at the cited line. Receipts are in red-c1/, one log a control, and each one fails exactly the test named.

# Test Planted control (file:line) Red
1 kv_classes_test.zig:42 classes of 6 and 2 available, one(7) waits, though 8 are free total-only: fitsNeed returns true past the bytes test (kv_classes.zig:61) yes
2 kv_classes_test.zig:61 W=2 spread needing {3, 2}, class 1 at 1 available, waits same yes
3 kv_classes_host_test.zig:160 one(9) against a class of 8 is refused at once by name while another stream runs, with nothing promised or taken for it; at one class of 16 the same request runs (a) neverNeed on totals (kv_classes.zig:80); (b) refused only when idle (lane_host_ledger.zig:92) yes, both
4 kv_classes_test.zig:78 each class's census is idle after takes, trims and finishes shrink skips the class count (kv_pool.zig:505) yes
5 kv_classes_host_test.zig:180 a head that needs class 0 (fixed) lets a later class-1 request go first, never reaches a failing reservation, and runs once class 0 has room choose on totals (lane_host_ledger.zig:107) yes
6 kv_classes_test.zig:264 one class counted in a ledger with bytes beside it: 3000 seeded steps, every count and fits/want answer hashed. Hash 0xf005c622d55ebd68 was recorded by the same walk on #2415's head af17f6c8fc (promise there, reserve here). At each step fitsNeed(one(k)) == fits(k), wantIn(0, k) == want(k) and neverNeed == null changed reclaim ask (kv_pool.zig:415, asks n instead of want) yes (aborts)
inv kv_classes_test.zig:124 interleaved two-class sequences (W=2 and W=3, 3 seeds, 600 steps, a bytes lease beside). After every step: class promises sum to the pool's promised count, and no class promises more than it holds free. A lease's ids are all of its class. For a new lease, fitsNeed predicts reserve exactly. A failed reservation leaves every count and the owner unchanged promise skips the class count (kv_pool.zig:381) yes
rb kv_classes_test.zig:175 a failed reservation, a cancel mid-stream and a requeue (promised, nothing taken) each leave every count and the owner as they were reserve keeps the failed owner (kv_pool_classes.zig:65) yes
r1 kv_classes_host_test.zig:172 lanes=1, one long stream holds the lane: one(9) against a class of 8 is refused by name before that stream is cancelled, nothing promised or taken for it refusal only through pick (lane_host.zig:356) yes
r2 kv_classes_test.zig:298 two classes without the class hook: ofPages gives NoClassHook; a resume's class 2 on a pool of two never fits and neverNeed names it (a) no hook check (kv_ledger.zig:36); (b) no class bound (kv_classes.zig:45) yes, both
r3 kv_classes_test.zig:272 a failed reservation notifies once, and the observer sees the owner already restored no outer pool change in reserve (kv_pool_classes.zig:61) yes

#2415's own pinned hashes are unchanged and green on this head: kv_pool_trace_test.zig (0x9289b00642a64c9) and kv_pool_class_test.zig (0x6a51e5e6ca5c61f6).

One class changes nothing

Every comparison here is against #2415's head, not against main, because this PR is stacked on #2415. #2415 itself conflicts with main (CHANGELOG, docs, engine_api.zig, kv_pool.zig). The review commit adds one more, in lane_host_admit.zig: main's new hold and our refused sit at the same place, and both stay. Once #2415 lands or is rebased, we will rebase this branch on it and rerun every row.

model (env) startup line most running requeued idle census at stop reply md5s (8)
Gemma 4 31B same counts (free room only) 4 / 4 0 / 0 promised 0, free 132 == total 132 both identical
Gemma 4 31B, TF_KV_SHARE=8 pool 2197 / 2196 pages* 4 / 4 0 / 0 promised 0, free == total both identical
Qwen3.8-27B (MLX 4-bit) identical 4 / 4 0 / 0 none printed (both) identical
Qwen3.6-35B-A3B, TF_QWEN_KV_PAGES=256 TF_QWEN_KV_SHARE=32 identical 4 / 4 0 / 0 none printed (both) identical
Nemotron 3.5 Lightning identical 4 / 4 0 / 0 free 51 == total 51; slots free 55 + held 9 == 64 both identical
Kolibri-1 same counts (free room only) 4 / 4 0 / 0 free 68 == total 68 (head printed it twice*) identical
Spark2.5 prompt cache 50.1 / 50.0 GiB* 4 / 4 0 / 0 free 132 == total 132 both identical
Dory, TENSORFOLD_DORY_KV_PAGES=1 identical 4 / 4 0 / 0 free 128 == total 128 both identical
Flash Next, TF_FLASHNEXT_KV_PAGES=256 identical 4 / 4 0 / 0 none printed (both) identical

72 of 72 replies are hash-identical. The hash covers reasoning and content, and every reply has more than 100 characters.

* These follow the free memory read at load, not the binary. We reran these three cells in A-B-B-A order (head first, then base first). #2415's own binary gave Gemma-share pools of 2197, 2198 and 2205 pages, a Spark2.5 cache of 50.1 or 50.0 GiB, and the mid-run idle census once or twice. Each head figure fell inside that spread, and replies were identical in every run. C1 changes no planning code. Receipts: runs/c1-gate2, runs/c1-gate3a, runs/c1-gate3b.

Review fixes, served (runs/c1r2-gate): the C1 binary before the fixes (eb79fbe4, 3c648fed3c) vs 9bc5e4b6 (a203fd1af0), same flags. Each server answered greedy and seeded (temperature 0.8, top_p 0.95, a seed a prompt) at c=1 (4 chats in turn) and at c=4 (8 chats, 4 at once), 24 replies of 400 tokens:

model startup line most running requeued idle census at stop reply md5s (24)
Gemma 4 31B identical 4 / 4 0 / 0 equal identical
Nemotron 3.5 Lightning identical 4 / 4 0 / 0 equal identical
Spark2.5 prompt cache 50.0 / 49.9 GiB* 4 / 4 0 / 0 equal identical

72 of 72 replies are hash-identical (reasoning and content hashed, every reply over 1400 characters). In each arm, the c=1 reply to a prompt also equals its c=4 reply, greedy and seeded. * This is the free memory read at load again; the A-B-B-A above showed the same spread on #2415's own binary.

Verification on the head

Head a203fd1af0, merge base #2415's af17f6c8fc:

  • test-kv-pool 80/80.
  • test test-golden: 699/699 steps, 8056 passed, 52 skipped.
  • test-cuda-host: 393/393 steps, 982 passed, 11 skipped.
  • Lane host api/lone/halt: 666/666.
  • test-kernel-contract, test-server-security, test-pull-security, fuzz-cortheon: green.
  • x86 (-Dtarget=x86_64-linux-gnu) check-native-cuda-host and compile-cuda-tests: green.
  • x86 host (8 cores, no GPU, native, -Dfixed-cpu): test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 728/728 steps, 9611 passed, 69 skipped; check-native-cuda-host compile-cuda-tests 16/16; zig fmt --check clean. test-host is not on this branch: it came to main after GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415's merge base 223da7659b, so it runs once the stack is rebased.
  • tools/pr_check.py: 0 errors.
  • zig fmt --check, git diff --check: clean.
  • Lean: 341 = 341, 0 new.
  • Planted controls on this tree: 12 of 12 red (the 8 above and the 4 review controls), and each restored file green. The four review tests also fail on 3c648fed3c itself.

Proposed CHANGELOG line (for you to place)

  • KV pool admission by owner class (Roadmap: one paged KV pool and a radix prompt cache for every family #2444 C1): Pool.reserve picks a lease's owner class once, inside the reservation (a resumed prefix's class first). A request is admitted only when its class holds its pages, and a request past a whole class is refused by name even while other streams run. One class behaves exactly as before.

For your two-GB10 pair

Please compare #2415 (af17f6c8fc) with this head under GLM TP=2, with TF_GLM_KV_SPLIT unset and set:

  • concurrency 1/4/8;
  • an oversized request (one class plus one page): refused at once with too_big_class while others run, also with every lane busy;
  • resume: a kept prefix keeps its class, and a cross-class adoption gives ResidueMismatch, not a panic;
  • cancel mid-stream;
  • the idle census line after drain, every class free + 0 of cap.

With the flag unset, token hashes and the startup line should be identical. We have one GB10, so GLM TP=2 was not run here.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied for C1 and for the planted controls behind every test. The admission logic reads well. When a family has no Admit.need, never and fitsClasses answer exactly as before. At one class, fitsNeed reduces to Pool.fits. A few things before it can go further:

  1. Scope. Against main, this diff carries all of GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415, plus a GLM-on-CUDA disk store for --learn-conversations that neither description mentions: native/cuda_glm_disk.zig, families/glm/cuda_disk_image.zig and cuda_disk_ranks.zig, the cuda_refusal.zig change that lets GLM take the flag, core/rows_select.zig:54-67, core/rows_read.zig:168-172 and docs/api.md. Which PR does the disk store belong to? Please give it its own PR, with its own description and resumed = fresh receipts, so C1 can be reviewed alone.
  2. Rebase. Ten engine files conflict with main for real. Three of the changes matter here. First, Admit moved to core/engine_admission.zig:4. Second, kv_pool.zig gained mid-stream retirement (kv pool: a window's pages go back once their readers are done, and sliding attention reads through page tables (#2444 P4, step 1) #3353), and its freeOrPend and settle push freed ids straight onto free/nfree (kv_pool_retire.zig:84-85 and :101-102). With per-class stacks, those pushes must go through push (kv_pool_classes.zig:71). If they don't, cfree[0] drifts from nfree even at one class, and take (kv_pool.zig:434) pops the wrong slot. A test that retires and settles at one class and at two would pin this. Third, takeJob now counts a refusal as prompt_too_large; please say whether too_big_class should count too. The CHANGELOG conflict is ours, so leave it.
  3. 600-line limit. native/cuda_kv_pool.zig comes to 602 lines, and that part applies to main as it is. core/lane_host.zig is already at 600 on main and gains a line. core/kv_pool.zig would land near 601 after the rebase.
  4. Default path. admit.refused (lane_host_admit.zig:26) runs on every takeJob for every family. It calls passed() on each queued job before it learns there is no Admit.need. Could it return null at once when the engine has no need hook, so other families do no extra work?
  5. Numbers. Your served rows compare against GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415's head, not main, and none of them is GLM. After the rebase, please post main-against-branch reply hashes from one machine for a few default families and for GLM with TF_GLM_KV_SPLIT unset. If GLM won't fit on one GB10, please say so. Please also post concurrent = solo and resumed = fresh for GLM with a kept prefix.

This also needs #2415 to land first.

  • Synthena

@jschmied

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. Point 1 first, as it decides the shape of the rest.

  1. Scope. The disk store is GLM-5.3-Flash on CUDA keeps conversation states on disk, every rank's part (--learn-conversations) #1411 (@wojo, "GLM-5.3-Flash on CUDA keeps conversation states on disk", f0a9651b6):
    the first 10 commits under this branch (047f58856..3dada70d0) are GLM-5.3-Flash on CUDA keeps conversation states on disk, every rank's part (--learn-conversations) #1411's, the next 9 (64e6fc490..af17f6c8f)
    are GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415's, and C1 is the top 2 (3c648fed3, a203fd1af). GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415 is stacked on GLM-5.3-Flash on CUDA keeps conversation states on disk, every rank's part (--learn-conversations) #1411 (its header fields moved
    into GLM-5.3-Flash on CUDA keeps conversation states on disk, every rank's part (--learn-conversations) #1411), and C1 needs GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415's owner classes, so the order is GLM-5.3-Flash on CUDA keeps conversation states on disk, every rank's part (--learn-conversations) #1411, GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415, then this. The body will say so.
    Once GLM-5.3-Flash on CUDA keeps conversation states on disk, every rank's part (--learn-conversations) #1411 and GLM on CUDA: the latent split's per-rank page book and owner (TF_GLM_KV_SPLIT, #1431 part 1; stacked on #1411) #2415 land, this diff is C1 alone.

2-5. These come with the rebase once #2415 lands, when this branch drops #1411's and #2415's commits:
the retire and settle pushes go through push, with a test that retires and settles at one class and at two;
the three files stay under 600 lines; admit.refused returns null at once when the engine has no Admit.need;
and the too_big_class count is answered in the body. Then main-against-branch reply hashes from one GB10 for a few
default families and for GLM with TF_GLM_KV_SPLIT unset (or a plain note if GLM doesn't fit), plus
concurrent = solo and resumed = fresh for GLM with a kept prefix.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. That identifies the disk store as #1411 and clarifies the #1411 → #2415 → C1 order, so no duplicate disk-store PR is needed. The other asks remain open as you noted: integrate retirement through the class-aware free path with one-/two-class tests, keep the no-hook admission path cheap, settle the refusal counter, and meet the file-size and current-main equality checks after the parents are ready. The existing #2415-relative receipts remain credited within that scope.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

On a203fd1a, zig build test-kv-pool -Doptimize=ReleaseSafe -Dcpu=apple_m1 -j5 --summary all passed 80/80 on M5 Max with Zig 0.17.0. The full trial merge into 9ba855b3 still conflicts. I isolated the pool and retirement changes in scratch to check the open owner-class question.

The regression reserves one page in its owner class, takes it, retires it at reader token 18, then settles 17 and 18 in order. Before 18 the page stays out of the free stack. At 18, the class should regain one free page and one promise. Using main's retirement module as-is, that last class-free assertion failed. Both freeOrPend and settle wrote directly to p.free[p.nfree] without restoring the class count. Calling owners.push(p, id) at both points made the regression pass for one class and for two classes, with the second case using class 1. The partial overlay ran 101/103 tests, with two budget/band failures still to resolve. This is evidence for the return path only. The full stack and GPU checks remain open.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked #4466 at 3d443e8f0, which carries #3665 and this PR. I reran the same suite on a local trial of that train plus main 1eed88bb0 and #4467 at 3f9742cf9. The train's only conflict was in the changelog, where I kept the current main version for the test.

zig build test-kv-pool test-kv-safety-host test-glm-ring-host \
  test-gradient-serving check-native-cuda-host -Dcpu=apple_m1 -j4 --summary all

Both runs passed all 30 steps and all 190 tests on M5 Max with Zig 0.17.0. The combined run passed the serving pins and compiled the Linux ARM64 CUDA native executable. The owner-class pool checks and GLM ring checks here use host fixtures.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I reran the checks on the new official train #4479 at 6ce450f2, which includes #3665 and #3676 in landing order. On M5 Max with Zig 0.17.0, all 45 build steps succeeded. 349 host tests passed with two skips, the serving pins passed, and both Linux ARM64 native CUDA and HIP targets compiled.

zig build test-kv-pool test-kv-safety-host test-glm-ring-host test-gradient-serving check-native-cuda-host test-qwen35-hip-host test-native-hip-host test-draft-hip-host check-native-hip-host -Dhip=true -Dcpu=apple_m1 -j4 --summary all

This is the exact published train with no scratch edits. The checks use host fixtures.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I reproduced both red Linux GLM KV-split tests on the current a15cf1ba trial into d21617008. The recording rig in cuda_regions_test.zig zeroes the layer and fills the index head count and width, but leaves the index geometry zeroed. That causes Geometry.check to return IndexShape before the intended launch assertions. Hosted Linux job

Setting only r.l.index.geom = .{}; in Rig.init passed all 26 filtered GLM KV-split tests on M5 Max with Zig 0.17.0. Before the change, the same filter passed 24 and failed those two. I registered the scratch target on the existing GLM host test root with filter GLM KV split:.

zig build test-review-glm-kv-split -Dhip=true -Dcpu=apple_m1 \
  -Doptimize=ReleaseSafe -j2 --summary all

The original trial separately passed 337 selected host tests with two skips and compiled both native CUDA and HIP. The one-line fixture adjustment leaves production code untouched. The head also trial-merges cleanly into 7d243251. Hosted reruns and device checks remain separate.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I independently checked fb13fdde6de158a11971ca982ee68d310c47b07f on an M5 Max with Zig 0.17.0. The current #2415 head, 5af6a50f8, is already in its history. The GLM region checks that previously failed with IndexShape now pass. On the published head, all 183 tests passed and the ARM64 Linux CUDA server compiled.

zig build test-kv-pool test-glm-regions-host test-glm-pages-host test-glm-snapshots-host test-glm-prompt-settings-host check-native-cuda-host -Dcpu=apple_m1 -Doptimize=safe -j3 --summary all

The trial merge into main 7fb9fc661 has one conflict, in zig/src/families/glm/cuda_env_test.zig. Keeping main's TF_GLM_INDEX_SPLIT entry alongside this stack's TF_GLM_KV_SPLIT entry resolved it locally. The trial passed 324 tests with three skips and compiled the ARM64 Linux CUDA and HIP servers.

zig build test-kv-pool test-glm-regions-host test-glm-pages-host test-glm-snapshots-host test-glm-prompt-settings-host test-env-defaults-host check-native-cuda-host check-native-hip-host -Dhip=true -Dcpu=apple_m1 -Doptimize=safe -j3 --summary all

I also ran zig build test-glm-rev25-host -Dcpu=apple_m1 -Doptimize=safe -j2 --summary all on the same conflict resolution against the preceding main e7aba1a74. All 30 strict environment and indexer tests passed, and the host emulator exited successfully. The two-GB10 serving comparison remains pending.

Igor Lessio - AIFLOW LABS

wojo added 13 commits November 23, 2026 17:44
…re each byte sits in its lease

The rows store's view of a GLM kept state, without the store: the words (format,
position, head rows, ring bases, KDA copy bits), the KDA prefix, each DSA layer's
latent rows, scales and whole pools by position, its rings and pools in progress
as the state's own, the head's caches at a whole verify window (rows past the
head's own read as zeros), then the tail. Copies run a page of the lease at a
time. Nothing is wired to --learn-conversations yet.
…state on disk

Rank 0's engine thread leases, fills, reads and seals each rank's copy through the follow link
(cuda_disk_ranks: blank, put, take, seal, prefixes). The store's image is rank 0's image followed by
each other rank's prefix, the one part a rank holds alone; the rest are the same bytes on every rank,
checked at start by the identity probe. A blank state is refused by restore until its seal.

A blank whose disk step fails on the link gives rank 0's lease back, and its id goes on the dropped
list, so the next step drops it on any rank the step reached; the id is not used again. An NCCL failure
there already ends every rank (the liveness lines), but a CUDA error in the step's launch or upload
returns to the disk read, which tries one shorter state and then prefills while the server goes on.
cuda_disk_ranks_test.zig runs the steps on host memory with a fake link: that failed blank, a blank state
refusing bytes past its words and front until sealed (DiskOrder), each BadStep a follower refuses before
its states or the link, and each other rank's shared bytes taken past its prefix and compared to rank 0's
(RanksDiffer, in ranks.same, which the probe calls). attach's refusals of the shared store and of more
ranks than prefix_buf holds (KvShareWithLearnConversations, TooManyRanks) have their own test in
cuda_glm_disk.zig. link and prefix_buf stay process-wide: the process serves one model.
With TF_GLM_KV_LIVE_HALF=1 a keep holds one KDA half and the disk image both, so GLM refuses
--learn-conversations with it by name at startup (cuda_refusal.zig); the test that pinned GLM refusing
--learn-conversations outright now pins that it takes the flag alone and refuses it beside live-half keeps.

Rank 0's link becomes the disk steps' link in `follow.Link.lead` (which also sets whether the other ranks begin
asleep), at TP only, and `Link.deinit` clears it, so cuda_native.zig stays at its 600 lines. cuda_disk_ranks_test.zig:
one rank leaves the steps local, two set the link, another link's deinit leaves it, its own clears it; the test fails
with the clear removed.
…sk state into that storage

A family whose kept states live in preallocated storage it reuses (GLM's snapshot pages on CUDA) and
cannot trim never had a disk read chosen: the selection counted its spare storage as fixed and its
kept states as not reclaimable, so no state ever fit. Such a family's room for a read is now its
spare storage plus what evicting unborrowed states frees, and a read is ready once the family says
its spare storage takes the state, as a keep's admission already asks. Families with trim, or
without reused storage, are unchanged.
…t, as before

The disk read's early admission for a family whose spare storage takes the state now applies only
to a family without trim, as the selection's capacity already does. A family with trim, such as
Flash Next's or Qwen3.8-27B's pools on Metal, makes room for a read by trimming its spare storage
and evicting, exactly as it did before, and a new test pins that its read stays within the budget
when its reuses answers yes.
…he state's rows

An index ring based at `base` holds the rows from `base` up to the state's position, and the image keeps
at most a ring's rows of each. The seal now checks the words' main base against the state's position and
the head's base against its rows, so an image whose words name a ring that starts past them, or too far
back to be held, is refused before the blank state is made whole.
…/O worker GLM's store uses

The write-behind gave GLM's store its own I/O worker, while the grid test wrote on the test's thread
(sync_writes). It now runs on each, drained by write.drain, so a worker path that loses the grid's
chunk starts fails the test.
…rn-conversations alone keeps its states

Since ashhart#1413 CUDA serves --spill-gib and --checkpoint-slots, and --learn-conversations admits GLM, so
--learn-conversations --spill-gib (or --checkpoint-slots) opened GLM and ignored the flag: its disk store
writes every rank's part between passes and stages nothing at eviction. GLM now refuses both by name.
Its store's spill stays off, since an eviction would gather on rank 0 mid-pass while the other ranks
wait in the gate's all-reduce. docs/api.md lists every CUDA family that keeps states on disk.
…he shared-store refusal names TF_KV_SHARE

- A kept state's device pages are read out with cuda.memory.download, which stages through the pinned buffer on an
  integrated GPU (ashhart#2103, ashhart#2289), as every other synchronous readback does; the copy back in stays a direct HtoD.
- The refusal beside share_pages names TF_KV_SHARE, the switch behind it since ashhart#2211, in its message and comment.
- The disk image test's driver answers cuCtxGetDevice and cuDeviceGetAttribute (a discrete card).
…e owner, and a read refuses another by name

The image's words gain three: the ranks that wrote it, its layout and the rank that owns its latent rows.
Every image is unsplit so far (every rank holds every row): it records this server's world, layout 0 and
no owner. A read refuses words of another world (DiskWorld) or another layout, or an owner its layout
does not have (DiskLayout), before the blank state is sealed. The words are 72 bytes, the seal step 18
words. ashhart#1431's split states fill the layout and owner without another format.

A disk read forgets a state's file refused as DiskWorld or DiskLayout after one recall, as it does one
refused as DiskWords (rows_read.refused); rows_refusal_test.zig's cases include both.
… attach, so a long state is staged whole

cuda_glm_disk.attach opened the store with rows.Rows.open, which keeps the 1 GiB default staging permit and
skips the floor rows.attach applies (the longest state's charge, within the RAM store's budget). At about
18.5 KiB a token that stopped every state past roughly 55K tokens: `imprint: saving 124928 tokens skipped
(StagingFull)`, whatever --learn-gib said, and a long conversation was recomputed cold after a restart
(found by crystal8194 on ashhart#1411).

attach now goes through rows.attach, as Qwen 3.5 27B does, with `longest` the capacity's whole pools
(`image.longest`, the last position `parts` takes; rows.attach falls back to the default when pricing it
fails, so the position matters). Spill stays off and the slots unset, as before. The start-up line gains the
permit: "a save stages up to N MiB".

Tests:
- test-cuda-disk-open-host: GLM's own open over a store of 18,944-byte tokens. A 124,928-token state's charge
  is past the 1 GiB default and within the permit, which is the longest state's charge; with a RAM store too
  small to keep the state the permit stays the default. It fails with the floor gone (the permit is 1 GiB).
  It prices the permit a save's stage step asks; it does not write 2.3 GiB.
- The GLM set: `longest` is a position the store's parts take at capacities on and off a pool's edge, and the
  next pool past it is refused.
…id from one class, and one class is today's pool

A pool can hold W owner classes (Pool.initClasses, Layout.classes): page ids c, c + W, c + 2W ... form
class c, each on its own free stack, as DeepSeek's sessions pool books ids by residue (pg = local*W + r).
A lease names its class (Lease.owner) and every id it takes, adopts or shares is of that class; a promise
fails when its class lacks the pages, though another has them. The owner rule lives in one function:
roomiest, the class with the most available pages, the lowest on ties (ashhart#1313's). fitsAny answers as a
promise from it would. planClasses floors a plan's pages to a multiple of the classes and refuses a class
that holds less than one stream's window (ClassTooSmall); plan's error set is unchanged, and at one class
planClasses is plan for the same budget, the cache's slots and slots_only (ashhart#2358) included.

The class book lives in kv_pool_classes.zig (planClasses, the per-class counts, roomiest, fitsAny and the
stacks' push and pop, and the class tests' imports); kv_pool.zig keeps the fields and names them, and
promise and hold keep main's reclaim walk (ashhart#2528's chain) as it is: the class test comes after it. Above
one class, runs are refused (claimRun null, coverRun as cover), since a run spans every class, and so is
a reclaim store: joinReclaim returns OwnerClasses, since a store's eviction frees pages of any class and
a promise needs its own class's. Nothing joins one there today (GLM refuses TF_KV_SHARE with the split);
the refusal keeps it so.

One class is today's pool, id for id and in the same order: init is initClasses(..., 1), and a scripted
run of promise, cover, trim, finish, hold and release gives the trace main records (pinned by its hash).
kv_pool_trace_test.zig goes past that script on one class: 400 seeded steps on 32 pages through adopt,
share, drop, runs, reclaims and a shuffled stack, every operation taking effect, its store joining as
any store does (joinReclaim), its hash recorded on main's kv_pool.zig (ddd2df8, again on 9c9bf54,
and on f03e5aa, after ashhart#2528's chain).
…t one rank, without pages or with host pages

The switch for ashhart#1431's per-rank latent book: unset, 0 or off (the default) and 1 or on; any other value is
refused naming the choices. Every rank resolves it inside the watched start, after TF_KV_PAGES: one rank is
KvSplitNeedsRanks (checked first, since auto pages are off there), pages off or fp8 windows
KvSplitNeedsPages, TF_GLM_KV_HOST KvSplitOnHost, and TF_KV_SHARE KvSplitShare (the store's pages come from
any owner's class). The fingerprint carries it (layout 21), so ranks started with different values stop
with kv_split named. Nothing books by owner yet: this commit only reads, agrees and refuses.

Its rows: environment.zig checks the same four words as a glm row, when GLM's CUDA family opens on every
rank, so a typo never stops another family (docs/environment.md; cuda_env_test.zig), and profile.zig
registers it beside TF_GLM_KV_HOST for glm5_next, identical, 1 and on reported as set, evidence ashhart#2415,
since it changes how pages are booked and how many streams fit (docs/profiles.md).
…s lie in two regions, each with its own table

The pool's arena is the same bytes, laid out as two regions: every page's pooled keys first, a pooled
part apart, then every page's latent rows, a latent part apart. Both strides come from the weights (the
DSA layers and the head times a cache's part), so a thin model's pages are laid out alike. Each paged
sequence gets a second table after its first (State.ltable), and Caches a second (pkt): the latent
launches (lat_write, the dense and sparse chunks, and dsa_tokens' rows) take the latent table and stride,
the pooled-key launches (pool_keys, scores) the pooled table and stride. No kernel or launch is new.
attend refuses a pooled table without its own stride before it launches.

Every rank still holds every row, so the latent table holds the same ids: TF_KV_POISON fills both parts
of a page, and kept states copy the same bytes. Off, every launch argument, table write and fill is as
before.
wojo and others added 13 commits November 23, 2026 17:44
…wner's class, sent with begin and checked by every rank

With the switch on, the pool has an owner class a rank (Layout.classes = TF_GLM_WORLD). Rank 0 picks a
stream's owner when it opens, by the pool's rule (the class with the most available pages, the lowest on
ties), and takes every page from that class; admission asks whether that class holds the request. begin
carries the owner in its unused depth word, and every other rank checks each id is of it before it maps
anything (ResidueMismatch, or BadStep for an owner past the classes). The pool step carries the switch,
and a rank whose own differs refuses it (RankMismatch). Every rank refuses a pool whose class holds less
than one stream's window (ClassTooSmall), and the plan floors the pages to a multiple of the classes and
refuses such a class with its numbers; it plans from the budget main's plan builds, the cache's `slots`
and slots_only (ashhart#2358) included. A request longer than a class is refused by name, never requeued.

The lane cost cache keys its prices on the switch (keyShape's split word): under it the timing stream
books its pages from a class.

Every rank still holds every latent row, so the owner is bookkeeping only for now; the start-up line
says so, and the idle line counts each class. Off, there is one class: ids, admission, begin and the pool
step are as before.
…r classes, each prompt on one, the classes in turn

The check resolves the switch as serving does (cuda_start.splitting, refused by name at one rank) and,
with it on, makes an owner class a rank of two windows and a page over each. Each prompt's paged stream
and the stream that shuffles its pages open on the same class, k % W for prompt k, so every class serves
and its pages still come out of order (jumps counted by W). Every stream is compared with its twin on a
whole window, byte for byte, and every class must be idle after. Off, the check is as before.
…th regions of every leased page, once

A paged sequence on two regions (every page's pooled keys first, then every page's latent rows) and one
on interleaved pages, both on ten ids out of order, at a length whose latent rows and pooled keys reach
every page, with and without the MTP head. The split plan's paged pieces, counted on a map of the pages,
read every leased page in both regions, each row's bytes exactly once, and nothing else (no overlap, none
missed); the rows are placed from the geometry alone, not from the state's fields. With the same rows in
both layouts (every row on every rank), the split plan's bytes, in its order, equal the interleaved plan's
and so do the lengths. Both tests fail when the pooled parts step by the latent stride (x.ps) or the
latent parts by the pooled one. glm_snapshot_host.zig is at 600 lines, so the tests have their own file in
the same step.
…links, Header bytes and all, to a follower's loop

Rank 0 is a Leader on the pages' fake engine with a Link on host memory: Leader.pool and Leader.beginOn
encode through Link.send's put path (tf_glm_put_words run on the host, word for word) and a host NCCL
that keeps each broadcast. The pool step's 64 bytes carry the switch in flags, and begin's carry the
lease's owner in depth, with its ids after; off, both are byte for byte the headers main sends (flags 0,
depth 0). A second rank decodes them in follow itself, through Link.receive: its pool books an owner
class a rank, and slot 1 maps rank 0's ids under that owner. A begin whose owner on the wire is not its
ids' class is refused (ResidueMismatch) with nothing mapped, and a follower started without the switch
refuses the pool step (RankMismatch) and makes no pool.

Mutants, each alone: begin's depth left 0, the pool's flag dropped, the follower's begin calling map
(owner 0) and its pool step ignoring the flag; each fails at least one of the three tests. The pages'
split test's Fake is made pub for it.
…ions, each with a control given the other table

No launch is new, so glm_cuda_records.zig is unchanged; what the split changes is the geometry the eight
paged launches meet. contract_glm_pages.zig gains Geometry: in an arena of n pages, every page's pooled
keys first (2 x 32,768 bytes apart), then every page's latent rows (2 x 524,288 apart), the second cache
tested. With regions on, tf_glm_lat_write and tf_glm_chunks_16/32 (dense and sparse) take the latent
region's table and stride, tf_glm_dsa_tokens rows of that stride (1,024 a page, not 1,088), and
tf_glm_pool_keys and tf_glm_scores the pooled region's. Off, every argument and byte is as before.

contract_glm_regions.zig's Set holds the eight cases at either geometry; contract_tests.zig registers
the eight on two regions (2 lines), and Controls now holds both sets as controls (8 -> 16). A region
control gives each launch the other region's table, a second shuffle of the same pages that differs at
every entry (sparse chunks: token rows read through it), so its rows land on or come from other pages.
glm-index-check gains a paged case at the pooled stride (12 x 32,768, which tf_glm_index_scores' fast
path takes) with a latent table of its own for the token lists. docs/kernel-contract.md says so.

Host tests (test-glm-page-contract-host, 3 -> 5): sixteen controls, the last eight on two regions; a
disabled control in either set is refused; the region cases register apart from the interleaved ones at
the same served shapes as their controls; the regions fill the interleaved arena exactly, pooled keys
first, and off places everything as before; a region control's table differs at every entry (1-11
pages, 64 seeds each). Mutants, each caught: the fix-up of equal entries dropped, the latent rows placed
at the first cache, Set ignoring regions, the region controls not planted. The GPU gates (each case
green, each control red) are not run here; the contract's body cross-builds for aarch64-linux with
empty images (-Dfatbins, -Dcontract-controls), which is what analyzes it.
Main's retired pages now return through the owner classes' push, so a class's
free count stays true. With one class the stack is the same, id for id.
The rank agreement's layout goes to 23: main's 22 has draft_split and this
series adds kv_split. claimAt moves to kv_pool_classes.zig to keep kv_pool.zig
within 600 lines.
GLM's state arena moves to cuda_state_arena.zig, and one cache-default test
moves beside the other capacity tests. Neither changes behavior.
…sen once inside the reservation

Admit.need gives the pages a request needs a class (kv_classes.Need: one, or a spread for admission only). The
lane host tests it in its ledger beside the family's fits, and refuses a request past a whole class by name even
while other streams run. Gate.want takes a class, so a promise passes its class's test with the pool's bytes inside
it. Pool.reserve picks the owner (a resumed prefix's class, else the roomiest) inside the reservation, and a
failed one leaves the owner and every count as they were. No multi-class reclaim: joinReclaim still refuses
above one class. At one class every answer is ashhart#2415's: the ledger-counted pool trace hash is the one ashhart#2415 records.
…ane busy, no class hook refused, one notice a reservation

A request past a whole owner class is refused at takeJob before a lane is asked for (lane_host_admit.refused), not
only once one frees; requests waiting for a read or a prefix cut, or already cancelled, are left to their own path.
Ledger.ofPages refuses a pool of several classes without the class hook (NoClassHook) instead of reading the whole
pool as each class, and a resume's class the pool lacks never fits and is refused. Pool.reserve is one pool change:
a failed reservation notifies once, with the owner already restored. One class: no answer changes.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The class-aware owners.push return path is present in both immediate free and settlement, and the other runtime/accounting requests are answered. One explicitly requested regression is still missing.

kv_pool_window_test.zig:67-90 exercises retirement only through the ordinary one-class Pool.init; the owner-class tests do not retire and settle a page through Pool.initClasses. Please add the one-/two-class retire→settle case to kv_pool_class_test.zig; its existing registration already includes that file in test-kv-pool:

  • Reserve and take one page, retire it at reader token 18, then settle 17 and 18.
  • In the two-class case, use a page owned by class 1.
  • After settling 18, assert that its owner class has regained one free page and the lease has regained one promise; the next take must return that page from the same class.

That test pins the original bug where direct free-stack writes updated the total count without updating the owner class. The current production path looks corrected; this request is for the missing regression, not another runtime change.

  • Synthena

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Added the regression in 706ae4ba65, test only, on top of your ec4aea0f43.

kv_pool_class_test.zig:240, "a retired page settles back to its owner class", runs through Pool.initClasses at one and two classes. In the two-class case the lease is reserved in class 1. It reserves and takes one page, retires it at reader token 18, then settles 17 and 18. At 17 the class count, the lease's promise and pending are unchanged. At 18 the owner class has one more free page, the lease and the class each hold one promise again, and the per-class scan agrees. The next take returns the same id from the same class. A second retire, after 18 has settled, covers the immediate path through freeOrPend too.

Planted controls, each red, then green with the file restored (test-kv-pool 124/124):

  • the original bug in settle (a free-stack write that updates only the total): 6 tests fail, including the new one;
  • settle puts the page on class 0's stack and count, whatever its class: only the new test fails (expected 4, found 3 on the class count after settling 18);
  • the same class-blind write in freeOrPend: 7 fail, including the new one.

zig fmt --check, git diff --check and tools/pr_check.py (0 errors, lean 165 = 165) are clean. The full x86 CI set on 706ae4ba65: green (test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths 2455/2455 steps, 24966 passed, 157 skipped; check-native-cuda-host compile-cuda-tests 17/17; lean 0 new). No runtime change. The head still conflicts with current main in GLM disk files that came after your rebase; I have not rebased it.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The new regression covers one and two classes, including class 1, pending settlement and immediate return. It answers the remaining test request, and the runtime/accounting fixes are present.

We still need current-main default reply hashes and GLM split, concurrent/solo and resumed/fresh results. The older served table compares with the parent. We will handle the main integration, preserving its newer page-free and disk-transfer behavior.

  • Synthena

This branch has not been deployed

No deployments
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.

4 participants