Long-Context Speculative Decoding with Shared KV Cache and Sparse Index Selection

    This article examines speculative decoding for long-context inference when the target model uses native sparse attention. As target-side KV caches become more compact, independent draft-model caches become a bottleneck for memory, prefill, prefix caching, and concurrency. The article describes a layer-paired design in which draft layers reuse the target model’s KV cache and sparse index selection instead of maintaining their own context state. It explains why index choices remain stable within a candidate block, outlines key implementation requirements, and reviews benefits and limits. It also summarizes reported acceptance-length and throughput gains and proposes evaluation metrics for real deployments.

    1. The Core Tension in Long-Context Inference: After Attention Sparsification, the Draft Model Becomes the New Bottleneck

    With the spread of agents, code understanding, long-document question answering, and similar workloads, the context lengths that models must handle continue to grow. To control attention computation and memory overhead, a new class of target models has begun to adopt native sparse attention designs: each layer includes a lightweight indexing module that selects a fixed number of historical positions for each query position. This keeps computational complexity relatively manageable even under long contexts.

    Speculative decoding, however, has not fully kept pace with this change. Speculative decoding typically consists of a target model and one or more draft models. The draft model predicts multiple candidate tokens at once, and the target model verifies them in parallel. To maintain candidate quality, block-parallel draft models often need to maintain their own context cache. Conventional approaches either store the full context or use a sliding-window approximation.

    When the target model itself is already highly sparse, maintaining a separate cache in the draft model becomes increasingly heavy. The better the target model compresses its own KV, the more prominent the draft-model cache becomes as a proportion of total memory. This not only increases memory pressure but also affects prefill efficiency, prefix-cache hit rates, and throughput under high concurrency.

    Therefore, the key question for long-context speculative decoding can be summarized in one sentence: how can the draft model obtain sufficiently accurate candidate predictions without maintaining a duplicate context cache?

    2. Three Types of Overhead in Conventional Block-Parallel Draft Models

    In long-context scenarios, the cost of block-parallel draft models mainly comes from three areas.

    1. Memory overhead

    If the draft model stores a full context cache, its memory usage grows linearly with context length. Even with a sliding-window strategy, it still needs to retain key-value state within a certain window. When the target model already uses sparse attention, the draft model can instead become one of the main sources of memory usage.

    2. Prefill and repeated computation

    The draft model needs to understand the context in order to generate candidate tokens. If it maintains its cache independently, it may repeat work during prefill that the target model has already processed. For long-context tasks, this repeated computation can significantly increase time to first token.

    3. Lower prefix-caching and concurrency efficiency

    In multi-turn dialogue, agent tool calls, code completion, and similar scenarios, prefix reuse is very common. If the draft model has an independent cache, the prefix-cache reuse path becomes more complex, and the hit rate drops. At the same time, under high concurrency, every request carrying a draft cache reduces the number of concurrent requests that can be served.

    3. Core Idea: Pair Draft Layers with Target Layers and Share KV and Index Selection

    A more efficient approach is to stop having the draft model maintain context independently and instead form a layer-level pairing relationship with the target model. The target model already stores the KV for each layer and has already used its indexing module to select accessible historical positions for each query position. Draft layers can directly reuse both types of information.

    This can be broken down into two key mechanisms.

    1. KV sharing: sharing the target model’s key-value cache

    Draft layers no longer store their own context cache; instead, they read the KV from the corresponding target-model layers. In this way, the draft model retains only the necessary lightweight structures, such as the draft head, candidate-generation logic, or small-scale parameters, and no longer bears full context storage.

    2. Index sharing: sharing the target model’s index selection

    The target model’s indexing module has already selected a set of historical positions for the current query position. Draft layers do not recompute the selection; they directly use the same set of positions. This avoids repeated index computation and keeps the draft candidates aligned with the target model’s attention range.

    The overall logic can be represented as:

    1. Target model:
    2. Stores KV for each layer
    3. Generates sparse indices for each query
    4. Draft model:
    5. Does not store independent KV
    6. Does not regenerate indices
    7. Reads target-layer KV and indices
    8. Generates candidate tokens within a block

    This design decouples “context storage” from “candidate generation.” The target model handles context representation and position selection, while the draft model only needs to quickly produce candidates within the given context.

    4. Why Later Tokens in a Block Can Reuse Earlier Index Selection

    A block-parallel draft model predicts multiple tokens at once. Strictly speaking, the attention selection for later tokens may differ from that of the previous token. If every token reselected positions, shared indexing would fail.

    The method works because of a key observation: within a candidate block, the positions that later tokens actually need to attend to overlap heavily with the positions selected in the previous step. Controlled experiments in the relevant technical material show that, in long-context draft scenarios, an index selection made one step ahead can cover about 90% of the positions that later tokens would select on their own.

    This coverage rate matters more than a simple speed metric because it determines the theoretical upper bound of the method. If coverage is too low, draft candidate quality will decline, the target model’s acceptance rate during verification will fall, and the final speedup will be offset. Only when index selection has strong intra-block stability can shared indexing avoid materially harming the benefits of speculative decoding.

    5. Key Engineering Implementation Points

    From an engineering perspective, this approach requires the inference framework to support the following capabilities.

    1. Layer-level pairing

    Draft layers need to be explicitly associated with specific target-model layers. In general, they can be paired one-to-one by layer index, or mapped according to the model structure. The more stable the pairing relationship, the simpler cache reading becomes.

    2. Read-only shared cache

    Draft layers only read the target-layer KV and indices; they do not write back or modify them. This avoids cache-consistency overhead and reduces lock contention under concurrency.

    3. Intra-block candidate generation

    When the draft model generates multiple candidates within a block, it needs to reuse the index set for the current query position. The illustrative logic is as follows:

    1. for draft_step in range(block_size):
    2. query = build_query(draft_step)
    3. kv = target_kv[layer_id]
    4. index = target_index[layer_id][query.position]
    5. logits = draft_head(query, kv, index)
    6. token = sample(logits)
    7. candidates.append(token)

    4. Alignment with the target model’s verification flow

    When the target model verifies candidate blocks, it still uses its own sparse attention and KV. The draft model only provides candidates and does not change the target model’s verification logic. This limits changes to the draft side and reduces intrusion into the main model’s inference path.

    6. Where the Gains Come From: More Than Memory Savings

    The benefits of this cooperative design are not limited to memory.

    1. Lower draft-cache usage

    The draft model no longer maintains a full context cache, so memory usage drops significantly. The longer the context, the more pronounced the benefit.

    2. Less repeated prefill computation

    Context encoding already completed by the target model can be reused directly by draft layers, avoiding a second pass over the long context on the draft side.

    3. Higher prefix-cache hit rate

    Because the draft side no longer maintains an independent cache, prefix reuse only needs to center on the target model cache. The path is shorter, and the hit rate is higher.

    4. Better high-concurrency throughput

    In high-concurrency scenarios, removing each request’s draft cache allows the system to serve more concurrent requests. This benefit is especially noticeable for long-context agent tasks.

    5. Higher candidate acceptance length

    Under the same training configuration, controlled experiments in the relevant technical material show that this method accepts more tokens per step than conventional block-parallel draft schemes. For general tasks, the improvement is about 3.9% to 10.5%; for long-context and agent tasks within 128K, it expands to 10.0% to 31.5%.

    Under a 64K context, high concurrency, and matched single-user decoding latency, the two test groups achieved throughput improvements of about 62% and 81%, respectively. This shows that the method is not effective only for short contexts; it becomes more worthwhile as context length increases.

    7. Applicability Boundaries: Not Every Target Model Fits

    This class of methods has a clear prerequisite: the target model must use native sparse attention and must be able to provide stable index selection for each query position.

    If the target model uses dense attention, there is no shareable sparse index, and draft layers cannot directly reuse the target layer’s selection results. In that case, the draft model still needs to maintain its own cache or adopt another approximation strategy.

    In addition, the effectiveness of the method depends on three factors:

    1. The quality of the target model’s index selection. If the indices themselves are unstable, the draft candidate acceptance rate will decline.
    2. Intra-block selection coverage. The higher the coverage, the safer block-parallel drafting becomes.
    3. The inference framework’s cache-sharing capability. If the framework cannot efficiently share KV and indices in read-only mode, the engineering benefit will be discounted.

    Therefore, when evaluating this approach, it is not enough to look only at single-step decoding speed. Acceptance length, long-context throughput, memory usage, and concurrency stability must also be considered.

    8. Practical Evaluation Recommendations

    To evaluate a similar approach in a real system, consider the following metrics.

    1. Acceptance length

    Measure the average number of tokens accepted per verification step. This metric directly determines whether speculative decoding is effective.

    2. End-to-end throughput

    Test short-context, long-context, and high-concurrency scenarios separately rather than looking only at single-request latency.

    3. Memory usage

    Focus on whether the draft cache has been removed and whether the target model’s KV has become the main source of memory usage.

    4. Prefix-cache hit rate

    In multi-turn dialogue and agent scenarios, the prefix hit rate has a major impact on overall performance.

    5. Tail latency

    In long-context scenarios, P95 and P99 latency often reflect real user experience better than averages.

    6. Fallback mechanism

    When index coverage is insufficient or the candidate acceptance rate is too low, the system should be able to fall back to a normal draft mode or disable speculative decoding to avoid negative optimization.

    9. Conclusion

    The focus of long-context inference optimization is shifting from simply expanding the window to reducing the cost of context reuse. Native sparse attention allows target models to handle long contexts efficiently, but it also makes the independent cache of conventional draft models a new bottleneck.

    By pairing draft layers with target layers and sharing the target model’s KV and index selection, candidate tokens can be generated without duplicating context maintenance. The core value of this approach is that it decouples storage, indexing, and candidate generation, making long-context speculative decoding lighter and better suited to high-concurrency agent scenarios.

    At the same time, it has clear boundaries: it applies only to target models with stable sparse indices and requires the inference framework to support efficient read-only cache sharing. For long-context serving, this type of cooperative optimization deserves continued attention, but final results still need further validation on real production traffic and across multiple inference frameworks.