Optimizing Draft Models for Long-Context Inference: KV and Index Sharing
This article examines why draft models become a cost bottleneck in long-context speculative decoding, and how KV sharing and index sharing address it. It explains the structural savings in memory, prefill, and prefix cache behavior, the cross-step selection stability that makes shared indexes viable, the metrics to watch during evaluation, and the engineering practices needed to adopt the approach incrementally.
1. The Problem: Long Contexts Amplify Draft Model Costs
In the past year or two of inference-side optimization, speculative decoding has become hard to avoid in long-context serving. The core logic is straightforward: a lightweight draft model guesses several candidate tokens in one pass, and the target model verifies them in parallel, accepting the longest correct prefix. Because a single target forward pass can validate multiple positions, the end-to-end number of decoding steps drops significantly.
But once context length grows from a few thousand tokens to hundreds of thousands or more, the cost-effectiveness of this scheme starts to be questioned, for three reasons:
- The attention pattern has changed. To control attention cost over long sequences, the mainstream approach is native sparse attention: each layer is equipped with a lightweight indexer that selects a fixed number of historical positions for each query to attend to. In other words, the target model is already making the “where to look” decision itself, and writing the selected keys and values (KV) into its cache.
- Draft-side cost has not dropped accordingly. Conventional block-parallel draft models follow the dense-model playbook, maintaining their own separate context cache that either retains everything or truncates with a sliding window. The better the target model gets at compressing its own KV, the more glaring the share taken by the draft model’s cache becomes.
- The cost is more than GPU memory. Cache growth also affects prefill latency, prefix cache hit rate, and the concurrency a single machine can support — the three factors that directly determine the unit cost of inference serving.
Put differently, the problem is not that “the draft model is not accurate enough.” It is that, in order to stay accurate, the draft model carries a context that duplicates the target model’s and is even more bloated.
2. The Core Idea: KV Sharing and Index Sharing
One proven approach is fairly plain: since the target model already stores KV and has already selected positions for each query, the draft layers need neither to store another copy nor to compute the selection again.
In practice this becomes two designs:
- KV sharing: draft layers are paired one-to-one with target layers and read the KV directly from the target cache; the draft model maintains no context cache of its own.
- Index sharing: draft layers do not run their own scoring/indexing process, but reuse the position set selected by the target layer’s indexer, attending only at those positions.
The difference is obvious in pseudocode:
# Conventional block-parallel draft: own cache + own indexfor layer in draft_layers:draft_cache.update(hidden_states) # extra memoryidx = draft_indexer.score_and_select(q) # extra scoring costout = sparse_attention(q, draft_cache.kv, idx)# Shared draft: read target-side results onlyfor layer in draft_layers:kv = target_cache[layer.paired_layer] # zero extra cacheidx = target_indexer_output[layer.paired_layer]out = sparse_attention(q, kv, idx)
The benefits of this design are structural: the draft model’s memory footprint drops from being linearly related to context length to being roughly constant, prefill no longer needs to traverse history again on the draft side, and the prefix cache key returns to a single source, so hit rate naturally recovers.
3. The Precondition: Stability of Cross-Step Selection
Sharing indexes means that multiple positions inside a draft block use the same position selection result, produced one step earlier. This may look aggressive, but whether it holds depends on a measurable quantity: how much the sparse selection made one step ahead overlaps with the position set that each subsequent token would have selected on its own.
Observations on native sparse attention models show that this overlap covers roughly ninety percent of what each subsequent token would select by itself. That number deserves more attention than any end-to-end benchmark score, because the whole method rests on it. In engineering terms, it can be understood and validated like this:
def overlap_rate(target_idx_step_t, target_idx_step_t_plus_k):# Measure the intersection ratio between the selection k steps ahead and the actual oneinter = target_idx_step_t & target_idx_step_t_plus_kreturn len(inter) / len(target_idx_step_t_plus_k)
If the overlap decays noticeably with context length or across task types (retrieval-oriented vs. generation-oriented), fallback strategies are needed — for example, adapting by block length, keeping an independent index at critical layers, or falling back to per-token selection for low-overlap segments.
4. What to Measure
Compared with comparable block-parallel draft schemes under the same training recipe, the observable gains concentrate at two levels:
- Acceptance length: more tokens accepted per decoding step on average, the most direct efficiency metric for speculative decoding.
- Differences across task tiers: a moderate lead on general tasks, with the gap widening further on long-context and agentic tasks. The reason is easy to understand — the longer the context and the more tool calls and multi-hop reasoning involved, the more wasteful the draft side’s duplicated cache maintenance becomes, and the more pronounced the relative advantage of the shared approach.
For evaluation, it is advisable to cover at least the following matrix to avoid being misled by a single metric:
| Dimension | Suggested values |
|---|---|
| Context length | 4K / 32K / 128K |
| Task type | general generation, long-document retrieval, multi-turn tool calling |
| Metrics | average acceptance length, end-to-end throughput, time to first token, peak GPU memory, prefix cache hit rate |
5. Engineering Implementation Notes
- Layer pairing strategy: the mapping between draft layers and target layers needs explicit design, and the inference framework should expose the target cache in read-only fashion to avoid implicit copies.
- Cache lifecycle: eviction, paging, and offloading policies for the shared cache should be unified with the target model’s, so the two management logics do not interfere with each other.
- Consistency of sparse selection: index results must stay stable within the same batch, and batching must prevent the selection sets of different requests from bleeding into one another.
- Observability: bring acceptance length, index overlap, and cache hit rate into logging services and monitoring alerts; only then can you tell which layer the gains actually come from.
- Elastic resources: training and evaluation can rely on container platforms and object storage for elastic compute and datasets, using general-purpose capabilities to build a reproducible experiment pipeline.
6. Conclusion
The cost bottleneck of long-context inference is shifting from “how fast can we compute” to “how little can we store.” The value of the shared draft model is to bring that insight down to the implementation level: do not store the context twice, do not make the sparse decision twice, and let the draft model return to a purely predictive role. For teams building long-context inference services or agent platforms, this approach offers a low-cost, incrementally verifiable optimization path — first validate the precondition with the overlap metric, then roll out the shared cache gradually, and finally evaluate end-to-end gains by task tier.
