Skip to content

Design: content-addressed host KV cache — retrospective for #73, relation to #51/#64 #75

Description

@iamwavecut

Design doc for #73, written after the fact (the PR skipped this step; future work starts here). Overlaps #51/#64 — a synthesis proposal is at the end.

Problem

  1. Any prefix lost from device residency is re-prefilled: 53 s at 118k (int8, 5090), 234 s at 134k on a 24 GiB card. 2. Trajectories forking from a shared prefix (subagents) pay the full prefix per branch.

Design (implemented in #73, opt-in --kv-host-cache-mib N, N=0 inert)

  1. Chained page keys: key[i] = fold(key[i-1], token_i) over ids, types, all MRoPE axes, and per-item media SHA-256, per KV page. One 64-bit match certifies the whole prefix — the causal validity KV needs. Salted by kv-dtype/spec config + format version.
  2. Pinned segment store: budget-bounded chunks; page dedup by key with refcounts; whole-segment LRU (never punctures a chain); shared pages pinned during staging so eviction cannot race a save.
  3. Anchors at terminal + rewrite-checkpoint frontiers: GDN linear state, MTP watermark, boundary hidden — the sound fork points for hybrid attention.
  4. Hostpack kernels: batched gather/scatter between pool planes and packed staging borrowed from the idle workspace arena.
  5. Engine seam: ContentRestore reuse path planned only when resident paths miss; save at terminal completion; decode never touches the machinery.

Numbers: 118 828 tokens cold 53 379 ms → restore 422 ms (126×), byte-identical; branch switch over a shared prefix ≈ 100 ms; production soak on the sm_86 fork at 251×.

Planned follow-ups (in order; each lands only after feedback here)

  1. Storage-provider split: interface (present/reserve/read/write/seal/evict/anchors, byte spans) + pinned impl → enables a file-backed provider (mmap NVMe), cache survives restarts. Matches feat(engine): host-backed KV cache - park evicted lanes to pinned RAM #64's provider direction.
  2. Restore-before-planning (adopted from feat(engine): host-backed KV cache - park evicted lanes to pinned RAM #64's integration): rehydrate the lane before request planning so the unmodified planner picks append/checkpoint paths; deletes the ContentRestore special cases.
  3. Interval anchors (every K pages) for mid-generation forking.

Relation to #64 (park evicted lanes)

Complementary shapes of one problem: #64 parks whole lanes by prefix identity (precise state, simple, no dedup/branching, slab per max-sequence); #73 stores content-addressed pages (dedup, branching, survives prompt rebuilds, needs retokenization stability). A workable synthesis: #64's park/restore-before-planning as the fast path, backed by a shared content-addressed page store as the substrate. Happy to converge on whichever shape you prefer.

Open questions

  1. One host-cache substrate or two features?
  2. Is the retokenization caveat acceptable, or should ledger token ids be the only key source?
  3. Budget flag naming vs feat(engine): host-backed KV cache - park evicted lanes to pinned RAM #64's --host-kv-cache.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions