Repository navigation
Inkling 2: window-bounded KV for the sliding-window visits (1/4, SparkInkling 0.5.1 engine) - #430
Conversation
A sliding-window layer reads only its last `window` keys, yet the paged cache gave every layer a row per token of context. `new_windowed` keeps the plan's layers in pools of their own, a few blocks per live sequence, at a local block the primary block maps to (a device map the kernels read). A local block follows its primary block, so a shared prefix shares its window rows; a freed primary block drops them. Holders keep a mapping alive: live sequences hold what their next forward reads (`window_hold` / `window_release`), snapshots pin the window they resume from (with a primary ref), pins go first under pressure, and an exhausted pool is a `KV cache exhausted` refusal. A released local block is lent on another stream only after an event recorded on the releasing stream. Window layers keep unpooled entries in the primary list, so primary-indexed loops skip them; `poison_block` moves to zero_impl.rs beside the zeroing it mirrors. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 790c09b)
Inkling 2 Mini's 40 sliding-window visits (1,024 tokens) held a KV row for every token: 192 KiB a token over 48 visits. They now take the window pool, so context costs the 8 global visits' 32 KiB a token. - factory: Inkling builds a windowed cache sized for every live sequence's window and step, one forward's new rows and up to 8-32 snapshot pins; the rest of the budget buys primary blocks. High-speed swap, the NVMe disk tier, multi-rank and GLM plans keep full pools. - model: a sequence holds the window its next forward reads, from the 32-key tile holding its first row's first key (where the prefill kernels start), through its last row. Holds are taken last in both reservations, trimmed after each prefill chunk and released before the table shrinks. A rejected draft never moves the floor. Rows below a resume point must still be mapped, so no zeroed block stands in for rows that exist; a snapshot whose window is gone is declined and the prefill recomputes. Snapshot aux collection queues a pin, applied under the cache lock. Swap-resume is off with a window. - layer: visit 0 maps the rows' slots and block tables through the window map (`inkling2_window_meta`, captured in decode graphs); window visits write and read through them. Attention kernels are unchanged and read the same rows at the same positions in the same order. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit c4b3d64)
A long prompt snapshots every 4,096 tokens, and a resume needs its snapshot's window rows. One pin per live sequence kept only the newest eight, so a second session's long prompt evicted the first one's resume points (seen on one GB10: a 607K prompt declined the 180K prompt's shared snapshot at 69,640 and recomputed it). Pins now take up to an eighth of the KV budget (at least 8), and a resume that adopts a pinned window moves it to the back of the eviction order. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit b83832a)
|
Holding this as a draft: I found a bug in the window-bounded KV it carries. Two concurrent prompts of about 20K tokens each, on one DGX Spark (Inkling 2 Mini, Spark mode, 8 sequences of up to 1,048,576 tokens, 8,192-token prefill chunks), both fail. Typical error: I'll push the fix to this branch with a CPU test that interleaves two chunked prefills, and mark it ready again. 🤖 Generated with Claude Code |
Two or more long prompts prefilling together failed with "KV window: window rows of logical blocks [...] are gone" (HTTP 500, or one token then an error). Their later chunks ran through the batched prefill step, which reserved blocks with ensure_blocks_through_prefill and never took the window holds, so those chunks wrote no sliding-window KV and the next step found it missing. The mixed decode+prefill step, the whole-prompt prefill (a preempted request's resume) and the two-phase prefill reserved the same way. One-chunk prompts take the single path, which holds its rows, so they passed. - ensure_prefill_blocks reserves a prefill forward's blocks and window rows together; every path that does not vote uses it, and a source test keeps direct ensure_blocks_through_prefill calls out of model code. - The batched, kernel-batched and mixed steps trim each sequence's window after its chunk, so the pool holds one forward's rows at a time as it is sized to. - With window-bounded KV a whole-prompt prefill runs as chunks, the two-phase prefill falls back to chunks, and scoring is refused (its streams would hold whole prompts' windows). No effect without a window plan: the hold and trim return at once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Fixed in dca1509, and this PR is ready again. Cause. When two or more prompts are mid-prefill, the scheduler runs their later chunks through the batched prefill step. That step reserved blocks with Fix.
Checks.
🤖 Generated with Claude Code |
AzeezIsh
left a comment
There was a problem hiding this comment.
@data-angel Gated dca1509e0 against its base main 9f4fd773f: one GB10 (sparky jobs 208, 209) and one Strix Halo (DevLab A/B). Both binaries were built from fresh worktrees at the exact commits. It holds up, so I'm merging it. One observation for later is at the end.
Exact where it should be (GB10, base vs PR)
| check | result |
|---|---|
| Inkling Strict, plain: greedy C1 / C8 | 8/8 · 8/8 identical |
| Inkling Strict + incoai DFlash2 (0.5.1 strict draft env): greedy C1 / C8, vs plain base | 8/8 · 8/8 identical, base and PR |
| Inkling Spark + DFlash2: greedy C1 / C8 | 8/8 · 8/8 identical |
| SparkInkling 0.5.1 default profile (8 × 1,048,576, 8,192-token chunks) + DFlash2, PR: greedy C1 vs plain base | 8/8 identical |
| 4 × ~25K-token prompts at once, prefix cache off: cold serial answers | 4/4 identical, twice (job 209) |
| 4 × ~25K at once, with DFlash2 (Strict and Spark): concurrent answers base vs PR | 4/4 · 4/4 |
| Qwen3.8-27B QAD exact profile: lp_dump (26,912 tokens), greedy C1 / C8 | max|Δ| 0.0000 · 8/8 · 8/8 |
Concurrent answers without the drafter differ from run to run on main itself: base vs base was 2/4 identical in job 209, PR vs PR 4/4. Batched prefill timing on main explains it, not this PR.
Capacity (KV pool, max tokens, same budget)
| config | base | PR |
|---|---|---|
| Strict, 0.80, 131K max seq | 404,704 | 2,069,536 |
| 0.5.1 default profile (Strict + DFlash2) | 378,000 | 1,906,640 |
| Spark + DFlash2, 0.80 | 364,096 | 1,854,192 |
| Strix Halo Spark, 0.80 (A/B harness) | 298,336 | 1,501,008 |
Your repro list and long context (PR, 0.5.1 default profile): 2×20K, 4×20K, 8×20K and 2×60K at once (prompts of ~25K and ~75K tokens) all returned HTTP 200 with full-length answers. One 624,810-token prompt was answered correctly, which base can't hold at this profile. Under pressure I ran 8 × ~123K at once into a 335,808-token pool (0.35): all 8 were served (admission queued them, nothing preempted). 0 ERROR/panic lines in every arm.
Also clean (PR): tools 14/14 in every arm; quality probe arithmetic 40/40; image 3/3; cachehit warm == cold 6/6 in every arm; cross-contamination 8/8 identical, 0 contaminated. Decode is unchanged (sq_bench Strict C1 36.1 / 36.1 tok/s, C8 110.9 / 110.7). Cold 41K-token prefill was 3,437 / 3,458 tok/s on base and 3,334 / 3,390 on the PR, about 2.5% slower on 2 reps each. That's within reach of noise, so I'm noting it, not claiming it.
Strix Halo (DevLab run 46134953448, harness inkling_ab_gate.sh, base built on the same runner): the strix-hip build passes, and the window is on there too. lp_dump is identical (max|Δ| 0 over 19,952 tokens), NLL ties 32/32, Strict greedy 8/8, decode unchanged (Spark C1 42.5 → 42.8, C8 64.7 → 66.0), 0 hipError lines. Spark greedy at C4 was 3/8, but a main-vs-main control on the same harness (run 46140800913) gives 2/8 Spark and 6/8 Strict. So C4 text on that harness isn't stable run to run, and the 3/8 says nothing about this PR.
CI: every workspace job passes. The env budget, cargo deny and the PR benchmark gate are red on main too.
Observation, not blocking: one prefix-cache resume that base served was declined on the PR (job 208 Strict arm, after a 2 × ~25K concurrent phase):
prefix snapshot at 24992 declined: KV window: window rows of logical blocks [1536..1561] below position 24992 are gone
Prefix cache hit: 25008 tokens (1563 blocks) but no SSM snapshot — recomputing all KV
The missing rows start exactly at token 24,576, a chunk start, and the rows below it were still mapped. So the pin for the 24,992 snapshot looks evicted (or never taken) while an older pin survived. The answer is still right because it recomputes, but it costs a re-prefill (8.6 s vs 2.0 s here). Hit/recompute counts otherwise match base in every arm. Worth a look when you next touch the pins.
The stack: #431–#433 carry this PR's first three commits but not dca1509e0. Their branches merge cleanly onto main with this PR, and none adds a direct ensure_blocks_through_prefill call, so no rebase is needed. I'm gating each one as the merge commit main will get, and those runs are in progress.
sparky nightq 208 / 209 · base 9f4fd773f ink 3eddad86 q27 ed47238d · PR dca1509e0 ink 27eaee9a q27 a592dd85 · DevLab 46134953448 / 46140800913 · 2026-11-28
🤖 Generated with Claude Code
Change 1 of 4 porting the SparkInkling 0.5.1 engine to
main(9f4fd773f), one change per PR, stacked linearly.This PR is three commits on
main; the next PR is based on this one's branch.What
Inkling 2 Mini's 40 sliding-window visits (1,024-token window) held a KV row for every token of context: 192 KiB a
token over the 48 visits. They now keep KV only for their window, so context costs the 8 global visits' 32 KiB a
token.
spark-runtime(790c09b07):PagedKvCache::new_windowedkeeps a plan's sliding-window layers in pools of theirown, a few blocks per live sequence, at a local block the primary block maps to (a device map the kernels read).
A local block follows its primary block, so a shared prefix shares its window rows and a freed primary block drops
them. Live sequences hold what their next forward reads (
window_hold/window_release), snapshots pin thewindow they resume from, pins go first under pressure, and an exhausted pool is a
KV cache exhaustedrefusal.A released local block is lent on another stream only after an event recorded on the releasing stream.
poison_blockmoves tozero_impl.rsbeside the zeroing it mirrors.c4b3d64ee): the factory builds the windowed cache for Inkling (high-speed swap, the NVMe disk tier,multi-rank and GLM plans keep full pools). Visit 0 maps the rows' slots and block tables through the window map
(
inkling2_window_meta, captured in decode graphs); window visits write and read through them. The attentionkernels are unchanged and read the same rows at the same positions in the same order. A snapshot whose window is
gone is declined and the prefill recomputes; swap-resume is off with a window.
b83832a7e): pins take up to an eighth of the KV budget (at least 8), and a resume that adopts apinned window moves it to the back of the eviction order, so a second session's long prompt no longer evicts the
first one's resume points.
Port conflict:
mainmovedroute/kv_writefrominkling2/glue.rstoglue/route.rs;window_metastays inglue.rs(479 lines).Observed (the fork's engine, not this branch; see "Where the numbers come from" below): SparkInkling 0.5.1's
default profile serves 8 sequences of up to 1,048,576 tokens at 0.80 of GPU memory on one DGX Spark, with KV pools
of 1,909,536 tokens (Strict weights) and 1,790,944 (Spark weights); its
saverprofile (0.50) holds 882,992 and741,520.
The series
The engine of SparkInkling 0.5.1
(
Enntity/atlasinkling2/rc-0.5.1-20261126ata4dbba378), ported ontomain(9f4fd773f) as one changeper PR, stacked linearly:
The DFlash2 drafter commits that 0.5.0 carried are already on
main. Two things are not in this series:the fork's
ATLAS_PREFILL_BUSY_TOKENSchunk cap (#4 here makes it unnecessary, and the fork removed it, so it isnot proposed and no PR adds an
ATLAS_*name) and the opt-in LoopCD (--loopcd), which is not proposed for now.After #4, the engine files these commits touch equal
a4dbba378's except formain's own changes underneaththem (
glue.rs'sroute/kv_writenow inglue/route.rs;weights.rs,serve_load.rs),rustfmt, code movedas is to keep files under the 500-line cap (#2, #3), and the AMD flash prefill kept beside the new gb10 kernel (#3).
Where the numbers come from. Every GPU number below was measured on the fork's engine on its older base
(before #413 and #426), not on these branches: SparkModelBench
293a44f(RigMark protocol 1.3.0, RigMark Qualityv0.0.2,
reasoning_effort: low) on one DGX Spark, SparkInkling 0.5.1's default profile, published with receipts inresults/2026-11-27-rc-0.5.1.
No GPU has run these rebased branches.
Test plan
cargo fmt --all -- --check;cargo clippy -p spark-runtime -p spark-model -p spark-server --tests -- -D warnings;cargo test --release -p spark-runtime -p spark-model -p spark-server(spark-model 2,524, spark-runtime 608 and spark-server 3,258 passed; the same five spark-server tests fail onmainin this container (three need a.gitcheckout, two read the disk's free space)); the 500-line cap;check_spdx.py,check_kernel_shadows.pyATLAS_*name (check_env_budget.pyreads 1,141 onmainand on this branch)spark benchmark run <gate> --pull-request-gategates and the strix-hip build: left to the maintainers (this branch touches no strix-hip file;inkling2_misc.cu, which it extends withinkling2_window_meta, is symlinked there)Authorship
AI-authored: Claude (Opus 5.5) in Claude Code, directed and reviewed by a human; no hand-written code.
CLA
🤖 Generated with Claude Code