AI Trends

Speculative Encoding Uses a Single Network for Cross-Model Cache Conversion

Baseten Base Labs: Model ResearchUpdated Nov 26 00:49

Speculative Encoding: Many-to-Many Cache Translation | Base Labs

AI summary

Base Labs introduces Speculative Encoding, which uses a single 2.35B-parameter network to perform state conversion in all 42 directions across 7 models from 4 model families. For documents up to 8k tokens long, converted caches retain 96.9% of the target model’s native accuracy; at 32k tokens, the target model begins answering 4× faster than when prefilling the text again, while retaining more than 90% accuracy. A query-conditioned compressor can also compress caches by up to 128×, achieving better results than full converted caches in long-context settings.

Why read this

AI score 59

This research consolidates pairwise-trained cache converters into a single network, providing a transferable engineering path for reducing redundant prefill in multi-model collaboration.

Topics

Tags

Body

IntroductionRelated workArchitectureTrainingStabilityResultsAcross familiesLong documentsCompressionInitializationArchitectureTrainingResultsConclusionAppendix A: implementation detailsAppendix B: training and evaluation setupReferencesPaper · NOV 2026Speculative Encoding: Many-to-Many Cache Translation

We introduce speculative encoding, a single network that translates states directly across models.

Ben Geist (Ramp Labs)

Thomas VilleneuveIntroductionRelated workArchitectureTrainingStabilityResultsAcross familiesLong documentsCompressionInitializationArchitectureTrainingResultsConclusionAppendix A: implementation detailsAppendix B: training and evaluation setupReferences

1Introduction

Language model systems increasingly split work across several models, and context moves between them as text. Before a model can use the text it receives, it must prefill it, running every token through each of its layers to build its key-value (K/V) cache. Prefill costs grow quadratically with context length, and the work repeats what the sending model has already computed.

Existing cache-to-cache translation methods avoid the text-roundtrip by mapping the sender's K/V cache directly into the receiver's cache. However, they are trained as model pairs, so a system of nnn models requires n(n−1)n(n-1)n(n−1) separately trained translators.

We introduce speculative encoding, a single network that translates states directly across models. Across seven models from four families, our translator covers all 42 source-target combinations and keeps 96.9% of the target model's native accuracy on documents up to 8k tokens. On 32k-token documents, the target starts answering 4× faster than re-prefilling from text while keeping over 90% of its accuracy. An additional query-conditioned compressor can shrink the requested cache, improving retention by 4 points at 128k context under 64× compression.

2Related work

We build on existing work in cache-to-cache translation, compression, and cross-model portability.

Cache-to-cache translation. Transferring a K/V cache between models lets the receiver skip prefill. Within a family, a smaller model can approximate a larger model's cache [Horton et al., 2024], and a closed-form per-head linear map converts the cache between sizes with matching head shapes [Heo et al., 2026; Qu et al., 2026; Dery et al., 2026; Chen et al., 2026]. Across families, most methods require the receiver to re-prefill the text [Fu et al., 2026; Liu et al., 2026; Rossi et al., 2026a; Lee et al., 2026]. SwaT [Alabdulkareem et al., 2026] removes this step by training one translator per source-target pair. Separately, YOCO and DeepSeek-V4.1-Flash build a layer's K/V from the hidden states of a lower layer [Sun et al., 2024; DeepSeek-AI, 2026].

Compression. Perceiver [Jaegle et al., 2021] uses cross-attention to extract information from a large input into a small set of output vectors. STILL [O’Neill et al., 2026] applies this approach to K/V cache compression by writing a compressed cache in one forward pass. This is trained with KL against the model natively reading the context to match the model’s usual rollout. SwaT compacts its translated cache in a separate step with Attention Matching [Zweiger et al., 2026]. CacheBack [Rossi et al., 2026b] selects which cache entries to send based on the receiving model’s query.

Cross-model portability. PorTAL [Geist, 2026] generates LoRA adapters for different base models using a shared model-agnostic core and thin model-specific alignment layers. To adapt a new base model to a previously learned task, only the alignment layers need to be trained.

We take four ideas from this work. From YOCO and DeepSeek-V4.1, we build K/V directly from hidden states. From SwaT, we bridge different tokenizers by starting the decoder from the target's own token embeddings. From STILL, we train with KL against the target's native rollout. Finally, PorTAL's shared core and thin per-model alignment transforms one-pair designs into a single translator for every pair of models.

3Architecture

The translator maps the source model's hidden states into the target model's hidden states. The target then computes its K/V cache from them with its own frozen weights. We translate hidden states over K/V cache for better generality. Predicting hidden states and forcing them through the target's frozen weights (K/V matrices) helps constrain keys and values to a space that is well understood by the target model. In addition, every layer of every model has only one hidden state per token, while per token K/V caches differ based on head count, head width and positional encoding, and linear-attention layers keep no K/V at all.

