Skip to content

serving: opt-in KV-quant + flash attention — the unique half of #2053, rescued onto canary - #2244

Open
joelteply wants to merge 3 commits into
canaryfrom
feat/kv-quant-flash-attn
Open

serving: opt-in KV-quant + flash attention — the unique half of #2053, rescued onto canary#2244
joelteply wants to merge 3 commits into
canaryfrom
feat/kv-quant-flash-attn

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Salvage of #2053, which had become unmergeable for a reason worth stating: half of it was already in canary.

What was superseded

Canary now threads a ServingDemand struct (window_tokens, 61 references in serving_daemon). #2053's elastic-window commits pass two scalars (demand_lanes, demand_ceil) and predate that struct — so every rebase attempt collided on an API canary had already replaced with a better one. The feature landed; the branch's version of it is dead weight.

What was NOT

flash_attn / kv_quant / cache_type return 0 matches in canary. This is real, unlanded work:

  • 0ea9538a1 opt-in KV cache quantization — q8_0 halves KV, feeds the elastic window
  • 175cd6d51 KV-quant fit coupling — the window GROWS into the freed KV memory
  • 10fed2798 opt-in flash attention — faster prefill+decode, lower memory

Cherry-picked onto canary, all three applied clean (no conflicts), which is itself evidence they were only ever blocked by the superseded commits sitting in front of them.

Verification

cargo check -p continuum-core --lib --tests clean.

Why not just rebase #2053

Tried. It conflicts commit-by-commit on the replaced demand API, and resolving each one means hand-reconstructing a feature that is already live. The remaining #2053 commits (grid-overflow effector, expert_observe harness) are separate units and get the same treatment — verify against canary first, rescue what is unique.

joelteply and others added 3 commits August 11, 2026 16:35
…he elastic window (#232)

Adds SERVING_KV_CACHE_TYPE (config, default f16/off): when set to q8_0 (or q4_0) the
llama-server lane runs --cache-type-k/v <type>, cutting resident KV ~in half at
near-lossless quality. That frees memory the elastic window (#234) can spend on a bigger
context or more warm lanes — faster for multiple personas AND more room for hard coding,
the same "faster + best code" pair.

OFF by default and safe-by-construction: absent / f16 → byte-identical f16 launch (no
behavior change), so this can't destabilize a backend whose build lacks Metal KV-quant
kernels — enabling it is an explicit operator opt-in, never a blind assumption
([[verify-real-device-numbers-not-a-clamp-premise]]).

Follow-up (noted in code): to have the PLAN grow the window on the freed memory rather
than leave it as extra headroom, footprint_for must scale kv_per_token by the quant
factor. This slice is the safe enablement; that fit-math coupling is the next step, and
wants a live burst on a KV-quant-capable backend to validate quality + the speedup.

continuum-core lib compiles clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…d KV memory (#232)

Completes the KV-quant feature. The launcher flag (prior commit) makes a lane run q8_0
KV; this makes the PLAN know it: footprint_for scales kv_per_token by the quant divisor,
so the served window is sized against the KV the lane WILL actually hold, and the elastic
window (#234) grows into the freed memory instead of leaving it idle.

- kv_divisor_for (pure, env-free, unit-tested): f16/unset/unknown → 1 (no change), q8_0 → 2,
  q4_0/q4_1 → 3. CONSERVATIVE by design — under the ideal ~3.5x for q4 — so the plan can
  never over-grow the window past the real KV and OOM (over-reserve = smaller window = safe).
- Applied only in the config-aware footprint_for; footprint_from_parts stays pure so its
  tests are env-independent. Same SERVING_KV_CACHE_TYPE key as the launcher — one config,
  two consumers (flag + fit rate), documented to stay in sync.

Default (f16 / unset) → divisor 1 → byte-identical: this can't change serving on a box that
doesn't opt in. Test pins the mapping + the safe-default. Wants a live burst on a
KV-quant-capable backend to confirm quality + the actual window growth.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…memory (#232)

The fused attention kernel is faster on BOTH prefill and decode and lowers peak memory —
directly attacking the prefill-bound turn latency (#139) and freeing room the elastic
window (#234) can spend. SERVING_FLASH_ATTN=1|on|true adds --flash-attn to the lane;
absent → llama.cpp default (no flag), byte-identical.

OFF by default: Metal/backend flash-attn support + quality vary by build, so it's an
operator opt-in, never a blind assumption ([[verify-real-device-numbers-not-a-clamp-premise]]).
Composes with the KV-quant flag: enable both for the field-proven GLM-style speedup, then
validate on a live burst. continuum-core lib compiles clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant