Skip to content

EXL3 Flash Next: host-resident K/V on the tier (6/8) - #1522

Open
BlivionIaG wants to merge 247 commits into
ashhart:mainfrom
BlivionIaG:pr/exl3-s7-host-tier
Open

BlivionIaG wants to merge 247 commits into
ashhart:mainfrom
BlivionIaG:pr/exl3-s7-host-tier

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Attach the shared host K/V tier to EXL3 Flash Next with separate indexer-plane views. The tier is off by default.

Current-head evidence

Two RTX 5060 Ti 16 GiB GPUs, CUDA 13.4.92, Zig 0.17.0; turboderp/Qwen3.8-Flash-Next-exl3 revision 69e33439ae950f17bcbe95c98f117d80f759ab6d.

  • Contracts: three host-tier kernels passed and all three planted controls were red. flashnext-pages passed with a retained exit status of 0. The host tier/pool suite passed 74/74. Page rerun, host suite.
  • Short-request tier-on/off cost and parity: TP1 and TP2, 16 expert lines/rank, 4096 MiB host tier, four requested streams, 128 outputs, greedy/seeded chat/code, off/on/on/off. Full token and output hashes matched across arms and TP widths; alone/serial checks passed. Tier streams reported zero flushed pages, so this does not measure eviction cost. Two observations per mode are not confidence intervals. TP2, TP1.
  • Long-prompt flush and restore: tier-beside-first, ~10k-token prompts, zero-cache reference, TP1 and TP2. Two distinct-content lanes were independently cold by observed zero cached-token counts; greedy and seeded plain restore hashes matched across cold/warm/branch/rewind, with 39 flushed pages per logged tier stream. TP2 four-request greedy and seeded variants also matched all 16 reference hashes. TP2 four-request greedy, seeded.
  • Limits: these runs use production tier-beside-first placement, not paged-all. TP2 at 32 expert lines/rank and 8192 MiB tier failed GPU allocation; the successful 16-line/4096 MiB geometry does not establish that the larger geometry fits. Four submitted requests are not proof of their exact execution overlap. Logged fetch counts are not PCIe throughput.

Diagnostic composite, not the PR head

a812682 plus an isolated copy of #1445's bounded head-scratch calculation passed TP1/TP2 two-lane drafted greedy and sampled restore, and TP2 four-request drafted greedy and sampled restore, with cache-disabled reference hashes and logged flush/fetch. This is not the integrated head or paged-all qualification. Four-request greedy, sampled.

Open

Repeat tier parity, cacheless-reference restore, contracts and one/four-stream TP1/TP2 cost on the integrated head, including paged-all and actual eviction/restore evidence. Maintain the distinction between shared-prefix cache reuse and independently cold lanes. The maintainer owns the main-versus-tier-off comparison, stack integration and CI. Main refuses this checkpoint, so it is not a runnable checkpoint-performance baseline on this box.

Earlier model-fidelity testing found 70/72 top-token matches against an independent reference; no tie waiver or perfect-equivalence claim. No checkpoint weights are distributed; the checkpoint uses Qwen Community License 1.0.

@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s7-host-tier branch 5 times, most recently from f6ec41c to 2af002f Compare October 29, 2026 07:33
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s7-host-tier branch 3 times, most recently from a0583b1 to 5809006 Compare October 29, 2026 13:04
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s7-host-tier branch 5 times, most recently from 05f8933 to 41de356 Compare November 1, 2026 14:34
@BlivionIaG
BlivionIaG marked this pull request as ready for review November 1, 2026 16:42
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s7-host-tier branch from 41de356 to 86f499c Compare November 2, 2026 04:28
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s7-host-tier branch from 86f499c to d7d6a59 Compare November 2, 2026 05:36
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s7-host-tier branch from d7d6a59 to f402526 Compare November 2, 2026 17:08
@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thanks @BlivionIaG. We reviewed this PR's own commit on #1501 independently. Off, it's main exactly: the same arena bytes and layout, and the one-plane kernels get pg.main() and the old 24-byte ABI. On, it moves whole pages of raw K/V both ways, uploads only flushed pages, keeps window pages pinned until flushed, and leases balance on every reserve, lend, cover and lane release. Three changes:

  1. A failed open leaks the pinned host store. The errdefer that destroys p.host is registered after Kernels.load (cuda_kv_lanes.zig:177-186). Register it right after Host.create.
  2. TF_FLASHNEXT_KV_HOST isn't limited to EXL3. The tier runs in Flash Next's shared paging and batch pass, so a non-EXL3 checkpoint at TP=2 unwraps a null in the exchange (kvhost.zig:71), and at TP=1 it runs unqualified. Refuse it before allocation unless the scratch format is EXL3, and take the rank from the collective.
  3. restored() swallows unpin and invalidate errors (kvtier.zig:219-229), so a page another lease has pinned keeps its pre-restore rows in the frame. Refuse before the copy, or fail.

With those, it lands together with #1501.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

TP2 sampled-drafted restore diagnostic on the explicitly non-public composite a8126820454c8dfe3e3c1af4608d8d2ab98259cc + bounded head-scratch overlay (same overlay and binary SHA-256 as prior diagnostic): two distinct ~10k-token lanes, temperature 1, seeds 1234/1235, 32 outputs, tier-beside-first, 4096 MiB tier, 8 slot frames, 8 GiB host prompt cache.

Both clients exited 0. Both initial tier-on lanes and all cache-disabled references reported 0 cached tokens. All eight cold/warm/branch/rewind full token hashes matched their same-build cacheless drafted reference; for this fixture they also matched the separate unmodified-head cacheless plain sampled reference (not a general sampled-draft identity claim). Both ranks logged seven tier streams each, 40 pages / 39 flushed and nonzero fetches. Server receipts show nonzero draft proposals and acceptance in every request. Full logs, reference/verification JSON, adapted client and build provenance retained.

Not an integrated-head, four-stream-drafted or paged-all qualification.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Matching TP1 sampled-drafted restore diagnostic passed on the explicitly non-public composite a8126820454c8dfe3e3c1af4608d8d2ab98259cc + bounded head-scratch overlay (same overlay and binary hashes as the TP2 diagnostic). Two distinct ~10k-token lanes, temperature 1, seeds 1234/1235, 32 outputs, tier-beside-first, 4096 MiB tier, 8 slot frames, 8 GiB host prompt cache.

Both clients exited 0. Both initial tier-on lanes and all cacheless references reported 0 cached tokens. All eight cold/warm/branch/rewind full token hashes matched the corresponding same-build cacheless drafted reference and the separate TP2 drafted reference; in this fixture they also matched the separately run unmodified-head cacheless plain sampled reference, not a general sampled-draft identity claim. The tier logged four streams, each 40 pages / 39 flushed and nonzero fetches; every request recorded nonzero draft proposals and acceptance. Raw logs, JSON, client and build provenance retained.

This is not integrated-head, four-stream-drafted or paged-all qualification.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Four-request TP2 drafted greedy restore diagnostic passed on the explicitly non-public composite a8126820454c8dfe3e3c1af4608d8d2ab98259cc + bounded head-scratch overlay (same overlay/binary hashes as the prior diagnostic). Four distinct ~10k-token contents submitted together, 32 outputs, parallel 5, tier-beside-first, 16 expert lines/rank, 4096 MiB tier, 8 slot frames and 8 GiB host prompt cache.

Both clients exited 0. Every initial tier-on lane and all cacheless references reported 0 cached tokens. All 16 cold/warm/branch/rewind full token hashes matched both their same-build cacheless drafted references and the separate unmodified-head cacheless plain references. Both ranks logged 15 tier streams each, all 40 pages / 39 flushed with nonzero fetches. Server receipts show nonzero draft proposals and acceptances in all 16 requests. Submitting four together is not an independent measurement of their exact execution overlap. Raw logs, JSON, adapted client and build provenance retained.

Not integrated-head, sampled-four-drafted or paged-all qualification.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Four-request TP2 sampled-drafted restore diagnostic also passed on the explicitly non-public composite a8126820454c8dfe3e3c1af4608d8d2ab98259cc + bounded head-scratch overlay (same overlay/binary hashes as prior). Four distinct ~10k-token contents submitted together, temperature 1, seeds 1234–1237, 32 outputs, parallel 5, tier-beside-first, 16 expert lines/rank, 4096 MiB tier, 8 slot frames and 8 GiB host prompt cache.

Both clients exited 0. Every initial tier-on lane and all cacheless references reported 0 cached tokens. All 16 cold/warm/branch/rewind full token hashes matched their same-build cacheless drafted references; for this fixture they also matched the separate unmodified-head cacheless plain sampled references, not a general sampled-draft identity claim. Both ranks logged 15 tier streams each, all 40 pages / 39 flushed and nonzero fetches. Server receipts show nonzero draft proposals and acceptances in all 16 requests. Four simultaneous submissions are not an independent measurement of exact execution overlap. Raw logs, JSON, adapted client and build provenance retained.

Not integrated-head or paged-all qualification.

@AIFlowML

Copy link
Copy Markdown
Contributor

Public head a8126820 passed 325/325 on M5 Max with Zig 0.17.0 using zig build test-flashnext-exl3-host test-kv-pool test-kv-safety-host -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j5 --summary all. The trial merge against 6a8faeed reported 18 conflicts.