Setup. Let M\mathcal{M}M be a set of frozen models. Model m∈Mm \in \mathcal{M}m∈M has LmL_mLm layers and width DmD_mDm. We write xi,ℓm∈RDmx^m_{i,\ell} \in \mathbb{R}^{D_m}xi,ℓm∈RDm for the hidden state entering layer ℓ\ellℓ at token iii, with xi,0mx^m_{i,0}xi,0m being the token embedding, and XmX^mXm for all the hidden states model mmm produces over a document. We aim to train one translator TTT with T(Xsrc)=X^tgtT(X^{\mathrm{src}}) = \hat X^{\mathrm{tgt}}T(Xsrc)=X^tgt for any source and target models πsrc,πtgt∈M\pi_{\mathrm{src}}, \pi_{\mathrm{tgt}} \in \mathcal{M}πsrc,πtgt∈M.1^{1}1

Requirements. Three requirements shape the architecture:

Shared parameters. Most of the translator’s parameters should be shared across all models, so the translator grows with the number of models rather than the number of pairs.

Model-layer awareness. Models differ in width, and each layer of each model holds different information, so the shared parameters must know which model and layer they read from and write to.

One memory per source. Each source encodes its context once, and any target can decode it later.

Design. These requirements lead us to a transformer encoder-decoder shared by all models, which we adapt to each model-layer with projections and biases (Figure 1). The encoder turns the source's hidden states into a memory μ\muμ, and the decoder reads μ\muμ to predict the target's hidden states. Only the projections and biases are trained to be model specific.

Figure 1

The translator, shown translating Llama 3.1 8B into Qwen3.5 9B. Green boxes are shared by all models, and blue boxes belong to one model, namely its projections and its source and target biases.

