DIGM — prefill-time prompt-token KV eviction as a KV cache compression method (+ a framework gap: history_length blocks shrinking below the prompt)
Maintainers usually reply within 1 day
@Hudayday is already working on this.
Since Dec 2, 2026.
Assessment
This issue has not been assessed yet.
Description
🚀 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.
- Dominant language
- Python
- Stars
- 15.2k
- Forks
- 3k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 477
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/TensorRT-LLM
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xPossibly taken @NimaVaziri claimed this today. OpenPytorch
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NVIDIA/TensorRT-LLM#23406 ·
Maintainers usually reply within 1 day
-
Inference runtime Windows
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
NVIDIA/TensorRT-LLM#23394 ·
Maintainers usually reply within 1 day
-
[Bug]: MMLU subsampling changes when evaluators are interleavedPossibly taken @LeNeLeNeWo claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NVIDIA/TensorRT-LLM#23273 ·
Maintainers usually reply within 1 day
-
Trace-replay Pareto window includes the drain when sessions finish out of admission orderPossibly taken @sbeierle claimed this 3 days ago. OpenTesting
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NVIDIA/TensorRT-LLM#23077 ·
Maintainers usually reply within 1 day
-
LongBench V2 blog command breaks on inline comments after continuationsPossibly taken @ddlw claimed this 25 days ago. OpenDoc
Difficulty 1/5 Under an hour Newbie friendliness 91/100
NVIDIA/TensorRT-LLM#21879 ·
Maintainers usually reply within 1 day
All issues in NVIDIA/TensorRT-LLM
Similar issues
-
[Resource]: SpaicelyOpenresource-submission validation-passed
Difficulty 1/5 Under an hour Newbie friendliness 68/100
hesreallyhim/awesome-claude-code#3875 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
bvis/aegis-hass#725 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stampOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
#1643 unrecoverable split: 1 digest with a 403 — two earlier captures of the same URL are real 200sOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Robin-IA/Congressional-Letters-Dev#1684 ·
Maintainers usually reply within 1 day