Repository navigation
fix(inkling2): DFlash2 DraftContextWindow prefix cache, flat SWA I/O, and StateStore RAM cap - #408
Conversation
… and StateStore RAM cap - Add single-allocation flat SWA raw block I/O (read_block_all_layers_into, read/restore_sliding_raw_blocks_flat_for) eliminating 2,560 per-layer Vec<u8> allocations per parked anchor - Flatten Inkling2StateAnchor to zero-copy Arc<Vec<u8>> SWA + packed ShortConv host bytes + optional Span 2 4-bit DraftContextWindow (v2 fingerprint with in-memory DFlash2 context fusion weight hash) - Add hard StateStore RAM cap, 4-tier RAM trim, spill backoff, ColdKeyHold-protected in-place SSD upgrades & Global KV chain repair, unwritable-writer cleanup, and HostPoolCacheLimitGuard Governor budget registration - Wire live DraftContextWindow capture (lazy detach_snapshot, best-effort) and zero-target-reprefill prefix-cache restore across both scheduled and exclusive DFlash2 lanes, plus parked draft-ring cap & Governor reclaim (UnitKey::DraftContext, UnitKey::Extent, allocator freed_by_marks) - Gate cache-opted-out turns across prefill, decode, preemption, replay, and final-token materialization; include embedding weights in resident accounting and lazy-allocate LookupIndex
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Why
In long multi-turn Inkling-2-Mini coding-agent sessions with DFlash2 enabled, two root bugs compounded:
DraftContextWindow(sliding_window = 2048), while target SWA blocks older thanN - 1024are pruned.Inkling2StateStorehad no RAM cap, never dropped RAM after SSD write-behind, stored each parked anchor as2,560separateVec<u8>s (~45%mimallocbloat) +192separate 16 KB MetalShortConvbuffers, and was invisible toGovernor::charge().Architecture
flowchart LR subgraph Turn["Inkling-2-Mini Turn (Scheduled & Exclusive)"] LiveWin["Live DraftContextWindow (2.53 MiB 4-bit GPU ring)"] Snap["Lazy Boundary Snapshot (detach_snapshot, 0 host stall)"] LiveWin --> Snap end subgraph Store["Inkling2StateStore (RAM-capped + Governor-charged)"] Anchor["Flat Inkling2StateAnchor\n• Arc<Vec<u8>> SWA (0-copy)\n• Arc<Vec<u8>> ShortConv\n• Span 2 4-bit DraftContextWindow"] HostBudget["HostPoolCacheLimitGuard\n→ Governor stats.pools"] Anchor --> HostBudget end subgraph Disk["ColdCacheManager SSD Tier (v2 fingerprint)"] Blob["State Blob (Spans 0, 1, 2)\n+ 8-layer Global KV chain"] Hold["ColdKeyHold on in-place upgrades\n+ quota-floor eviction guard"] Blob --- Hold end Snap -->|"ClaimClass::Optional\ntry_reserve + publish"| Anchor Anchor -->|"4-tier RAM trim &\nwrite-behind / repair"| Blob Anchor -->|"Prefix hit\n(0 target re-prefill)"| LiveWin Blob -->|"SSD restore\n(0 target re-prefill)"| LiveWinSummary of Changes
Vec<u8>s per anchorVec<u8>moved zero-copy intoArc<Vec<u8>>(read_block_all_layers_into,read/restore_sliding_raw_blocks_flat_for)Arc<Vec<u8>>(~1.9 MiB)DraftContextWindowcapture (detach_snapshot), Span 2 persistence (v2fingerprint hashing loadedfc+hidden_normweights), and 0-target-reprefill restore across both scheduled & exclusive lanesram_cap((lanes * 4).clamp(8, 32)), 4-tier RAM trim,HostPoolCacheLimitGuardcharged intoGovernor::charge(), lifetime-tiedTrackedPackedBytes,ClaimClass::Optionaladmission,UnitKey::Extent+UnitKey::DraftContext+ allocatorfreed_by_marksreclaimColdKeyHoldfallback pinning,ColdCacheManagerquota-floor guard,MakeRoom::Refusein-place overwrites, independentRepairtracking +spill_backoff, unwritable-writer cleanupreuse_cache = falseleaked checkpoints/taps; missingpush_decode_limit& embedding weightsreuse_cache; wiredDecodeCacheLimitGuard; addedEmbedding::resident_weight_arrays(); lazy-allocatedLookupIndexand reset on parkVerification
cargo fmt --all -- --check: passcargo clippy -j 2 -p mlx-paged-attn -p mlx-core --lib --tests -- -D warnings: pass (0 warnings)cargo test -j 2 -p mlx-paged-attn --lib: 234 passed, 0 failedcargo test -j 2 -p mlx-core --lib models::inkling2: 152 passed, 0 failed (re-verifiedstate_disk34/34 post-rebase ontoorigin/main)cargo test -j 2 -p mlx-core --lib disk_tier: 36 passed, 0 failedcargo test -j 2 -p mlx-core --lib cache_limit: 33 passed, 0 failedcargo test -j 2 -p mlx-core --lib engine::governor: 42 passed, 0 failedcargo test -j 2 -p mlx-core --lib models::qwen3_5::dflash2_state: 66 passed, 0 failed