UMIM · NeurIPS 2026

Distilling Sequential Computation in Transformer Language Models

Zixuan Lan1Jessica Yang2Yanhong Li3Karen Livescu2Jiawei Zhou4
1University of Chicago2Toyota Technological Institute at Chicago3Independent Researcher4Stony Brook University

Paper overview

Abstract

Transformer language models process sequences token by token in an autoregressive manner, making growing contexts increasingly expensive. Yet many adjacent token spans are highly predictable or frequently occur as stable units, suggesting that their representations may be compressible. We introduce a method for distilling sequential computation by replacing spans of input tokens with collapsed representations, computed on the fly by a lightweight merge module. This module generates a single surrogate embedding from a sequence of static token embeddings that captures the functional role of the multiple tokens, allowing pretrained models to operate on compressed inputs without architectural changes or re-training. We apply this approach during inference to compress both prompts and intermediate decoding steps, using a rollback mechanism to substitute stored multi-token KV cache entries with their single-step surrogates. Experiments across diverse models show that the merge module can be used to reduce effective sequence length by up to 40% with minimal accuracy degradation across language modeling evaluations and downstream tasks, including question answering, summarization, commonsense reasoning, and long-form mathematical reasoning. Additional lightweight adaptation of the merge module further improves the accuracy-compression trade-off in selected settings. These results demonstrate that sequential token computation in Transformers can be effectively approximated through condensed surrogate representations that preserve the original behavior without model updating.

01 Build Merge Rules

Extract high-frequency N-grams.

Detecting repeated spans2 · 3 · 4-grams

A language model learns regularities from large collections of text. Modern language models use those regularities to predict what comes next, creating representations that remain useful in the world beyond the training corpus. Researchers study how a language model preserves meaning across long sequences and how repeated structures appear in the world of natural text. Performance improves as a result of better data and optimization; compression becomes possible as a result of patterns that recur again and again. Across many documents, the same language model encounters familiar structures in the world of news, science, and history. These spans become reliable compression candidates as a result of their repeated use.

Large text collections contain biographies, news reports, scientific articles, and conversations written in many different styles. A language model may encounter the same short constructions thousands of times even when the surrounding topic changes. The phrase language model often appears in technical writing, while in the world recurs throughout narrative text andas a result of frequently connects an observation to its consequence. Counting these repetitions across the corpus reveals contiguous token spans that remain stable across documents, authors, and domains.

Similar repetition appears across topics that otherwise share very little vocabulary. An astronomy article may describe objects in the world beyond Earth, while a report on computation discusses how a language model processes a sequence. Historical writing links causes and consequences as a result of earlier events, and educational material returns to the same explanation in several chapters. When these local patterns recur at scale, their frequency distinguishes stable spans from combinations that appear only once. The corpus therefore provides both the candidate phrases and enough examples to observe them in varied surroundings.

Frequently recurring spans are retained asMerge Rules R

2-gramlanguage model
3-gramin the world
4-gramas a result of

02 Core component

The Merge Module Mφ

Static embeddings Trainable Mφ Frozen Base LLM
Matched spanStatic token embeddings
languageelanguage
modelemodel
Merge ModuleMφ

Single-layer multi-head attention pooling

Trainable
Output projectionWoLinear · GELU · LayerNorm
Concatenate[ o₁ ; o₂ ; ··· ; oₕ ]
Attention poolingLearnable queries Q = {q₁, q₂, ···, qₕ}
q₁
LHead 1M
o₁
q₂
LHead 2M
o₂
q₃
LHead 3M
o₃
qₕ
LHead hM
oₕ
Shared K / V projectionWkv
Linear · GELU · LayerNorm
One surrogate embeddinglanguage model
Frozen Base LLMθ
Mϕ ⁣(e(xt:t+n))=Wo[o1;⋯ ;oh]⊤,oi=softmax ⁣(qi⊤Wkve(xt:t+n)dh)(Wkve(xt:t+n))⊤. M_\phi\!\left(e(x_{t:t+n})\right) = W^o \left[\mathrm{o}_1;\cdots;\mathrm{o}_h\right]^\top, \quad \mathrm{o}_i = \mathrm{softmax}\!\left( \frac{q_i^\top W^{kv} e(x_{t:t+n})}{\sqrt{d_h}} \right) \left(W^{kv} e(x_{t:t+n})\right)^\top .

