Skip to content

Add experimental selective KV retention and native-model qualification - #1412

Draft
Gajesh2007 wants to merge 3 commits into
masterfrom
codex/selective-kv-retention
Draft

Gajesh2007 wants to merge 3 commits into
masterfrom
codex/selective-kv-retention

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Full-attention KV keeps growing during decode. This adds an explicit singleton benchmark mode that retains the native recent window and reduces older full-attention history. The provider rejects serving activation: qualification exposed a reproducible GPT completion regression, and temporary scoring/compaction allocations still need serving ownership.

Depends on mlx-swift-lm #295, pinned at verified signed commit 46477f0. DARKBLOOM_CBV2_SELECTIVE_KV=half requires an explicit contiguous backend, benchmark construction, one concurrent request, and MTP off. MiMo and other model families are excluded. All exact prefix-cache paths are fenced; existing admission bounds remain conservative.

The policy preserves dense prefill, native K/V dtype, original absolute positions, the first four tokens, at least the latest 512 tokens, and native sliding windows. It selects half of older full history in 16-token chunks using bounded recent-query attention and evenly spaced coverage. The dedicated refactor removed the redundant gather-to-new-row copy: one owned gather includes bounded spare capacity that remains unreachable until overwritten.

Before

flowchart LR
  I["Benchmark input"] --> F["Factory: native contiguous rows"]
  F --> D["Dense prefill and full-history decode"]
  D --> R["Scores and timing"]
  classDef input fill:#dbeafe,color:#172554,stroke:#2563eb
  classDef exact fill:#dcfce7,color:#14532d,stroke:#16a34a
  class I,R input
  class F,D exact
Loading

After

flowchart LR
  I["Benchmark input + explicit half policy"] --> G{"Allowed experiment scope?"}
  G -->|"yes"| F["Factory: selective full rows + native windows"]
  F --> D["Dense prefill; selected-history decode"]
  D --> R["Scores, actual pruning, allocator observations"]
  G -->|"no"| X["Refuse incompatible activation"]
  F -.-> C["Fence every prefix cache; require MTP off"]
  classDef input fill:#dbeafe,color:#172554,stroke:#2563eb
  classDef candidate fill:#fef3c7,color:#78350f,stroke:#d97706
  classDef fence fill:#fee2e2,color:#7f1d1d,stroke:#dc2626
  class I,R input
  class G,F,D candidate
  class X,C fence
Loading

Measured qualification:

  • Two teacher-forced pilots retain about 52–53% of full-attention storage with matching supplied continuation top-1 IDs. Dense prefill still determines the allocation peak.
  • Frozen-binary 4K/32K generation: GPT answers/tools pass 12/12 natively versus 11/12 with retention; Gemma passes 8/12 in both modes, with all 14 generated token arrays identical. Gemma's four native arithmetic/code errors remain visible.
  • The GPT failure reproduces in a separate unchanged-cap trial: six native observations answer in 164 tokens; all six selective observations exhaust 256 tokens without a final answer. This is a targeted reproduction, not extra held-out cases.
  • Matched nonterminal eighth-token samples show lower active MLX allocation: GPT 95–99 MiB at 4K and 752–758 MiB at 32K; Gemma 39.6–41.3 MiB and 314.7–316.3 MiB. These are live allocator observations, not RSS or extra admission capacity.
  • All four main arms complete request-scope, actual cancellation, exact donor recovery and clean shutdown checks. Whole-run allocation peaks are effectively unchanged. Short-output decode can slow substantially; no general speedup is claimed.

Full results, exact artifact hashes, compressed raw reports, limitations and follow-up hypotheses. All measured inputs are synthetic text. Both arms disable MTP and prefix reuse; this does not qualify multimodal retention, concurrent serving, or combination with quantized KV.

Validation:

  • Focused selective/teacher-forced checks, nested selective tests, 34 radix harness tests, six comparison tests, and 14 native-CI routing tests pass.
  • Isolated native allocator fixture releases exactly 15,728,640 bytes after evaluated compaction (34,603,008 → 18,874,368 active bytes).
  • Hosted Provider Unit Tests, Provider SDK Tests and Provider Prompt Parity pass on source head 393aa0007; this final commit adds evidence/docs only. SDK feat(console-ui): image upload in chat for vision models (Gemma 4) #295 build/tests, lint, fork map and CodeQL pass on 46477f0.
  • Complete local provider/SDK checks were attempted and failed on initial missing MiMo test fixtures and native SwiftPM Metal-resource lookup; two SDK test targets terminate on missing Qwen4 gemm headers. These local failures remain separately documented.
  • Canonical docs coverage, touched-page lint and diff checks pass. Full docs lint retains the existing frozen-report link to absent coordinator/registry/cache_match_groups.go. Parent Before/After figures were visually verified on GitHub.

Memory limitation: BF16 Gemma keys are cast in full to FP32 while scoring. At 32K its two global KV heads and D512 require 128 MiB per global layer (640 MiB across five if graph lifetimes overlap), plus score/normalization intermediates and source/destination overlap. The serving gate stays closed until this temporary ownership and the quality regression are addressed.

@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Ready Ready Preview Oct 9, 2026 11:08am UTC
d-inference-console-ui-dev Ready Ready Preview Oct 9, 2026 11:08am UTC
d-inference-landing Ready Ready Preview Oct 9, 2026 11:08am UTC
darkbloom-status Ready Ready Preview Oct 9, 2026 11:08am UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 9, 2026 11:08am UTC

Request Review

This branch was successfully deployed

5 active deployments
Preview – d-inference — d1f71c63 Deployed Oct 9, 2026 by vercel[bot]
Preview – d-inference-landing — d1f71c63 Deployed Oct 9, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — d1f71c63 Deployed Oct 9, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — d1f71c63 Deployed Oct 9, 2026 by vercel[bot]
benchmarks — d1f71c63 Deployed Oct 9, 2026 by Gajesh2007 via E2E Benchmarks #2508
Preview – darkbloom-status — d1f71c63 Deployed Oct 9, 2026 by vercel[bot]
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.

1 participant