TL;DR
The authors introduce Universal Multi-step Input Merging (UMIM), a lightweight plug-in module that compresses predictable multi-token spans into a single "surrogate embedding" on the fly. By utilizing a novel KV cache rollback mechanism during decoding, UMIM reduces effective sequence lengths and memory footprints by up to 40% across diverse tasks—all while keeping the underlying large language model (LLM) completely frozen and unaltered.
What Problem Does This Paper Address?
Autoregressive large language models process text token by token, which makes handling long prompts and expanding contexts computationally expensive and memory-intensive due to the growth of the Key-Value (KV) cache.
However, human language is full of highly predictable, recurring multi-token units (e.g., phrases like "machine learning" or "New York"). Processing these predictable sequences step-by-step wastes computational resources. Existing context-reduction methods typically require modifying the tokenizer, completely retraining the LLM, or introducing heavy auxiliary architectures that add significant inference overhead.
This paper tackles a fundamental question: Can we compress multi-token sequences into single-step inputs at inference time without altering the internal weights or architecture of a pretrained LLM?
Methods
The authors propose Universal Multi-step Input Merging (UMIM), which consists of three core components:
- Frequency-Based Merge Rules: The system pre-mines a set of high-frequency $n$-grams (where $2 \le n \le 4$) from a text corpus. During inference, a longest-match strategy scans the input sequence to identify candidate spans for compression.
- Lightweight Merge Module: Implemented as a single-layer multi-head attention pooling network, this module takes the static embeddings of a selected token span and compresses them into a single surrogate embedding.
- Predictive Distillation Loss: The merge module is trained by minimizing the KL divergence between the output distribution of the original uncompressed sequence and the compressed sequence. Crucially, the backbone LLM remains entirely frozen during this process; only the tiny external merge module is updated.
Prefill vs. Decoding Integration
- Prefill (Prompt Compression): Eligible token spans within the prompt are replaced by surrogate embeddings before entering the Transformer, resulting in a smaller initial KV cache.
- Decoding (Runtime Rollback): As the model generates new tokens, it checks the recent suffix against the merge rules. If a match occurs, UMIM dynamically rolls back the last $n-1$ KV cache entries and replaces them with a single merged surrogate KV state.
Datasets
The authors evaluated UMIM across a wide array of models (Llama 3.1 8B, Llama 3.2 1.5B, GPT2-XL, and DeepScaleR-1.5B-Preview) using the following datasets:
- Base Training: WikiText-103 for standard language models; a custom long-form mathematical reasoning trajectory corpus (mined from Omni-MATH and STILL-3-Preview-RL-Data) for DeepScaleR.
- Language Modeling: WikiText-103, BookCorpus, and OpenWebText.
- Downstream Tasks: QA benchmarks (PIQA, COPA, OpenBookQA, ARC-Easy, ARC-Challenge); Summarization (CNN/DailyMail, GovReport, QMSum); Advanced Math (AIME 2024, AMC); Long-Context Retrieval (RULER four-needle retrieval); and Code Generation (HumanEval).
Key Insights and Ideas
- Functional over Semantic Equivalence: The surrogate embedding does not attempt to mathematically average the token embeddings or match intermediate hidden states. Instead, it focuses purely on functional preservation—ensuring that the downstream next-token probability distribution remains identical to the original sequence.
- Context-Independent Input, Context-Dependent Processing: Although the merge module produces the same static surrogate embedding for a given $n$-gram regardless of context, once it enters the Transformer, it interacts dynamically with surrounding tokens via self-attention and positional encodings, naturally becoming context-dependent.
- Implicit Position Compaction: Rather than manually adjusting position IDs or interpolating encodings, the merge module implicitly learns to compensate for both token replacement and position shifting because it is trained end-to-end through the frozen LLM's full attention layers.
Key Results
- Substantial Token Reduction: UMIM consistently reduces effective sequence lengths by up to 40% across language modeling and downstream tasks with minimal accuracy degradation.
- Significant Prefill Speedups: By directly shortening the input sequence length, UMIM provides up to a 3.74× prefill speedup for long prompt contexts (e.g., 2048 tokens).
- Task Adaptation Boost: When the merge module is further specialized using Supervised Fine-Tuning (SFT) and Direct Preference Optimization (DPO) on specific downstream tasks, it can even outperform the uncompressed baseline. For example, on HellaSwag, the Task-Adapted variant achieved a +6.52 percentage point accuracy improvement over the baseline while maintaining compression.
Limitations and Future Work
- Decoding Overhead: The current implementation relies on a non-fused Python prototype, which limits decoding throughput improvements to a modest 0.9%–2.5% due to suffix matching and cache cropping overhead. Fusing these operations into custom CUDA or Triton kernels is a critical next step.
- Long-Context Performance Drop: Performance degrades on very long-context tasks (e.g., 8K/16K retrieval on RULER) because the base merge module was trained only on 512-token sequences. Incorporating long-context data during merge module pretraining will be necessary for scaling.
- Granularity Loss: Compressing multiple KV states into one means future queries cannot access individual constituent tokens independently, which might introduce approximation errors in highly ambiguous or context-sensitive scenarios.
Summary updated