Long-Context Speculative Decoding: KV Cache and Sparse Index Sharing
Sharing historical KV caches and sparse attention indices can reduce the draft model’s overhead in long-context speculative decoding. This article explains the two mechanisms, their dependence on short-term retrieval stability, and the architectural and implementation constraints involved. It also outlines how to evaluate candidate acceptance, memory savings, sampling correctness, and end-to-end throughput without confusing theoretical benefits with deployment results.
1. The Core Problem: Draft Models Also Carry Long-Context Costs
Long-context inference is common in multi-turn conversations, document analysis, code understanding, and agent tasks. As the history grows, the system must process more input and access more historical state at each generation step. Inference cost therefore depends not only on model size, but also on compute, GPU memory capacity, memory bandwidth, and scheduling efficiency.
Speculative decoding reduces the target model’s serial generation overhead. A lower-cost draft model proposes several candidate tokens, and the target model verifies them. When consecutive candidates are accepted, a single verification pass can advance generation by multiple positions.
The draft model, however, is not free. Conventional implementations usually maintain a separate historical key-value cache, or KV cache, for its attention calculations. Even if the draft model is smaller than the target model, this independent cache can become expensive when context lengths reach tens of thousands of tokens or more. It can:
- Consume additional GPU memory, reducing the number of concurrent requests the system can accommodate.
- Add overhead for building, updating, and managing historical state.
- Require prefix reuse to account for both target-side and draft-side state.
- Increase historical cache reads during decoding.
- Complicate scheduling by introducing two sets of state with separate residency and lifecycle requirements.
Optimizing long-context speculative decoding therefore requires more than improving draft prediction accuracy. An equally important question is whether the draft model can avoid storing and retrieving historical information that the target model already maintains.
2. Native Sparse Attention Creates a Basis for Sharing
Dense Attention vs. Sparse Attention
In typical dense causal attention, the current query attends to every valid historical position. As context grows, more historical keys and values generally participate in the attention computation.
Native sparse attention introduces position selection during model design and training. For each query, an indexing or scoring module first selects a subset of historical positions. Attention is then computed over those positions.
The important distinction is not simply that the model “looks at fewer tokens.” The model has learned to perform its tasks under a limited historical access budget. The indexing module is part of the model itself, rather than an inference-time pruning strategy added afterward.
Sparse attention does not eliminate all long-context costs. Index construction, position selection, cache storage, and irregular memory access can still introduce overhead. Actual gains depend on the architecture and implementation, not just the number of positions accessed per query.
Why Sharing Is Worth Investigating
During generation, the target model already has two useful resources:
- Historical KV state stored across its layers.
- Historical positions selected by its indexing modules for the current query.
If the draft model stores its own historical cache and independently determines which positions matter, it may repeat work the target model has already performed.
A sharing architecture changes this relationship. The draft model reuses the target model’s historical representations and retrieval results, allowing more of its resources to be spent on candidate generation.
This is architectural coordination, not simply connecting two otherwise independent models.
3. Two Core Mechanisms: Shared Historical State and Shared Retrieval Positions
KV Sharing: Reducing Duplicate Historical State
KV sharing maps draft layers to corresponding target-model layers. The draft layers then read historical keys and values directly from the target-side cache.
The scope of sharing matters. It primarily concerns historical attention state; it does not mean the draft model requires no runtime memory. Temporary representations within a candidate block, attention queries, intermediate activations, and verification-related state may still consume GPU memory.
KV representations from different models are not automatically compatible. Feasibility depends on factors such as:
- Layer mapping.
- Attention-head organization.
- Representation dimensions.
- Positional encoding.
- Cache layout.
The draft model generally needs to be designed and trained around the target model’s representations. An arbitrary existing draft model cannot simply be connected to the target cache with an expectation of correct behavior.
The main engineering benefit is reducing duplicate state that grows with history length. Whether KV sharing also reduces prefill time depends on whether the draft model must perform additional input processing and how the inference pipeline is organized.
Index Sharing: Avoiding Duplicate Historical Selection
Index sharing goes a step further by reusing historical positions already selected by the target model. Instead of independently scoring historical positions, a draft layer reads KV state at the positions selected by its corresponding target layer and uses that information to generate candidates.
This can reduce draft-side retrieval work and bring the draft model’s historical information access closer to that of the target model.
Index sharing does not imply that every layer uses the same position set. Different layers may rely on different information, so sharing generally needs to preserve layer-level correspondence. Combining all layers’ retrieval positions into one undifferentiated set may hurt candidate quality.
Nor is index sharing equivalent to a fixed sliding window. A sliding window usually retains recent content based on distance. Sparse indexing can select distant positions that are relevant to the current query. These mechanisms preserve information in fundamentally different ways.
4. The Key Assumption: Short-Term Stability of Retrieval Positions
Block-parallel drafting proposes multiple candidate tokens at once. At that point, the target model has not completed full computation for every future position, so it cannot yet provide fresh index results for each future query.
The sharing mechanism must therefore use positions selected at an earlier step to support several subsequent candidate positions. This raises a central question:
Are the historical positions selected for the current query still useful for the next few generation positions?
Some tasks provide a reasonable basis for short-term stability. While generating an explanation, the model may repeatedly refer to the same source passage. During function completion, several positions may depend on the same variable definitions and interface constraints.
Stability is not guaranteed, however. Important historical positions may change quickly when the topic shifts, the referenced object changes, a new tool result arrives, or generation moves to a different source of evidence.
Experiments described in the source material reported that, under certain test conditions, historical positions selected one generation step earlier covered approximately 90% of the positions selected by subsequent queries. This supports the feasibility of index sharing, but the result requires careful interpretation:
- Position coverage is not candidate-token acceptance rate.
- High coverage does not guarantee that all critical evidence is included.
- Results may vary across layers, tasks, and candidate distances.
- Missing a rare but important historical position may matter more than missing many ordinary positions.
A more useful evaluation measures coverage by distance within the candidate block and analyzes it alongside candidate acceptance. This helps establish the effective range of index sharing rather than relying on a single average.
5. How Benefits Translate into Performance
Accepted Tokens per Step Determine Verification Amortization
The direct benefit of speculative decoding depends on how many candidates a target verification pass accepts. If rejection frequently occurs near the beginning of a candidate block, proposing more tokens does not necessarily produce a large speedup.
Reusing the target model’s historical representations and retrieval positions may align the draft model more closely with the target model’s information base, potentially increasing the number of accepted candidates. That benefit must be demonstrated experimentally; it cannot be guaranteed from the architecture alone.
Controlled comparisons described in the source material reported improvements in accepted tokens per step, with more pronounced relative gains on long-context and agent tasks. These results support the technical direction, but they should not be interpreted as a promise of equivalent acceleration in every deployment environment.
Memory Savings May Create More Concurrency Capacity
A simplified estimate for an independent draft cache is:
Draft historical KV memory ≈ 2 × cached draft layers × history length × KV heads × head dimension × bytes per element
The factor of two accounts for keys and values. Actual memory usage also depends on cache blocking, alignment, compression, and metadata, so this formula is only a rough analytical tool.
As an independent draft cache grows with history length, eliminating that duplicate state may free memory for additional concurrent requests. Memory savings do not, however, imply proportional throughput gains. Compute, bandwidth, or scheduling may become the next bottleneck.
Measure Single-Request Speed and Aggregate Throughput Separately
Single-request decoding speed measures how quickly one request generates output. System throughput measures how much useful output the service can produce per second under latency constraints.
A sharing architecture may offer limited gains for a single request yet improve high-concurrency throughput by reducing state occupancy. Conversely, higher aggregate throughput does not prove that individual users experience faster generation.
Performance comparisons should therefore specify whether context length, output length, hardware, concurrency, and latency targets are held constant. Performance percentages without these conditions have limited value.
6. Engineering Requirements
Define Cache Access and Lifecycle Boundaries
Shared caches must preserve causal correctness. The draft model may access only historical state that has been legitimately established for the current request. It must not read uncommitted future information or cross request-isolation boundaries.
An implementation needs clear rules for:
- Distinguishing committed history from temporary candidate state.
- Associating each index result with its generation step.
- Assigning ownership and release responsibility for shared cache blocks.
- Reclaiming temporary state after candidate rejection.
- Keeping shared references valid during request migration or preemption.
Removing one cache does not automatically simplify state management. Cross-model sharing places greater demands on reference tracking and synchronization.
Optimize Sparse Memory Access, Not Just Access Counts
Reading fewer historical positions can reduce theoretical work, but irregular access may produce noncontiguous memory reads, lower cache hit rates, and poor kernel utilization.
Engineering optimization must therefore address index organization, blocked cache layouts, batching, and data access paths. Additional data movement may partially offset the computation saved by index sharing.
End-to-end measurements are essential. Attention access counts alone cannot establish final latency.
Preserve Speculative Decoding Correctness
Draft quality affects acceptance and speed; it must not replace the target model’s final decision. To preserve the target distribution, exact speculative sampling requires correct acceptance tests, correction sampling after rejection, and associated probability handling.
Plausible-looking candidates are not evidence of correctness. Validation must examine both performance and sampling semantics, especially under stochastic sampling, rather than checking only whether deterministic outputs match.
7. A Recommended Evaluation Matrix
To identify where gains come from, compare at least three configurations:
- The target model alone.
- Speculative decoding with independent draft state.
- Speculative decoding with shared state.
Under training and inference conditions that are as consistent as possible, record:
- Tokens actually accepted per verification pass.
- Time spent on drafting, target verification, and scheduling.
- Peak GPU memory and per-request state occupancy.
- Time to first output token and subsequent generation latency.
- Aggregate throughput and tail latency at different concurrency levels.
- Performance with prefix reuse enabled and disabled.
- Index coverage at different candidate distances.
- Output quality and sampling consistency.
The task set should cover different information-dependency patterns, including long-document retrieval, continuous code generation, multi-turn interaction, cross-paragraph reasoning, and frequent changes in evidence sources.
Failure cases deserve attention alongside average metrics. If shared indices fail noticeably in a small number of critical scenarios, the system may need shorter candidate blocks, refreshed indices, or other fallback strategies. These are engineering choices whose benefits must also be measured.
8. Conclusion: Reduce Duplicate Work, Not Just Model Size
The central challenge of long-context speculative decoding is making the draft model inexpensive while preserving its ability to use complex historical information accurately. Maintaining independent caches and retrieval logic can put these goals in conflict.
KV cache sharing and index sharing offer a path toward reducing duplicate state and computation. The draft model reuses historical representations and retrieval results that the target model has already established.
The approach has clear applicability limits. It generally requires a target model with a reusable native sparse retrieval mechanism, a draft architecture compatible with the target cache, and sufficiently stable historical position selection over short generation intervals. Models that do not meet these conditions cannot simply adopt the same design.
The ultimate criterion is whether sharing improves candidate acceptance efficiency, GPU memory utilization, and end-to-end throughput while preserving output correctness, task quality, and service latency requirements. Architectural savings become deployment value only when those benefits hold consistently on real workloads.
