DIGM — prefill-time prompt-token KV eviction as a KV cache compression method (+ a framework gap: history_length blocks shrinking below the prompt)
Maintainer thường phản hồi trong vòng 1 ngày
@Hudayday đang làm issue này rồi.
Từ ngày 2/12/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
🚀 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.
- Ngôn ngữ chính
- Python
- Star
- 15.2k
- Fork
- 3k
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 477
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/TensorRT-LLM
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xCó thể đã có người làm @NimaVaziri đã nhận hôm nay. Đang mởPytorch
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA/TensorRT-LLM#23406 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Inference runtime Windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
NVIDIA/TensorRT-LLM#23394 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: MMLU subsampling changes when evaluators are interleavedCó thể đã có người làm @LeNeLeNeWo đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NVIDIA/TensorRT-LLM#23273 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Trace-replay Pareto window includes the drain when sessions finish out of admission orderCó thể đã có người làm @sbeierle đã nhận 3 ngày trước. Đang mởTesting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
NVIDIA/TensorRT-LLM#23077 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
LongBench V2 blog command breaks on inline comments after continuationsCó thể đã có người làm @ddlw đã nhận 25 ngày trước. Đang mởDoc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
NVIDIA/TensorRT-LLM#21879 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của NVIDIA/TensorRT-LLM
Issue tương tự
-
[Resource]: SpaicelyĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
hesreallyhim/awesome-claude-code#3875 · 1 bình luận ·
-
[Bug]: Ajax Pro login issueĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
bvis/aegis-hass#725 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
datasektionen/cashflow#468 ·
-
dont call alembic upgrade until we check whether or not the cache DB has an alembic version stampĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
#1643 unrecoverable split: 1 digest with a 403 — two earlier captures of the same URL are real 200sĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Robin-IA/Congressional-Letters-Dev#1684 ·
Maintainer thường phản hồi trong vòng 1 ngày