cd /news/artificial-intelligence/speculative-encoding-many-to-many-ca… · home › topics › artificial-intelligence › article
[ARTICLE · art-177969] src=twitter.com ↗ pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Speculative Encoding: Many-to-Many Cache Translation

Researchers Ben Geist and Thomas Villeneuve introduced speculative encoding, a single network that translates hidden states directly between models, covering all 42 directions across seven models from four families. On documents up to 8k tokens the translated cache retains 96.9% of the target model's native accuracy, and on 32k-token documents the target answers 4× faster than prefilling the text while keeping over 90% of its accuracy. A query-conditioned compressor can shrink the translated cache to what a question needs, raising retention by 4 points over the full translated cache at 128k tokens and 64× compression.

recommendation

Translate the sender model's hidden states directly into the receiver's K/V cache instead of re-prefilling text; the source measured 4× faster answers at 32k tokens with over 90% accuracy retained.

more in playbook: Inference and self-hosting
read16 min views5 publishedNov 29, 2026
Speculative Encoding: Many-to-Many Cache Translation
Image: source

Researchers: Ben Geist, Thomas Villeneuve

Introduction #

Agents no longer act in isolation. Whether it's routers or multi-agent swarms, models of different sizes and families are increasingly passing context to one another 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 prefill repeats much of what the sending model has already computed.

Our earlier work, Latent Briefing, shared context between agents by compacting the receiving model's cache, but the receiving model still had to prefill the text itself. 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 n models requires n(n−1) separately trained translators.

We introduce speculative encoding, a single network that translates hidden states directly from one model to another. It covers all 42 directions between seven models from four families. On documents up to 8k tokens, the translated cache keeps 96.9% of the target's native accuracy. On 32k-token documents, the target starts answering 4× faster than prefilling the text, while keeping over 90% of its accuracy. A query-conditioned compressor can also shrink the translated cache to what a question needs. At 128k tokens and 64× compression, it raises retention by 4 points over the full translated cache.

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.

Architecture #

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 rather than 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, positional encoding, and attention mechanism.

Setup. Let 𝓜 be a set of frozen models. Model m ∈ 𝓜 has Lₘ layers and width Dₘ. We write xᵐ(i, ℓ) for the hidden state of width Dₘ entering layer ℓ at token i, with layer 0 being the token embedding, and Xᵐ for all the hidden states model m produces over a document. We aim to train one translator T with T(Xˢʳᶜ) = X̂ᵗᵍᵗ for any source and target models πˢʳᶜ, πᵗᵍᵗ ∈ 𝓜 ¹:

Requirements. Three requirements shape the architecture:

  1. 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.
  2. 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.
  3. 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 μ, and the decoder reads μ to predict the target's hidden states. Only the projections and biases are trained to be model specific.

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 d, P ⁱⁿ and P ᵒᵘᵗ. 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 as a target, eˢʳᶜ and eᵗᵍᵗ. Each block of the transformer learns its own projections of these vectors into each step:

Mixture of experts. Earlier translators learned 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, with the same information sitting at different depths depending on the model. Thus, we construct each attention step to read every layer so that the translator learns which source layers feed which target layer. Across tokens, attention reads only the last w 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 target cache.

Each source hidden state is first normalized and projected into the transformer:

The encoder sees only the source, so its output, the memory μ, is computed once and reused for every target. An encoder block applies self-attention and the experts (Figure 2). The memory is the output of Nᵉⁿᶜ stacked blocks:

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′ ≤ Lᵗᵍᵗ hidden states per token, all starting from the projected embedding:

A decoder block applies self-attention, cross-attention into the memory and the experts (Figure 3). The output of Nᵈᵉᶜ stacked blocks is the decoder's prediction:

Each target layer ℓ then reads its own learned mix of these hidden states, with weights λᵗᵍᵗ, and leaves through its own projection back 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 Ĉ. For each layer ℓ :

¹ The source's final output also enters the encoder, and T does not predict the target's final output, which only produces next-token logits.

Training #

We train all 42 directions jointly in two stages, with every base model frozen.

Stage 1: cache fitting. We first fit the translated cache to the target's native cache Cᵗᵍᵗ of the same document. This gives a direct signal at every token, layer and head:

The sum runs over the N K/V entries the target keeps.² 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ᴷ or sⱽ. 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, a. We minimize the KL divergence between the target's next-token distributions given its native cache and given the translated cache:

Stability

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 gₘ to the mean norm before averaging and clip the shared gradient ḡ and each target's own gradient to norm 1.

² 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.

Results #

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.

Across 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).

Long 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′, 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.

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′ = 8 and 4 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.

Compression #

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. Using the same techniques as speculative encoding, we push this further with a query-conditioned compressor that, given the target's question Q, shrinks the translated cache by a ratio r.³ It works in two steps, select then synthesize.

Initialization

For the translation training, 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 Q after the translated cache. For head h of full-attention layer ℓ, α are the usual attention weights from the question's queries to the translated keys:

We keep the decoder's hidden states y (before P ᵒᵘᵗ) at the B = |D|/r highest-scoring positions. Our compressor starts from this selection, which distillation then improves.

Architecture

The compressor mirrors the decoder (Figure 8), with the decoder's output y as its memory in place of the source memory. This allows each kept state to read the whole translated document as well as 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 λᶜᵐᵖ mixes its layers down to the decoder's L′ hidden states, the reverse of (5):

As in (5), each target layer then reads its own mix of the kept hidden states and leaves through its own projection:

The target's frozen attention weights turn these into the compressed cache Ĉ∗, as in (6). The compressor starts from the translator's last Nᶜᵐᵖ decoder blocks with their output maps at zero, so training starts from the SnapKV selection (Appendix A).

Training

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 Q and its answer a, and minimize the KL divergence between the target's next-token distributions given its native cache and given the compressed cache:

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

Results

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

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

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

Conclusion #

We introduced speculative encoding, a single translator that maps one model's hidden states to another's, so the receiving model can skip prefill. On documents of up to 8k tokens, the translated cache keeps 96.9% of the target's native accuracy. On 32k-token documents, the target starts answering 4× faster compared to prefill while keeping over 90% of its accuracy, the speedup growing with length. A query-conditioned compressor can shrink the cache up to 128× while staying within 2 points of the full translated cache, and on the longest documents it beats the full cache.

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.

Appendix A #

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 w 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 Nᶜᵐᵖ 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.

Appendix B #

Setting Value
Parameters 2.35B
Width d 768
Feed-forward always-on MLP + top-2 of 8 experts
Window w 8 tokens
Blocks Nᵉⁿᶜ ,Nᵈᵉᶜ ,Nᶜᵐᵖ 2, 8, 2
Hidden states per token L′ Lᵗᵍᵗ (full depth), 8 or 4
Training documents up to 8,192 tokens
Stage 1 / Stage 2 17k steps at lr 3e-4 / 8k steps at lr 1e-5
Seeds 3 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.

References #

  • 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.
── more in #artificial-intelligence 4 stories · sorted by recency
── more on @ben geist 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/speculative-encoding…] indexed:0 read:16min 2026-11-29 · —