DIGM — prefill-time prompt-token KV eviction as a KV cache compression method (+ a framework gap: history_length blocks shrinking below the prompt)
Los mantenedores suelen responder en 1 día
@Hudayday ya está trabajando en esto.
Desde el 2/12/2026.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
🚀 The feature, motivation and pitch
What. I'd like to propose DIGM, a training-free KV cache eviction method, as a new method in the KV cache compression framework (tensorrt_llm/_torch/kv_cache_compression). DIGM runs once per request at the end of prefill (on_context_step_end). It reads one middle layer's keys from the KV pool, scores tokens by z-scored key norm (low norm = keep), and averages the scores over fixed 8-token chunks so spans are kept or dropped whole. It keeps a fixed budget made of 4 sink tokens, a recent window (25% of the budget) and the best-scoring chunks. It then compacts every layer with the framework's existing algorithm-neutral mover (compaction.py). Original positions are preserved through py_num_compressed_tokens, the same way TriAttention does it.
Why. The current eviction method, TriAttention, evicts decode tokens and always pins the prompt. Long-prompt workloads (RAG, document QA, long chat histories) spend most of their KV on the prompt, and nothing in the framework reduces that today. DIGM needs no calibration file, no attention scores and no query-dependent observation window. Because it runs after prefill, every layer's keys are already in the pool, so scoring at a middle layer costs no extra forward work.
Prototype. I have an out-of-tree prototype on TensorRT-LLM 1.3.0 (PyTorch backend, KVCacheManagerV2). It subclasses KVCacheCompressionManager, registers through the factory, and reuses build_compaction_params / compact unchanged. It runs on an RTX 4070 Laptop GPU (8 GB, SM89).
- Identity check: with budget = prompt length (compaction runs, nothing evicted), the output matches the uncompressed engine token-for-token.
- Multi-key retrieval (RULER-style: varied random-sentence haystack; 4 "special magic number" needles with different names; the question asks for one 7-digit value). 10 depths × 3 lengths (~2K/4K/7K), greedy decoding, Qwen3-0.6B and Qwen3-1.7B. In TRT-LLM the whole prompt (context + question) is compressed at the end of prefill. "window" = 4 sinks + the most recent tokens with the same budget.
| TRT-LLM (whole prompt compressed) | Qwen3-0.6B 25% | Qwen3-0.6B 50% | Qwen3-1.7B 25% | Qwen3-1.7B 50% |
|---|---|---|---|---|
| full cache | 28/30 | 29/30 | ||
| DIGM | 20/30 | 24/30 | 24/30 | 28/30 |
| window | 7/30 | 15/30 | 7/30 | 15/30 |
- The same prompts against published methods in kvpress (HF transformers, kvpress's protocol: context compressed, question appended uncompressed):
| kvpress (context compressed) | 0.6B 25% | 0.6B 50% | 1.7B 25% | 1.7B 50% |
|---|---|---|---|---|
| full cache | 27/30 | 29/30 | ||
| DIGM | 18/30 | 23/30 | 24/30 | 29/30 |
| KeyDiff | 1/30 | 10/30 | 13/30 | 25/30 |
| ChunkKV (SnapKV, chunk 20) | 7/30 | 14/30 | 11/30 | 19/30 |
| StreamingLLM | 8/30 | 15/30 | 8/30 | 15/30 |
| SnapKV | 2/30 | 5/30 | 2/30 | 3/30 |
| Knorm | 0/30 | 0/30 | not run | not run |
| ExpectedAttention | 0/30 | 0/30 | not run | not run |
- Protocol: the DIGM settings (score layer = num_layers / 4, i.e. layer 7 of 28 for both models; chunk 8; recent 25%) were chosen on a separate dev prompt set (different seed) with Qwen3-0.6B, fixed, and then run once on the test prompts above, including on Qwen3-1.7B. An earlier configuration (layer 1, token-level, recent 50%) scored 3/30 and 8/30 on both models in kvpress, because layer-1 norms do not single out the needles in varied text.
- Known weak spot: short prompts at 25% keep (~2K tokens, ~490-token budget): 2/10 on Qwen3-0.6B, 7/10 on Qwen3-1.7B in TRT-LLM. Not yet understood.
- A larger model (Qwen3-4B) is next; I'll add the results here.
A framework gap the prototype hit (useful beyond DIGM). KVCacheManagerV2's history_length is monotonic and must stay <= capacity. update_context_resources → _resize_context_history sets it to context_current_position (= prompt length) when prefill finishes. After that, a method can't resize() the cache below the prompt length ("History length cannot exceed capacity"). TriAttention never hits this because it keeps the prompt. Any method that evicts prompt tokens will. My prototype works around it by not advancing history during prefill for managers bound to DIGM (block reuse off, dense attention only, where history is only a marker). Possible upstream options:
- When
kv_compression_manages_historyis set, let the compression manager own the context-phase history too (skip or defer_resize_context_history), the same as the generation path already does. - Add an explicit "rebase history after compaction" API on the per-request cache.
I'd like maintainers' guidance on which fits KVCMv2's design before writing it.
Proposed upstream shape (following kv-cache-compression-development.md → "Adding a compression method"):
DIGMKvCacheCompressionConfig(KvCacheCompressionConfig)withchanges_physical_kv_length = True. Fields:budget(orkeep_ratio),n_sink,recent_frac,score_layer,chunk,pool. Added toKvCacheCompressionConfigType.- A factory branch in
create_kv_cache_compression_managerand an entry invalidate_kv_cache_compression_compatibility. DIGM has no SM100 requirement. DIGMCompressionManagerwith batched GPU scoring (Triton) instead of the prototype's per-request Python path, using preallocated buffers and stream ordering like TriAttention.- The history fix above, as a separate PR.
- Tests: identity (keep all ⇒ exact match), compaction vs a reference gather, an e2e accuracy smoke test, and chunked prefill.
- A docs section in
features/kv-cache-compression.md. - Initial scope: dense attention, beam width 1, no speculative decoding, block reuse off. SWA/hybrid and spec-decode can follow.
Alternatives
- Decode-time only (TriAttention): keeps the full prompt, so there's no saving on prompt-heavy requests.
- Attention-score methods (SnapKV-style): need an observation window of queries at prefill, which the current hooks don't expose and which is query-dependent. Key-norm scoring works from the KV pool alone.
- Quantization (cold-page NVFP4/TurboQuant): orthogonal. It reduces bytes per token rather than the token count, and the two could compose.
Additional context
-
I'd like to implement this myself: the history fix as one PR and DIGM as a second PR that depends on it, once the design direction is agreed.
-
Prototype and benchmark scripts: I'll publish them in a public repo this week and link them here.
-
DIGM is covered by Indian patent application IN202641128952 (applicants: Sai Jathin Bhupalam and Dr. Naveen N C). Any contribution would be made under Apache-2.0, including its patent grant.
-
cc @Hudayday (author of the compression framework and the TriAttention integration). Happy to adjust the design to whatever fits the framework best.
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
- Lenguaje dominante
- Python
- Estrellas
- 15.2k
- Forks
- 3k
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 477
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de NVIDIA/TensorRT-LLM
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xPosiblemente ocupada @NimaVaziri la tomó hoy. AbiertoPytorch
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NVIDIA/TensorRT-LLM#23406 ·
Los mantenedores suelen responder en 1 día
-
Inference runtime Windows
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
NVIDIA/TensorRT-LLM#23394 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: MMLU subsampling changes when evaluators are interleavedPosiblemente ocupada @LeNeLeNeWo la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
NVIDIA/TensorRT-LLM#23273 ·
Los mantenedores suelen responder en 1 día
-
Trace-replay Pareto window includes the drain when sessions finish out of admission orderPosiblemente ocupada @sbeierle la tomó hace 3 días. AbiertoTesting
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
NVIDIA/TensorRT-LLM#23077 ·
Los mantenedores suelen responder en 1 día
-
LongBench V2 blog command breaks on inline comments after continuationsPosiblemente ocupada @ddlw la tomó hace 25 días. AbiertoDoc
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
NVIDIA/TensorRT-LLM#21879 ·
Los mantenedores suelen responder en 1 día
Todos los issues de NVIDIA/TensorRT-LLM
Issues similares
-
[Resource]: SpaicelyAbiertoresource-submission validation-passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
hesreallyhim/awesome-claude-code#3875 · 1 comentario ·
-
[Bug]: Ajax Pro login issueAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
bvis/aegis-hass#725 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stampAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
#1643 unrecoverable split: 1 digest with a 403 — two earlier captures of the same URL are real 200sAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Robin-IA/Congressional-Letters-Dev#1684 ·
Los mantenedores suelen responder en 1 día