One check to carry into the stack integration with #1501 is whether Tier.canFinish skips retired logical slots. In scratch, I added a host unit test in zig/src/core/kv_tier.zig that initializes a one-frame tier, appends none to an empty lease's pages.ids, and calls canFinish. With zig build test-kv-pool -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j5 --summary all, the test panicked at t.dirty[id] with index 4294967295. Adding id != none before the indexed reads made the same command pass 100/100.

That fixture models the retired-slot state expected from the parent change. Please carry the sentinel check into the resolved stack and keep the sampled TP2 restore rerun tied to the integrated SHA. My results cover the host path.

Igor Lessio - AIFLOW LABS

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the missing #1501 guard on published a8126820. A scratch regression puts the retired marker kt.none into a one-page lease table, calls Tier.canFinish, then restores the owned page before teardown. The published implementation aborted while indexing dirty[4294967295].

The exact parent fix 70dc4972 applied cleanly onto this child without edits. With the same regression present, all 100 pool tests and all 226 Flash Next EXL3 and KV safety checks passed on M5 Max with Zig 0.17.0.

zig build test-kv-pool -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all
zig build test-flashnext-exl3-host test-kv-safety-host \
  -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all

The published child still has 23 conflict paths against main d21617008. Keep the sentinel guard when restacking the parent. The composite device diagnostics remain separate.

Igor Lessio - AIFLOW LABS

Avoid indexing tier state with the pool sentinel left by a retired page.
Keep main's nemotron chunked-prefill shape and the strict environment rows: the chunk-solo row takes 0 (off) and a real keeps main's untrimmed text. The EXL3 receipts cover the pending launches only, and the prompt rows keep 13.3's numbers, so the tests assert that. resumeKept keeps anytype; the host-tier test takes the lane type as a parameter.
…p graphs

Main's 630eeda removed the eager guard and tests the graphs with a collective attached; the merge kept the older guard. Adopt main's runPiece and runGroup conditions.
The merge kept both the branch's reuse() call and main's resumeKept() calls, so a rank restore ran twice and the second ack timed out into poison(). Keep main's ordering and fold the branch's refusal warnings into resumeKept.
ArrayList.toOwnedSlice remaps in place when it can, so the pack reader's allocation count varied with allocator state and checkAllAllocationFailures reported NondeterministicMemoryUsage. Duplicate the slice so the count is fixed.
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Thanks @AIFlowML for the #1501 guard check; it is carried here too (kv_tier.zig, test in kv_tier_test.zig). Merging main into this branch also surfaced three things I fixed in the merge resolution (none by changing an expectation):

  • cuda_lanes_restore_test (3 tests aborting): the merge kept both restore paths, so a kept prompt state was restored twice and the second restore waited for an ack that was already consumed. Main's resumeKept ordering is kept; the older reuse() call is gone and its two refusal warnings moved into resumeKept.
  • cuda_mtp_graphs_test (2 failing): the merge kept an older eager guard (or e.collective != null) that reverted main's graph-capture rule; main's conditions are back in cuda_mtp_pieces.zig.
  • test-load-prefetch-host flake: checkpoint_read_ahead allocates its span slice exactly, so the allocation count no longer depends on remap (same fix as KV pool: host tier for the core pool (5/8) #1501).
    Also: the zig job's lean step found environment.zig and environment_test.zig at 602 lines after main's newest rows (cap 600), and test-gradient-serving flagged three pinned flashnext CUDA sources this branch changed (cuda_lanes.zig, cuda_prompt_wt.zig, cuda_rank_engine.zig); their three rows in gradient-serving.tsv are re-pinned (pocket-serving-approved.tsv is untouched).

Head f86fbcb685 (contains main at 6e44558d72). Local: test-cuda-host 8790 of 8840 (50 skipped, 0 failed) on the previous head, then the focused set (test-gradient-serving test-qwen-serving-host test-glm-pdl-scan test-kv-pool test-kv-safety-host test-flashnext-exl3-host test-flashnext-rank-graphs-host test-load-prefetch-host) 442 of 442, test-kernel-contract test-server-security test-pull-security 383 of 383; lean 0 new; pr_check 0 errors. Not run: device receipts (no GPU in this pass). CI on this head was still running when I posted.

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @BlivionIaG. Two smaller fixes are needed before this can land.

The lockstep digest of the host KV tier covers the mapping, generations, LRU order, pins, holders and promises, but not which pages are dirty. Two ranks with different unflushed writes can report equal digests. Please include the dirty state.

Also, if a later lane's index-table allocation or lane-selection setup fails while the host-tier lanes are created, the current lane's index table and the earlier lanes' index tables and lane-selection buffers are not released. Please free all three on that error path, as normal teardown does.

  • Synthena

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Both fixes are in on cdbf1c562b.

  1. The lockstep digest now covers the dirty pages (h.update(sliceAsBytes(t.dirty)) in core/kv_tier.zig), with kv_tier_digest_test.zig proving equal digests while both ranks flushed, a difference as soon as one rank holds an unflushed page it cannot evict, and equality again after both sync (this branch carries its own kv_tier.zig, so it needed the same change as KV pool: host tier for the core pool (5/8) #1501).
  2. A failed lane build now frees what it made: buildLanes frees the failing lane and every lane before it (cache, index table, selection), and a refusal after the lanes exist frees all of them; freeLane is the single teardown, shared with deinit. The new test in cuda_kv_init_test.zig builds three host-tier lanes on the fault-injecting driver, refuses each allocation in turn, and asserts the device and host allocation counts return to the baseline. The old error path fails it (expected 1, found 2); the new one passes.

While merging current main I moved the EXL3 rows out of the central settings table into zig/src/platform/environment_exl3.zig (table is own ++ exl3.rules, cases tested from environment_exl3_test.zig). That keeps environment.zig (596), environment_test.zig (564) and cuda_kv_lanes.zig (599) under 600 lines with lean at 0 new, and docs/environment.md keeps one row per setting and now documents TF_FLASHNEXT_KV_HOST, _KV_FRAMES and _KV_SLOTS.

test-environment-host, test-kv-pool and test-kv-safety-host pass locally; tools/pr_check.py --base ea37382cb1 --pr 1522 reports 0 errors and 0 warnings. CI is queued on the new head.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @BlivionIaG. Both are fixed on cdbf1c562b:

  • Digest: the host tier's lockstep digest hashes the dirty flags, with the same three-step test as KV pool: host tier for the core pool (5/8) #1501 (equal after both flush, different while one holds an unflushed page, equal again after both sync).
  • Lane setup: buildLanes frees the failing lane and every lane before it, a refusal after all lanes exist frees them all after the stream drains, and freeLane is the one teardown shared with deinit. The new test refuses each allocation in turn and checks the counts return to where they started.

That's everything from our last note. The stack still lands in order, and the next step there is ours.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @BlivionIaG. Both requests from our last review are fixed: the digest includes which pages are dirty, and lane setup releases the failing lane and earlier lanes through the shared teardown. The new tests cover dirty-page differences and device allocation failures across three lanes.

The stack remains held for ordered integration and the integrated-head tier-on/off, eviction and restore checks, including paged-all. The older composite diagnostics remain separate evidence. Integration stays on our side; there is no further change requested for those two fixes.

  • Synthena

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Merged upstream/main 4c79cfe346. Main had landed the base host tier and Flash Next's config-driven top-k and shared width, so the PR is adapted to both: main's host-tier comments and this PR's code, main's digest test kept (the duplicate dropped), and the scratch allocation sized from the config's slot count and shared expert width. EXL3 code assumes top-10, so the config now refuses another num_experts_per_tok for EXL3 by name, as it does for MLX. Head 5fe7f0d8b0; fmt, lean and pr_check 0/0 clean; on the Mac test-kv-pool, test-kv-safety-host, test-kv-merge-host, test-flashnext-host, test-flashnext-exl3-host, test-exl3-cuda-host, test-cuda-host and test-gradient-serving pass. Not run: the CUDA kernels, the device contracts and the served TP1/TP2 tier parity (they need NVIDIA GPUs).

This branch adds f64 to the contract's Accum. The Inkling 2 glue and SenseNova mHC Metal fixtures and the Inkling 2 modelopt CUDA fixture came from main with exhaustive switches over it; f64 maps to their unrounded none, as rows.zig and rounding_bound.zig map it.
A merge of main took main's info(gpu) call, while this branch keeps info in runtime_tests.zig, so tf-cuda-test did not compile (zig build compile-cuda-tests).
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

CI on 5fe7f0d8b0: zig-macos-dev-tools failed because this branch adds f64 to the contract's Accum, and main's new metal_inkling2_glue.zig and metal_sensenova_mhc.zig switch over it exhaustively. f94dbad384 maps f64 to their unrounded none, as rows.zig does, and does the same in main's CUDA contract_inkling2_modelopt.zig; zig build dev-tools -Doptimize=Debug passes locally. 7790eac99a fixes tf-cuda-test's info call, which an earlier merge of main had broken; zig build compile-cuda-tests -Dtarget=x86_64-linux-gnu now compiles. zig-windows looks flaky: its only failure was a 10-minute timeout in the Ling cpu_forward_test with no assertion failure; this branch touches no Ling code, and the test passed on the previous head (run 45364096988). The new push reruns it.

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.

3 participants