Projections and biases. Multimodal models connect an image encoder to a language model by projecting the encoder's features into the language model's input space [Tsimpoukelli et al., 2021; Liu et al., 2023]. We connect each model-layer to the transformer the same way, with learned projections to and from its width ddd, Pm,ℓinP^{\mathrm{in}}_{m,\ell}Pm,ℓin and Pm,ℓoutP^{\mathrm{out}}_{m,\ell}Pm,ℓout. Inside the transformer, all models share parameters. To give these shared parameters model-layer specific behavior, we add a model-layer bias to the input of every self-attention, cross-attention and feed-forward step. We learn one vector for each model-layer as a source and one as a target, em,ℓsrce^{\mathrm{src}}_{m,\ell}em,ℓsrc and em,ℓtgte^{\mathrm{tgt}}_{m,\ell}em,ℓtgt. Each block of the transformer learns its own projections of these vectors into each step:Encoder block bDecoder block b′Self-attentionRb esrcRb′ etgtCross-attention—Cb′ etgt (queries),Sb′ esrc (memory)Feed-forwardUb esrcUb′ etgt\begin{array}{lcc} & \text{Encoder block } b & \text{Decoder block } b'\\[4pt] \text{Self-attention} & R_b\, e^{\mathrm{src}} & R_{b'}\, e^{\mathrm{tgt}}\\[2pt] \text{Cross-attention} & \text{—} & C_{b'}\, e^{\mathrm{tgt}}\ \text{(queries)}, \quad S_{b'}\, e^{\mathrm{src}}\ \text{(memory)}\\[2pt] \text{Feed-forward} & U_b\, e^{\mathrm{src}} & U_{b'}\, e^{\mathrm{tgt}} \end{array}Self-attentionCross-attentionFeed-forwardEncoder block bRbesrc—UbesrcDecoder block b′Rb′etgtCb′etgt (queries),Sb′esrc (memory)Ub′etgt

Mixture of experts. Earlier translators learn one mapping per pair of models. We instead hold all of these mappings in shared parameters by making each block's feed-forward step a mixture of experts [Shazeer et al., 2017]. Experts can then specialize to groups of model-layers while all of them stay shared (Appendix A).

Attention. Models differ in depth, and the same information can sit at different depths, so the translator learns which source layers feed each target layer. Thus, we construct each attention step to read every layer. Across tokens, attention reads only the last www tokens, given that the source's hidden states encode their preceding context (Appendix A). Its cost therefore grows linearly with document length, while prefill grows quadratically.

Translating a document. We now follow a document from the source to the cache. Each source hidden state is first normalized and projected into the transformer:hi,ℓ=Psrc,ℓin RMS(xi,ℓsrc),ℓ=0,…,Lsrc(1)h_{i,\ell} = P^{\mathrm{in}}_{\mathrm{src},\ell}\,\mathrm{RMS}\big(x^{\mathrm{src}}_{i,\ell}\big), \qquad \ell = 0, \dots, L_{\mathrm{src}} \qquad (1)hi,ℓ=Psrc,ℓinRMS(xi,ℓsrc),ℓ=0,…,Lsrc(1)

The encoder sees only the source, so its output, the memory μ\muμ, is computed once and reused for every target. An encoder block Encb\mathrm{Enc}_bEncb applies self-attention and then the experts (Figure 2). The memory is the output of NencN_{\mathrm{enc}}Nenc stacked blocks:h′=h+SelfAttn(RMS(h)+Rb esrc)Encb(h)=h′+MoE(RMS(h′), Ub esrc)μ=EncNenc∘⋯∘Enc1(h)(2)\begin{aligned} h' &= h + \mathrm{SelfAttn}\big(\mathrm{RMS}(h) + R_b\, e^{\mathrm{src}}\big)\\ \mathrm{Enc}_b(h) &= h' + \mathrm{MoE}\big(\mathrm{RMS}(h'),\ U_b\, e^{\mathrm{src}}\big)\\[6pt] \mu &= \mathrm{Enc}_{N_{\mathrm{enc}}} \circ \cdots \circ \mathrm{Enc}_1(h) \end{aligned} \qquad (2)h′Encb(h)μ=h+SelfAttn(RMS(h)+Rbesrc)=h′+MoE(RMS(h′), Ubesrc)=EncNenc∘⋯∘Enc1(h)(2)

Figure 2

Inside the encoder. Every block attends over all source layers of the last 8 tokens, then routes each hidden state to its experts, and the source bias enters both steps. The output is the source memory. Window and expert counts are those of our trained translator.

Because the translator crosses model families, source and target often use different tokenizers. We therefore initialize the decoder's states from the target's embeddings of the document's tokens. Here too we learn a projection for each model. The decoder predicts L′≤LtgtL' \le L_{\mathrm{tgt}}L′≤Ltgt hidden states per token, all starting from the projected embedding:yj,ℓ′(0)=Ptgtemb RMS(xj,0tgt),ℓ′=0,…,L′−1(3)y^{(0)}_{j,\ell'} = P^{\mathrm{emb}}_{\mathrm{tgt}}\,\mathrm{RMS}\big(x^{\mathrm{tgt}}_{j,0}\big), \qquad \ell' = 0, \dots, L' - 1 \qquad (3)yj,ℓ′(0)=PtgtembRMS(xj,0tgt),ℓ′=0,…,L′−1(3)

A decoder block Decb′\mathrm{Dec}_{b'}Decb′ applies self-attention, cross-attention into the memory and then the experts (Figure 3). The output of NdecN_{\mathrm{dec}}Ndec stacked blocks is the decoder's prediction:y′=y+SelfAttn(RMS(y)+Rb′ etgt)y′′=y′+CrossAttn(RMS(y′)+Cb′ etgt, RMS(μ+Sb′ esrc))Decb′(y)=y′′+MoE(RMS(y′′), Ub′ etgt)y=DecNdec∘⋯∘Dec1(y(0))(4)\begin{aligned} y' &= y + \mathrm{SelfAttn}\big(\mathrm{RMS}(y) + R_{b'}\, e^{\mathrm{tgt}}\big)\\ y'' &= y' + \mathrm{CrossAttn}\big(\mathrm{RMS}(y') + C_{b'}\, e^{\mathrm{tgt}},\ \mathrm{RMS}(\mu + S_{b'}\, e^{\mathrm{src}})\big)\\ \mathrm{Dec}_{b'}(y) &= y'' + \mathrm{MoE}\big(\mathrm{RMS}(y''),\ U_{b'}\, e^{\mathrm{tgt}}\big)\\[6pt] y &= \mathrm{Dec}_{N_{\mathrm{dec}}} \circ \cdots \circ \mathrm{Dec}_1\big(y^{(0)}\big) \end{aligned} \qquad (4)y′y′′Decb′(y)y=y+SelfAttn(RMS(y)+Rb′etgt)=y′+CrossAttn(RMS(y′)+Cb′etgt, RMS(μ+Sb′esrc))=y′′+MoE(RMS(y′′), Ub′etgt)=DecNdec∘⋯∘Dec1(y(0))(4)

