epic: Prompt-prefix cache reuse for sliding-window families

Abierto
#3,259 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
8/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
markdown, python, rust

Línea de trabajo

This is an epic tracking four sub-issues (#3255 to #3257, plus #3254) on the scheduler-owned prompt-prefix cache, so it is not a starting point. Read state_checkpoints.rs and the scheduler prompt-cache code, then the ADR 0010 reference migrations for Gemma 3 and Qwen 3.5. Pick a numbered sub-issue instead; this epic is done when all sub-issues merge and the scripts/bench_prompt_cache_replay.py --verify run is recorded in docs/benchmark_results/.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area:architecture area:inference priority:high status:blocked type:epic

Problem / Background

Sliding-window families miss the prompt-prefix cache whenever a request diverges before the end of the stored prefix. Measured on GB10 with mlxcel-server 0.8.1, gemma-4-12b-it-4bit, fp16 KV and about 5.8k-token prompts:

  • An exact multi-turn continuation hits: 5808/5823 tokens cached, TTFT about 4.9 s down to 0.4-0.56 s.
  • An edit, a regenerate, or a new chat with the same system prompt reuses nothing (snapshot_diverged). The sliding ring (window 1024) has wrapped, and the history-boundary snapshot cannot be truncated.
  • A desktop client (AI:GO) that edits the previous user message saw cached_tokens=0 on every turn.

Qwen3 under the same conditions reuses up to the divergence point.

The root cause is ownership. Sliding layers are model-owned rings, and every reuse feature is written per family. Among the sliding-window families, only Gemma 3, Gemma 4, AFMoE and Muse Glimmer have snapshot hooks. By code reading on origin/main, gpt-oss, Exaone 4, Ministral 3, Mellum, Laguna, Step 3.5, MiMo V2 Flash and DeepSeek V4 get no prefix reuse at all (see #3254).

Per-token KV in gemma-4-12b-it (40 sliding layers with 8 KV heads x 256, 8 full layers with 1 KV head x 512, K and V both stored) is 320 KiB sliding and 16 KiB full. The computed whole snapshot at 5.8k is about 431 MB, against snapshot_bytes_per_entry 435 MB measured.

Context Sliding ring Full-size sliding Full-attention KV
8k 320 MiB 2.5 GiB 128 MiB
32k 320 MiB 10 GiB 512 MiB
128k 320 MiB 40 GiB 2 GiB

Goal

Rotating families reuse prompt prefixes at any block boundary while the prompt-cache budget holds the sliding blocks, and at the nearest anchor (system root, previous turn) beyond that: across sessions that share a system prompt, and after edits, regenerates and branches. Live memory stays window-bounded, and save, restore, truncation, checkpoints and APC are implemented once in the scheduler instead of per model.

Sub-issues

Phase 1
  • #3255
Phase 2
  • #3254 (depends on #3255; merged in #3305)
Phase 3
  • #3256 (depends on #3254)
Phase 4
  • #3257 (depends on #3256)

Acceptance Criteria

  • All sub-issues completed and merged
  • On gemma-4-12b-it-4bit, the edited-previous-user-message replay (scripts/bench_prompt_cache_replay.py --verify) reuses up to the edit with outputs equal to cold reruns, recorded in docs/benchmark_results/
  • Follow-up issues filed for every family group still model-owned after #3254, linked here
  • #3250 re-evaluated against the scheduler-owned layer, with the decision recorded on that issue

Technical Considerations

  • #3254 is the foundation. It is sequenced after #3255 because both touch Gemma 3, state_checkpoints.rs and the scheduler prompt-cache code, and #3254 moves #3255's ring-only checkpoint into the generic path. It adds a scheduler-owned per-layer-kind state abstraction (paged blocks for full attention, window-bounded blocks for sliding, chunked, checkpointed recurrent state), with ADR 0010 and Gemma 3 and Qwen 3.5 as reference migrations.
  • #3255 is the interim fix and is recommended to ship first. It works on the current snapshot path and is built from what main already has (#2950, #2973, #3037, #3047). After #3256 it stays useful for recurrent families and any family #3256 does not cover.
  • #3256 is the main piece.
  • #3257 is the opt-in after it.
  • #3250 (quantized KV in snapshots) applies today to the snapshot path. Int8 and Turbo sequences are never pool-backed, so the paged sliding design covers FP16 only until #3250 is revisited against #3254.
  • #3246 (Prometheus prompt-cache double count) affects /metrics totals. All acceptance here reads cached_tokens and /v1/cache/stats instead.
  • App side. The client-side fix, keeping chat history append-only, is tracked separately in lablup/backend.ai-go. It is still needed for remote providers.

Run wrap-up — 2026-11-25

#3255 merged in #3283 and #3254 merged in #3305. The isolated execution-overhead optimization #3385 merged in #3406 (50ac7182), with the owner accepting the small-model performance tradeoff documented there. This does not complete the sliding-window work.

#3256 remains open with draft #3334 stopped at its second B=1 performance gate (about 6% slower on the measured Gemma 3 case). Server paged-cache acceptance, retention/eviction checks, the real-model live-block bound, Gemma 4 migration and replay/parity acceptance remain incomplete. #3257 is still blocked by #3256. The epic remains open.

Family follow-ups were filed as #3324–#3329. #3386 tracks the OpenAI-route ignore_eos propagation bug and #3387 tracks other pool-slab kernels. #3250 must retain its separate quantized-state acceptance: this optimization neither adds Turbo4 prefix cloning/trimming nor proves quantized sliding-cache reuse.

Lenguaje dominante
Rust
Estrellas
505
Forks
81
Merge medio
14 h 2 min
PR fusionados (30 d)
448

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de lablup/mlxcel

Todos los issues de lablup/mlxcel

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.