01The static embeddings of a matched token span enter the merge module before any Transformer layer.

03 Train Mφ

Train Merge Module

Merge Rules R Base LLM θ Shared · Frozen Merge Module Mφ Trainable
Teacher input
Thex₁
languagex₂
modelx₃
predictsx₄
thex₅
nextx₆
tokenx₇
Frozen Base LLM θ
Teacher outputs
pθ(·|x≤1)
pθ(·|x≤2)
pθ(·|x≤3)
pθ(·|x≤4)
pθ(·|x≤5)
pθ(·|x≤6)
pθ(·|x≤7)
Original sequence
Thex₁
languagex₂
modelx₃
predictsx₄
thex₅
nextx₆
tokenx₇
2-gram in Merge Rules R
MφMerge module
Student sequence
Thex₁
language modelx₂₃
predictsx₄
thex₅
nextx₆
tokenx₇
Student model
Student outputs
pθ(·|x≤1)
pθ(·|x₂₃)
pθ(·|x≤4)
pθ(·|x≤5)
pθ(·|x≤6)
pθ(·|x≤7)
Soft-target alignmentDistill only the computation changed by mergingx₃ ↔ x₂₃ · changed suffix
Teacher targetsUnmergedBase LLM θ · frozen
x₁The
pT1
x₂language
pT2
x₃model
pT3
x₄predicts
pT4
x₅the
pT5
x₆next
pT6
x₇token
pT7
AlignmentSoft targetsDKL(pT ∥ pS)
=No lossunchanged
x₂ absorbedinto x₂₃
Student predictionsMergedMφ trainable · θ frozen
x₁The
pS1
absorbedno student state
x₂₃language model
pS23
x₄predicts
pS4
x₅the
pS5
x₆next
pS6
x₇token
pS7
Σ aligned KLℒdistill
Gradients flow through frozen θθ receives no parameter update
Update onlyMφTrainable
2-gram rule in Rlanguage model(x₂, x₃) ∈ R
Sequencetoken embeddings
Thex₁
languagex₂
modelx₃
predictsx₄
thex₅
nextx₆
tokenx₇
language modelx₂₃
Teacheroriginal sequence
Thex₁
languagex₂
modelx₃
predictsx₄
thex₅
nextx₆
tokenx₇
Studentmerged sequence
Thex₁
x₂ collapsed
language modelx₂₃
predictsx₄
thex₅
nextx₆
tokenx₇
x₃ ↕ x₂₃
Unchanged prefix
Mφ produces x₂₃
Distill aligned position + changed suffix
same weightsBase LLMθFrozen

01Teacher baseline: the unmerged sequence passes through the frozen Base LLM and produces a next-token distribution at every position.

DKL(pteacher ∥ pstudent)

04 Inference

Inference with UMIM

