TL;DR
ChunkLLM is a lightweight, pluggable framework designed to accelerate long-context Large Language Model (LLM) inference without sacrificing accuracy. By introducing semantically aware chunking and updating attention selection only at chunk boundaries, it retains 99.49% of vanilla performance while slashing KV-cache usage to ~52% and delivering up to a 4.48× inference speedup on 120K-token sequences.
What Problem Does This Paper Address?
As LLMs are scaled to process massive context windows, the self-attention mechanism becomes a severe bottleneck. Because self-attention scales quadratically ($O(N^2)$) with sequence length, storing the Key-Value (KV) cache for millions of tokens quickly exhausts GPU memory and tanks inference speed.
To mitigate this, recent research has turned to chunk-sparse attention, which groups tokens into blocks and selectively attends to the most relevant ones. However, existing approaches suffer from two core flaws:
- Semantic Incompleteness: Many methods partition text into fixed-size chunks, blindly slicing through sentences and disrupting contextual meaning.
- High Inference Overhead: Dynamic chunking methods often re-evaluate chunk importance at every single generated token, introducing significant computational overhead that offsets the benefits of sparsity.
ChunkLLM tackles both problems by introducing a pluggable architecture that respects natural semantic boundaries and exploits attention stability during generation.
Methods
ChunkLLM leaves the base LLM completely frozen and introduces two lightweight, trainable modules:
- Chunk Adapter: Positioned at the bottommost layer of the model, this single-layer Feed-Forward Network (FNN) acts as a binary classifier. It leverages contextual information to predict whether the current token marks a natural semantic boundary (e.g., the end of a sentence), ensuring chunks remain semantically intact.
- QK Adapter (Q- and K-Adapters): Integrated into each Transformer layer in parallel with the original $Q$ and $K$ matrices. It compresses features and maps full token-to-token attention scores into coarse-grained chunk attention scores.
Training via Attention Distillation
To train the QK Adapter without altering the base model's capabilities, the authors use an Attention Distillation strategy. The frozen LLM acts as a teacher. The student (the QK Adapter) minimizes the Kullback-Leibler (KL) divergence between its predicted chunk attention scores and the aggregated full attention scores of the teacher model.
Inference and the Voting Mechanism
During decoding, ChunkLLM maintains two caches: a Cold KV-cache (storing all tokens in slower memory) and a Hot KV-cache (storing only selected chunks in fast GPU memory). To avoid re-calculating chunk selection at every token, ChunkLLM introduces a Vote mechanism. It aggregates chunk retrieval predictions across all layers, counting votes to select the top-$k$ shared chunks.
Datasets
- Training: The adapters were trained on a 6-billion-token subset of the FineWeb-Edu dataset. The text was preprocessed using
pySBD(a rule-based sentence boundary disambiguation tool) to generate ground-truth semantic chunk labels. - Evaluation:
- LongBench: A multi-task long-context benchmark covering single/multi-document QA, summarization, few-shot learning, synthetic tasks, and code generation.
- Needle In A Haystack (NIAH): Used to evaluate precise information retrieval capabilities across varying context depths and lengths up to 64K.
- PG19: Used to evaluate long-text generation perplexity (PPL) and runtime efficiency up to 120K tokens.
Key Insights and Ideas
- Intra-Chunk Attention Consistency (ICAC): The authors discovered that tokens within the same generated semantic chunk exhibit highly consistent attention patterns. Attention shifts predominantly occur at chunk boundaries. This insight allows ChunkLLM to trigger chunk selection only when a new boundary token is detected, drastically reducing inference latency.
- Cross-Layer Voting: Not all layers natively exhibit sparse attention characteristics. Instead of forcing layer-specific sparsity or falling back to full attention, aggregating layer predictions via a voting mechanism yields highly accurate, shared key chunks.
- Data-Efficient Scaling: Even though ChunkLLM is trained strictly on short context lengths (4K), its semantic chunking and distillation approach allow it to generalize seamlessly to 120K contexts during inference without any long-context fine-tuning overhead.
Key Results
- Substantial Speedups: When generating text within a 110K–120K token window on the PG19 dataset, ChunkLLM achieves a 4.48× speedup for Llama3.1-8B and a 3.84× speedup for Qwen2.5-7B compared to the vanilla Transformer.
- Cache Reduction with Near-Lossless Performance: On LongBench, ChunkLLM retains 99.49% of the vanilla model's performance while utilizing only 52.10% of the KV-cache memory footprint.
- Robust Retrieval: In the 64K-context NIAH retrieval test, ChunkLLM maintains stable, near-perfect accuracy, whereas alternative methods like SepLLM experience a near-total loss of retrieval capability once the context length exceeds 12K tokens.
Limitations and Future Work
While ChunkLLM excels at processing plain text, it is currently limited when handling highly structured or complex textual data layout types, such as large tables or JSON-formatted data. Standard sentence segmentation tools fail to identify clean semantic boundaries in structured code or data formats, which compromises chunk selection.
The authors note that future work will focus on incorporating tabular and JSON data into the adapter training corpus to specifically enhance ChunkLLM's structural parsing capabilities.
Summary updated