Each target layer ℓ\ellℓ then reads its own learned mix of these hidden states, with weights λℓ,ℓ′tgt\lambda^{\mathrm{tgt}}_{\ell,\ell'}λℓ,ℓ′tgt, and leaves through its own projection back to the target's width:x^j,ℓtgt=Ptgt,ℓout RMS(∑ℓ′λℓ,ℓ′tgt yj,ℓ′),ℓ=0,…,Ltgt−1(5)\hat x^{\mathrm{tgt}}_{j,\ell} = P^{\mathrm{out}}_{\mathrm{tgt},\ell}\,\mathrm{RMS}\Big(\textstyle\sum_{\ell'} \lambda^{\mathrm{tgt}}_{\ell,\ell'}\, y_{j,\ell'}\Big), \qquad \ell = 0, \dots, L_{\mathrm{tgt}} - 1 \qquad (5)x^j,ℓtgt=Ptgt,ℓoutRMS(∑ℓ′λℓ,ℓ′tgtyj,ℓ′),ℓ=0,…,Ltgt−1(5)

Figure 3

Inside the decoder. The source memory is already computed. Every block attends over the predictions of the last 8 target tokens, reads the source memory with cross-attention, then routes to its experts, and the target bias enters all three steps. The output projection returns each prediction to the target's width.

Finally, the target's own frozen attention weights turn the predicted hidden states into keys and values, which form the translated cache C^\hat{\mathcal{C}}C^. For each layer ℓ\ellℓ:K^ℓ=RoPE(Normℓ(X^ℓtgt) WℓK),V^ℓ=Normℓ(X^ℓtgt) WℓV(6)\hat K_\ell = \mathrm{RoPE}\big(\mathrm{Norm}_\ell(\hat X^{\mathrm{tgt}}_\ell)\, W^K_\ell\big), \qquad \hat V_\ell = \mathrm{Norm}_\ell(\hat X^{\mathrm{tgt}}_\ell)\, W^V_\ell \qquad (6)K^ℓ=RoPE(Normℓ(X^ℓtgt)WℓK),V^ℓ=Normℓ(X^ℓtgt)WℓV(6)

1^{1}1 The source's final output also enters the encoder, and TTT does not predict the target's final output, which only produces next-token logits.

4Training

We train all 42 directions jointly in two stages, with every base model frozen. In each step, every target trains on one document. Another model reads that document, or for a quarter of documents, the target itself.

Stage 1: cache fitting. We first fit the translated cache to the target's native cache Ctgt\mathcal{C}^{\mathrm{tgt}}Ctgt of the same document. This gives a direct signal at every token, layer and head:LMSE=1N∑ℓ, j, h(∥Kj,ℓ,htgt−K^j,ℓ,h∥2(sℓ,hK)2+∥Vj,ℓ,htgt−V^j,ℓ,h∥2(sℓ,hV)2)(7)\mathcal{L}_{\mathrm{MSE}} = \frac{1}{N} \sum_{\ell,\, j,\, h} \left( \frac{\lVert K^{\mathrm{tgt}}_{j,\ell,h} - \hat K_{j,\ell,h} \rVert^2}{(s^K_{\ell,h})^2} + \frac{\lVert V^{\mathrm{tgt}}_{j,\ell,h} - \hat V_{j,\ell,h} \rVert^2}{(s^V_{\ell,h})^2} \right) \qquad (7)LMSE=N1ℓ,j,h∑((sℓ,hK)2∥Kj,ℓ,htgt−K^j,ℓ,h∥2+(sℓ,hV)2∥Vj,ℓ,htgt−V^j,ℓ,h∥2)(7)

The sum runs over the NNN K/V entries the target keeps.2^{2}2 Keys and values differ in scale across layers and heads, so we divide each head's error by the RMS of its native keys or values, sℓ,hKs^K_{\ell,h}sℓ,hK or sℓ,hVs^V_{\ell,h}sℓ,hV. Every head then counts equally, and so do keys and values.

Stage 2: distillation. Stage 1 treats every error in the cache alike, but some errors change the target's output far more than others. In stage 2 we therefore train on the target's output distribution, teacher-forcing a question about the document and its answer, aaa. We minimize the KL divergence between the target's next-token distributions given its native cache and given the translated cache:LKL=1∣a∣∑k=1∣a∣KL(ptgt(⋅∣Ctgt,a<k) ∥ ptgt(⋅∣C^,a<k))(8)\mathcal{L}_{\mathrm{KL}} = \frac{1}{|a|} \sum_{k=1}^{|a|} \mathrm{KL}\big(p_{\mathrm{tgt}}(\cdot \mid \mathcal{C}^{\mathrm{tgt}}, a_{<k}) \,\big\|\, p_{\mathrm{tgt}}(\cdot \mid \hat{\mathcal{C}}, a_{<k})\big) \qquad (8)LKL=∣a∣1k=1∑∣a∣KL(ptgt(⋅∣Ctgt,a<k)ptgt(⋅∣C^,a<k))(8)

5Stability

Each step computes one loss per target, and their gradients on the shared parameters differ several-fold in norm. A plain average would let the targets with the largest gradients dominate. As in GradNorm [Chen et al., 2018], we instead rescale each target's gradient gmg_mgm to the mean norm before averaging:ν=1∣M∣∑m∈M∥gm∥gˉ=1∣M∣∑m∈Mν∥gm∥ gm(9)\begin{aligned} &\nu = \frac{1}{|\mathcal{M}|} \sum_{m \in \mathcal{M}} \lVert g_m \rVert\\ &\bar g = \frac{1}{|\mathcal{M}|} \sum_{m \in \mathcal{M}} \frac{\nu}{\lVert g_m \rVert}\, g_m \end{aligned} \qquad (9)ν=∣M∣1m∈M∑∥gm∥gˉ=∣M∣1m∈M∑∥gm∥νgm(9)

We then clip the shared gradient gˉ\bar ggˉ and each target's own gradient to norm 1.

2^{2}2 Sliding-window layers keep only the tokens in their window. Linear-attention layers keep no K/V entries, so for them the loss instead matches the layer's input at each token and its final convolution and recurrent states.

6Results

We train a 2.35B-parameter translator on seven models from four families: Qwen3.5 9B, Qwen3 14B, Llama 3.1 8B, Gemma 3 12B, Gemma 4 12B, Ministral 3 8B and Ministral 3 14B (Appendix B). Retention is the target's accuracy with the translated cache as a percentage of its accuracy with its native cache, averaged over three seeds. Since a weaker source limits what its cache can carry, we also report retention against the weaker of the two models.

7Across families

On documents of up to 8,192 tokens, the length used in training, retention at full depth averages 96.9% over 12 tasks and all 42 directions, with a worst direction of 93.1% (Figure 4a). Against the weaker model it averages 100.3% (Figure 4b). Tasks absent from training retain as much as tasks in the training data, 97.4% against 96.5% (Figure 5).

Figure 4

Retention for all 42 directions at full depth, averaged over 12 tasks and 3 seeds. Rows are sources and columns are targets. The last column averages each source over its six targets, and the last row averages each target over its six sources. (a) Against the target reading its native cache. (b) Against the weaker of the two models reading its native cache.

Figure 5

Retention per task, averaged over the 42 directions, at full depth over 3 seeds. Left: tasks whose training splits are in the training data (MMLU through its auxiliary training set). Right: tasks absent from training. Values above 100 mean the translated cache scored higher than the native reference.

8Long documents

Because the cost of speculative encoding grows linearly with document length while prefill grows quadratically, translation cuts latency most on long documents. To push this further, we vary L′L'L′, the number of hidden states the decoder predicts per token, which shrinks the translator's computation with little loss in retention. Retention does decline as documents grow longer, which we hope to address in future work.

Figure 6

Speedup in time to first token against retention, over all 42 directions. Each curve is one translator, with points at 32k, 64k and 128k tokens. Speedup is the median over directions of native prefill time divided by translated time, on one H200 with vLLM. Retention is the mean over directions and three seeds.

We test all 42 directions on multiple-choice questions over documents of 32k, 64k and 128k tokens, with the source's memory already computed (Appendix B). The speedup grows with length, and predicting fewer hidden states per token pushes it further. At 128k, full depth is 2.5× faster than prefill, while L′=8L' = 8L′=8 and 444 reach 6.1× and 7.5× and give up only 1–2 points of retention. At full depth, retention falls from 92% at 32k to 83% at 128k, on documents 4 to 16 times longer than any seen in training.

9Compression

At long contexts, a model receiving another model's context rarely needs all of it. To answer a question about a 128k-token document, the target may need only a few passages, yet the translated cache holds every token. We therefore built a query-conditioned compressor that, given the target's question QQQ, shrinks the translated cache by a ratio rrr.3^{3}3 It works in two steps, select then synthesize.

10Initialization

For the translator, stage 1 gives distillation a good starting point by fitting the translated cache to the target's native cache. A compressed cache has no native counterpart to fit, so we start instead from SnapKV [Li et al., 2024], which compresses a cache without training.

SnapKV keeps the positions the question attends to most (Figure 7). The target reads QQQ after the translated cache. For head hhh of full-attention layer ℓ\ellℓ, αℓ,h\alpha^{\ell,h}αℓ,h are the usual attention weights from the question's queries to the translated keys:αℓ,h=softmax(qℓ,h K^ℓ,h⊤/dh)sj,ℓ=max⁡h, k αk,jℓ,hsj=1L∑ℓsj,ℓ∑j′∈Dsj′,ℓ(10)\begin{aligned} &\alpha^{\ell,h} = \mathrm{softmax}\big(q_{\ell,h}\, \hat K_{\ell,h}^{\top} / \sqrt{d_h}\big)\\ &s_{j,\ell} = \max_{h,\,k}\ \alpha^{\ell,h}_{k,j}\\ &s_j = \frac{1}{L} \sum_{\ell} \frac{s_{j,\ell}}{\sum_{j' \in D} s_{j',\ell}} \end{aligned} \qquad (10)αℓ,h=softmax(qℓ,hK^ℓ,h⊤/dh)sj,ℓ=h,kmax αk,jℓ,hsj=L1ℓ∑∑j′∈Dsj′,ℓsj,ℓ(10)

We keep the decoder's hidden states yyy (before PoutP^{\mathrm{out}}Pout) at the B=∣D∣/rB = |D|/rB=∣D∣/r highest-scoring positions j1,…,jBj_1, \dots, j_Bj1,…,jB. Our compressor starts from this selection, which distillation then improves.

Figure 7

SnapKV selection, with illustrative weights. Each question token attends over the translated keys. Each position's score is the largest weight it receives, and the decoder output is kept at the top B positions.

11Architecture

The compressor mirrors the decoder (Figure 8), with the decoder's output yyy as its memory in place of the source memory, so each kept state can read the whole translated document. To know what to gather, the kept states also read the question. The compressor's input is the kept hidden states followed by the target's hidden states for the question alone. The question enters through the target's input projections, and λcmp\lambda^{\mathrm{cmp}}λcmp mixes its layers down to the decoder's L′L'L′ hidden states, the reverse of (5):zi,ℓ′(0)=yji,ℓ′,i=1,…,BzB+k,ℓ′(0)=∑ℓλℓ,ℓ′cmp Ptgt,ℓin RMS(xk,ℓtgt),k=1,…,∣Q∣(11)\begin{aligned} &z^{(0)}_{i,\ell'} = y_{j_i,\ell'}, \qquad i = 1, \dots, B\\ &z^{(0)}_{B+k,\ell'} = \textstyle\sum_{\ell} \lambda^{\mathrm{cmp}}_{\ell,\ell'}\, P^{\mathrm{in}}_{\mathrm{tgt},\ell}\,\mathrm{RMS}\big(x^{\mathrm{tgt}}_{k,\ell}\big), \qquad k = 1, \dots, |Q| \end{aligned} \qquad (11)zi,ℓ′(0)=yji,ℓ′,i=1,…,BzB+k,ℓ′(0)=∑ℓλℓ,ℓ′cmpPtgt,ℓinRMS(xk,ℓtgt),k=1,…,∣Q∣(11)z′=z+SelfAttn(RMS(z)+Rb∗ etgt)z′′=z′+CrossAttn(RMS(z′)+Cb∗ etgt, RMS(y+Sb∗ etgt))Cmpb∗(z)=z′′+MoE(RMS(z′′), Ub∗ etgt)z=CmpNcmp∘⋯∘Cmp1(z(0))(12)\begin{aligned} z' &= z + \mathrm{SelfAttn}\big(\mathrm{RMS}(z) + R_{b^*}\, e^{\mathrm{tgt}}\big)\\ z'' &= z' + \mathrm{CrossAttn}\big(\mathrm{RMS}(z') + C_{b^*}\, e^{\mathrm{tgt}},\ \mathrm{RMS}(y + S_{b^*}\, e^{\mathrm{tgt}})\big)\\ \mathrm{Cmp}_{b^*}(z) &= z'' + \mathrm{MoE}\big(\mathrm{RMS}(z''),\ U_{b^*}\, e^{\mathrm{tgt}}\big)\\[6pt] z &= \mathrm{Cmp}_{N_{\mathrm{cmp}}} \circ \cdots \circ \mathrm{Cmp}_1\big(z^{(0)}\big) \end{aligned} \qquad (12)z′z′′Cmpb∗(z)z=z+SelfAttn(RMS(z)+Rb∗etgt)=z′+CrossAttn(RMS(z′)+Cb∗etgt, RMS(y+Sb∗etgt))=z′′+MoE(RMS(z′′), Ub∗etgt)=CmpNcmp∘⋯∘Cmp1(z(0))(12)

As in (5), each target layer then reads its own mix of the kept hidden states and leaves through its own projection:x^i,ℓ∗=Ptgt,ℓout RMS(∑ℓ′λℓ,ℓ′tgt zi,ℓ′),i=1,…,B(13)\hat x^{*}_{i,\ell} = P^{\mathrm{out}}_{\mathrm{tgt},\ell}\,\mathrm{RMS}\Big(\textstyle\sum_{\ell'} \lambda^{\mathrm{tgt}}_{\ell,\ell'}\, z_{i,\ell'}\Big), \qquad i = 1, \dots, B \qquad (13)x^i,ℓ∗=Ptgt,ℓoutRMS(∑ℓ′λℓ,ℓ′tgtzi,ℓ′),i=1,…,B(13)

Figure 8

Inside the compressor. The kept hidden states and the question's hidden states enter together, and the question passes through the target's input projections. Every block attends over all of them without a window, reads the decoder output at every document position with cross-attention, then routes to its experts, and the target bias enters all three steps. Only the kept positions leave through the output projection.

The target's frozen attention weights turn these into the compressed cache C^∗\hat{\mathcal{C}}^{*}C^∗, as in (6). The compressor starts from the translator's last NcmpN_{\mathrm{cmp}}Ncmp decoder blocks with their output maps at zero, so training starts from the SnapKV selection (Appendix A).

12Training

We train one compressor per translator for all 42 directions, keeping the translator and the base models frozen. As in stage 2, we teacher-force the question QQQ and its answer aaa, and minimize the KL divergence between the target's next-token distributions given its native cache and given the compressed cache:Lcmp=1∣a∣∑k=1∣a∣KL(ptgt(⋅∣Ctgt,Q,a<k) ∥ ptgt(⋅∣C^∗,Q,a<k))(14)\mathcal{L}_{\mathrm{cmp}} = \frac{1}{|a|} \sum_{k=1}^{|a|} \mathrm{KL}\big(p_{\mathrm{tgt}}(\cdot \mid \mathcal{C}^{\mathrm{tgt}}, Q, a_{<k}) \,\big\|\, p_{\mathrm{tgt}}(\cdot \mid \hat{\mathcal{C}}^{*}, Q, a_{<k})\big) \qquad (14)Lcmp=∣a∣1k=1∑∣a∣KL(ptgt(⋅∣Ctgt,Q,a<k)ptgt(⋅∣C^∗,Q,a<k))(14)

We use the same gradient rescaling (9) and clipping as for the translator.

13Results

We evaluate the compressor on the long documents of Results, at 16×16\times16×, 64×64\times64× and 128×128\times128× for all three translators, over three seeds, and show the full-depth translator in Figure 9.

Figure 9

Retention against document length for the full translated cache and for compressed caches at 16×, 64× and 128×, with the full-depth translator. Mean over three seeds and 42 directions.

At 32k and 64k, compression keeps retention within 2 points of the full translated cache, even at 128×128\times128×. At 128k, every ratio beats the full cache, by up to 4.3 points at 64×64\times64×. Decoder depth does not meaningfully change these results: L′=8L' = 8L′=8 and L′=4L' = 4L′=4 translators follow the same pattern, gaining 4.0 to 5.1 points at 128k and 64×64\times64×. Compression helps most on the longest documents, where most of the context is noise for any one question.

3^{3}3 We compress only the full-attention layers. Sliding-window and linear-attention layers keep their translated cache, whose size is already bounded.

14Conclusion

We introduced speculative encoding, a single translator that carries computed context among seven models from four families, in all 42 directions. On documents of up to 8k tokens, the translated cache keeps 96.9% of the target's native accuracy. On long documents, the target starts answering 4× faster than with prefill at 32k tokens while keeping over 90% of its accuracy, and the speedup grows with length. A question-conditioned compressor then shrinks the cache up to 128× while staying within 2 points of the full translated cache and beating it at long contexts.

We see practical uses wherever models hand context to one another. A router can switch models mid-task without the new model rereading everything that came before. In a multi-agent swarm, one agent can ask another a specific question and receive just the part of its context that answers it. As systems grow to more models and more agents, reading a context once can be enough.

Want to keep up with our next AI experiments? Follow us on @RampLabs. We’re also hiring across roles at Ramp.

15Appendix A: implementation details

Mixture of experts. Each feed-forward step has one always-on expert and 8 routed experts, of which each hidden state uses 2 [Dai et al., 2024]. The router reads the hidden state together with its model-layer bias, and expert load is balanced without an auxiliary loss [Wang et al., 2024].

Token alignment. Source and target split the document into different tokens. Each target token reads the memory of the last www source tokens whose text ends at or before its own, and both are placed on the target's position axis for RoPE.

Compressor. Its blocks start as copies of the translator's last NcmpN_{\mathrm{cmp}}Ncmp decoder blocks, with attention output maps and feed-forward down projections at zero. The compressor therefore starts as the identity, and its first output is the SnapKV selection.

16Appendix B: training and evaluation setupSettingValueParameters2.35BWidth d768Feed-forwardalways-on MLP + top-2 of 8 expertsWindow w8 tokensBlocks Nenc, Ndec, Ncmp2, 8, 2Hidden states per token L′Ltgt (full depth), 8 or 4Training documentsup to 8,192 tokensStage 1 / Stage 217k steps at lr 3e-4 / 8k steps at lr 1e-5Seeds3 per translator\begin{array}{ll}\text{Setting} & \text{Value}\\[6pt] \text{Parameters} & \text{2.35B}\\[6pt] \text{Width }d & \text{768}\\[6pt] \text{Feed-forward} & \text{always-on MLP + top-2 of 8 experts}\\[6pt] \text{Window }w & \text{8 tokens}\\[6pt] \text{Blocks }N_{\mathrm{enc}}\text{, }N_{\mathrm{dec}}\text{, }N_{\mathrm{cmp}} & \text{2, 8, 2}\\[6pt] \text{Hidden states per token }L' & L_{\mathrm{tgt}}\text{ (full depth), 8 or 4}\\[6pt] \text{Training documents} & \text{up to 8,192 tokens}\\[6pt] \text{Stage 1 / Stage 2} & \text{17k steps at lr 3e-4 / 8k steps at lr 1e-5}\\[6pt] \text{Seeds} & \text{3 per translator}\end{array}SettingParametersWidth dFeed-forwardWindow wBlocks Nenc, Ndec, NcmpHidden states per token L′Training documentsStage 1 / Stage 2SeedsValue2.35B768always-on MLP + top-2 of 8 experts8 tokens2, 8, 2Ltgt (full depth), 8 or 4up to 8,192 tokens17k steps at lr 3e-4 / 8k steps at lr 1e-53 per translator

Data. Stage 2 trains on question-answer pairs from still-MCQ (our multiple-choice reading set), Qasper, HotpotQA, MuSiQue, ARC-Challenge, HellaSwag, WinoGrande, MMLU's auxiliary training set and GSM8K, and on continuations of PG-19 books and WikiText articles.

Evaluation. Each direction is scored on 2,395 questions from 12 tasks, about 200 per task, from still-MCQ, QuALITY, MMLU, SQuAD, GSM8K, ARC-C, BoolQ, HellaSwag, NarrativeQA, OpenBookQA, RACE and WinoGrande.

Long documents. Each direction and length is scored on 20 documents with 8 multiple-choice questions each, balanced across code, finance, Gutenberg and legal text.

17References

Alabdulkareem et al., 2026. Swarm Telepathy: Prefill-Free KV-Cache Transfer Across Families. arXiv:2610.15095.

Chen et al., 2018. GradNorm: Gradient Normalization for Adaptive Loss Balancing in Deep Multitask Networks. arXiv:1711.02257.

Chen et al., 2026. See What I See, Know What I Think: Dense Latent Communication Across Heterogeneous Agents. arXiv:2606.13594.

Dai et al., 2024. DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models. arXiv:2401.06066.

DeepSeek-AI, 2026. DeepSeek-V4.1-Flash: Pushing the Limits of KV Cache Compression. arXiv:2609.19969.

Dery et al., 2026. Latent Space Communication via K-V Cache Alignment. arXiv:2601.06123.

Fu et al., 2026. Cache-to-Cache: Direct Semantic Communication Between Large Language Models. ICLR 2026. arXiv:2510.03215.

Geist, 2026. PorTAL: Portable Task Adapters for LLMs. Ramp Labs. https://labs.ramp.com/research

Heo et al., 2026. Cross-Model KV Cache Transfer in LLM Families: A Closed-Form Linear Mapping for Prefill Reuse. arXiv:2608.03893.

Horton et al., 2024. KV Prediction for Improved Time to First Token. arXiv:2410.08391.

Jaegle et al., 2021. Perceiver: General Perception with Iterative Attention. arXiv:2103.03206.

Lee et al., 2026. KV Cache Translation across Heterogeneous Large Language Models. arXiv:2607.28979.

Li et al., 2024. SnapKV: LLM Knows What You are Looking for Before Generation. arXiv:2404.14469.

Liu et al., 2023. Visual Instruction Tuning. arXiv:2304.08485.

Liu et al., 2026. Dual-Cache Latent Space Communication between Heterogeneous Language Models. arXiv:2608.20617.

O'Neill et al., 2026. Still: Amortized KV Cache Compaction in a Single Forward Pass. arXiv:2606.07878.

Qu et al., 2026. CacheBridge: Efficient Cross-Model KV Transfer for Multi-Model LLM Serving. arXiv:2609.00891.

Rossi et al., 2026a. Latent Cache Flow: Model-to-Model Communication Without Text. arXiv:2605.22863.

Rossi et al., 2026b. Receiver-Conditioned Latent Communication gives 94% CacheBack. arXiv:2609.32046.

Shazeer et al., 2017. Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer. arXiv:1701.06538.

Sun et al., 2024. You Only Cache Once: Decoder-Decoder Architectures for Language Models. arXiv:2405.05254.

Tsimpoukelli et al., 2021. Multimodal Few-Shot Learning with Frozen Language Models. arXiv:2106.13884.

Wang et al., 2024. Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts. arXiv:2408.15664.

Zweiger et al., 2026. Fast KV Compaction via Attention Matching. arXiv:2602.16284.

Cite this work

@article{baselabs2026-speculative-encoding-many-to-many-cache-translation, title = {Speculative Encoding: Many-to-Many Cache Translation}, author = {Geist, B. and Villeneuve, T.}, journal = {Base Labs}, year = {2026}, number = {000}, url = {https://labs.baseten.co/000}, }

Related from the lab01

Bison-1 and Groundhog-1: frontier American-backbone decision modelsRollout·NOV 202602

Can gradient alignment make supervision on-policy? Rollout·NOV 202603

The bias of on-policy self-distillationRollout·NOV 2026

Source

Baseten Base Labs: Model Research