Merge Rules R · non-overlapping Merge Module Mφ · trained Base LLM θ · frozen
Prompt
Thex₁
languagex₂
modelx₃
predictsx₄
thex₅
nextx₆
tokenx₇
inx₈
thex₉
worldx₁₀
Apply Mφ
Mφ
Mφ
Compressed Sequence
Thex₁
language modelx₂₃
predictsx₄
the next tokenx₅:₇
inx₈
thex₉
worldx₁₀
Base LLM Forward
Prefill Output
Initial KV Cache
baseline 10 → UMIM 7
KV
KV
KV
KV
KV
KV
KV
First Next-token Distribution
Decoding
Effective positions 7 → 8KV length 7 → 8
Sample & Append
Next-token Prediction
sample“is”
Thelanguage modelpredictsthe next tokenintheworldis
KVKVKVKVKVKVKVNo KV
Tail Check
Check token-ID suffixes against Merge Rules R
intheworldis
2-gramworld · is3-gramthe · world · is4-gramin · the · world · is
No suffix appears in R
Base LLM Forward
Embedding“is”enew
+
KV Cache Context
Decoding Output
KVKV for “is”
Next-token Prediction
“a”
Decoding
Token IDs 8 → 9KV length 8 → 8
Sample & Append
Next-token Prediction
sample“a”
Thelanguage modelpredictsthe next tokenintheworldisa
KVKVKVKVKVKVKVKVNo KV
Tail Match
Tail Check
theworldisa
2-gram in Ris · a
KV Rollback
KV for “is”
Remove the previous suffix state
Apply Mφ
is&a→Mφ→“is a”
Base LLM Forward
Merged Embedding“is a”ẽis,a
+
Rolled-back KV Context
Decoding Output
KVKV for “is a”
Next-token Prediction
“test”

01PrefillMerge matched prompt spans before the first LLM forward, then build the initial compressed KV cache and first next-token distribution.

05 Results

Task-Agnostic Transfer

Base Mφ · Language ModelingLanguage modeling performance under token reduction.

PPL ↓Perplexity · lower is better

TR ↑Token reduction · higher is better

BackboneMethodWikiText-103Rule sourceBookCorpusUnseen corpusOpenWebTextUnseen corpus
PPL ↓TR (%) ↑PPL ↓TR (%) ↑PPL ↓TR (%) ↑
Llama-3-8BOriginal13.4—15.3—9.2—
Merge Module13.836.115.314.89.813.8
Llama-3.2-1BOriginal20.1—21.2—13.4—
Merge Module23.436.122.014.814.713.8
GPT2-XLOriginal28.6—27.1—13.1—
Merge Module37.935.130.014.114.412.5
Evaluation setting. The same WikiText-derived merge rules and WikiText-trained Base Mφ are applied directly to all three corpora. BookCorpus and OpenWebText are unseen transfer corpora; the backbone remains frozen and no downstream retraining is used. Original denotes the uncompressed backbone.

06 Lightweight Adaptation

Task Adaptation

Merge Rules Rtask · Re-mined Base LLM θ Frozen throughout Merge Module Mφ Only trainable component
01

Re-mine rules

Target taskDtask
Downstream task
Frequency miningf(g) ≥ τ
Task-specific merge rules
Rtask
02

Task SFT

WikiText-pretrainedMφWTBase merge module
Task-specific rulesRtaskRe-mined above
Target-task adaptationTask SFT
Base LLM θ frozen Update Mφ only
update φ only
SFT merge moduleMφSFT
03

Task RL

SFT merge moduleMφSFTwith Rtask
construct pairs
DPO sequence pairs
y+y−
Task-specific optimizationTask RL (DPO)
Base LLM θ frozen Update Mφ only
update φ only
Final moduleMφtask
Final task-adapted inference
Target-task inputMerge token spans using Rtask and MφtaskFrozen LLM θ
Task adaptation re-mines Rtask, applies SFT to the WikiText-pretrained merge module, uses MφSFT to construct DPO sequence pairs, and applies RL only to the merge module. The backbone LLM remains frozen throughout.

07 Adapted Results

Merge More. Perform Better.

HellaSwag · Llama-3-8BAccuracy across increasing token reduction
Rules re-mined for adaptationBigram onlyTheoretical merge ceiling · 50%
Baseline
One lightweight module39.53% token reduction+2.72 accuracy points

This adaptation experiment re-mines bigrams only. With non-overlapping token pairs, the theoretical token-reduction ceiling is 50%.

HellaSwag accuracy under task adaptation
Method12.10%21.94%28.89%39.53%
Baseline78.3478.3478.3478.34
MφWT + Rtask76.9575.7374.4771.13
MφSFT + Rtask78.0277.2876.3174.41
Mφtask + Rtask84.184.8683.6581.06