A speculative KV cache is a temporary memory buffer that stores the key-value (KV) pairs generated by a draft model for a sequence of candidate tokens. During the parallel verification step in speculative decoding, the larger target model can reuse these pre-computed KV states for the shared context, avoiding redundant computation. This reuse is critical for achieving a net inference speedup, as it reduces the computational overhead of the verification forward pass.
Glossary
Speculative KV Cache

What is Speculative KV Cache?
A speculative KV cache is a memory structure that stores the key-value pairs for a candidate token sequence during drafting, enabling efficient reuse during the target model's parallel verification pass.
The cache is populated during the draft model's autoregressive generation of the candidate sequence. When the target model performs its batched verification, it loads these cached KV pairs for the initial context, then computes only the new states for the speculative tokens. Effective management of this cache—including its allocation, population, and invalidation upon token rejection—is a key systems-level optimization for minimizing verification cost and maximizing the speedup factor in speculative decoding pipelines.
Key Characteristics of a Speculative KV Cache
A speculative KV cache is a memory structure that stores the key-value pairs for a candidate token sequence during drafting, enabling efficient reuse during the target model's parallel verification pass. Its design is central to the latency reduction in speculative decoding.
Draft Sequence Storage
The speculative KV cache temporarily holds the key-value (KV) pairs generated by the attention mechanism for every token in the candidate sequence proposed by the draft model. This storage is separate from the target model's primary cache and is structured to enable rapid parallel access during verification.
- Purpose: Avoids recomputing KV pairs for the draft sequence from scratch in the target model.
- Mechanism: As the draft model runs autoregressively, its attention layers produce KV pairs for each new token, which are appended to this dedicated cache.
Parallel Verification Enabler
The primary function of the speculative KV cache is to facilitate the parallel verification forward pass. When the target model verifies the candidate sequence, it can directly load the pre-computed KV pairs for the draft tokens, treating them as a contiguous block.
- Efficiency Gain: This allows the target model to score all
gamma(speculative factor) tokens in a single, batched forward pass instead ofgammasequential passes. - Core Requirement: The cache must be formatted identically to the target model's expected KV tensor structure for seamless integration.
Temporal and Conditional Lifespan
The speculative KV cache has a transient lifecycle, tightly coupled to the speculative decoding cycle. It is populated, used, and then either committed or discarded based on the verification outcome.
- Population Phase: Filled during the draft model's autoregressive generation.
- Usage Phase: Read during the target model's parallel verification.
- Disposition Phase: If tokens are accepted, the relevant KV pairs may be merged into the main cache. If a token is rejected, the cache for the subsequent candidate tokens is invalidated.
Memory Bandwidth Optimization
A key design goal is to minimize memory bandwidth pressure. The cache enables compute reuse by storing intermediate attention states, trading increased memory usage for reduced FLOPs.
- Trade-off: Stores
O(gamma * d_model * layers)additional values, whered_modelis the hidden dimension, to saveO(gamma * FLOPs_per_token)computation. - Hardware Consideration: The effectiveness of this trade-off depends on the GPU's memory bandwidth versus compute throughput, influencing the optimal speculative factor (gamma).
Integration with Target Model Cache
Upon successful token verification, the accepted portion of the speculative KV cache must be integrated into the target model's primary KV cache to maintain the autoregressive state for future generation.
- Append Operation: Accepted KV pairs are appended to the end of the target model's existing cache.
- Rollback Handling: If verification fails at token
t, KV pairs for tokenstonward in the speculative cache are discarded. The target model then generates the correct token autoregressively, extending its own primary cache.
Distinction from Primary KV Cache
The speculative KV cache differs fundamentally from the standard transformer KV cache in purpose, volatility, and management.
- Volatility: It is a short-lived, working buffer, unlike the persistent primary cache that maintains the entire conversation history.
- Ownership: Generated by and for a specific draft model (or drafting mechanism), whereas the primary cache belongs to the target model.
- Content: Contains states for a hypothetical future token sequence, not a verified history.
Speculative KV Cache vs. Standard Autoregressive KV Cache
This table compares the memory structures used to store attention key-value (KV) pairs in standard autoregressive decoding versus speculative decoding, highlighting the core differences in lifecycle, reuse, and performance.
| Feature / Metric | Standard Autoregressive KV Cache | Speculative KV Cache |
|---|---|---|
Primary Purpose | Stores computed keys and values for all previously generated tokens to avoid recomputation in subsequent steps. | Stores computed keys and values for a candidate token sequence generated by a draft model for parallel verification. |
Cache Population | Incrementally, one token position at a time, during each autoregressive generation step. | In a single forward pass of the draft model, generating keys and values for the entire candidate sequence (gamma tokens). |
Cache Reuse Strategy | Keys and values are appended and reused for all future generation steps from that sequence. | Keys and values for the candidate sequence are provisionally stored and conditionally appended to the main cache only upon full acceptance by the target model. |
Memory Lifecycle | Persistent and monotonically growing for the duration of the sequence generation. | Temporary; discarded if the candidate sequence is rejected, or merged if accepted. |
Verification Mechanism | Not applicable; generation is inherently sequential and verified as it proceeds. | The target model performs a single, batched forward pass over the candidate sequence, using the speculative KV cache to compute attention scores in parallel. |
Computational Overhead | Minimal per-step overhead for cache lookup and update. | Includes the cost of: 1) Draft model forward pass to populate speculative cache, 2) Target model's parallel verification pass. |
Optimal Performance Metric | Minimizing latency per generated token (time-to-first-token, inter-token latency). | Maximizing the acceptance rate of the candidate sequence to amortize the fixed verification cost over multiple tokens. |
Key Engineering Challenge | Managing memory growth for long sequences (context window management, paging). | Ensuring efficient, low-latency transfer and conditional merging of the speculative cache with the primary cache upon acceptance. |
Implementation and Optimization Considerations
The speculative KV cache is a critical memory structure for efficient speculative decoding. Its design directly impacts memory usage, verification speed, and overall system performance.
Cache Structure and Lifecycle
The speculative KV cache is a temporary buffer that stores the key-value (KV) pairs for the candidate token sequence generated by the draft model. Its lifecycle is tightly coupled to the verification pass:
- Population: The draft model's forward pass populates the cache with KV states for its proposed sequence.
- Verification: The target model's parallel verification pass reuses these cached KV states to compute attention scores efficiently, avoiding recomputation.
- Eviction: Upon token rejection, the cache for the invalidated suffix is discarded. Accepted tokens have their KV states merged into the target model's primary, persistent KV cache.
Memory Bandwidth Optimization
A primary optimization goal is minimizing data movement between GPU memory hierarchies. The speculative KV cache must be contiguously stored to enable fast batched reads during the target model's verification.
- Kernel Fusion: Fusing the cache lookup and attention computation into a single kernel reduces latency.
- Pre-allocation: Statically allocating the maximum required cache size (based on the speculative factor
gamma) prevents costly dynamic allocations during inference. - Quantization: Storing the speculative KV cache in a lower precision format (e.g., FP16, INT8) reduces memory footprint and bandwidth pressure, though it may introduce numerical error.
Integration with Persistent Cache
The speculative cache is ephemeral and must be correctly integrated with the target model's persistent KV cache, which holds the history of all accepted tokens for the ongoing generation.
- Append-on-Accept: Upon successful verification, the KV states for the accepted prefix of the candidate sequence are appended to the persistent cache.
- Rollback Handling: When a token is rejected, the system must rollback the persistent cache to the state before the invalid candidate sequence. This requires efficient pointer management or copy-on-write semantics to avoid expensive data copies.
- Cache Invalidation: The speculative cache for the rejected suffix and any subsequent draft proposals dependent on it is immediately invalidated.
Hardware-Aware Parameter Tuning
The optimal size of the speculative KV cache (dictated by the speculative factor gamma) is hardware-dependent. Tuning involves a trade-off:
- Higher Gamma: Longer candidate sequences increase the potential speedup but demand more on-chip SRAM (Static Random-Access Memory). If the cache exceeds fast memory, it spills to slower VRAM, negating benefits.
- Memory Hierarchy: The ideal
gammamaximizes the use of L2 cache/Shared Memory on the GPU. Profiling tools like NVIDIA Nsight Compute are used to find the sweet spot where verification cost is minimized. - Batch Size Consideration: In batched inference, the total speculative cache size scales with batch size, potentially becoming the memory bottleneck.
Advanced Architectures: Tree-Based Caching
For advanced speculative methods like speculative beam search or Medusa, the cache structure evolves from a linear sequence to a tree.
- Tree Attention: Requires a modified attention kernel that can process a tree of candidate sequences, where KV states are shared along common prefixes.
- Cache Duplication: Branches in the candidate tree require duplicated KV states for divergent token paths, increasing memory usage.
- Pruning: Aggressive pruning of low-probability branches during drafting is essential to control the exponential growth of the speculative KV cache in tree-based scenarios.
System-Level Trade-offs and Metrics
Implementing a speculative KV cache introduces system-level trade-offs measured by key metrics:
- Memory Overhead: The additional VRAM required for the speculative cache, which reduces available memory for larger batch sizes or longer contexts.
- Verification Latency: The time for the target model's parallel forward pass, which must be less than the time to generate
gammatokens autoregressively. This is the core condition for speedup. - Acceptance Rate Impact: A poorly performing draft model leads to low acceptance rates, causing frequent cache discards and rollbacks, wasting the memory bandwidth and compute used to populate the speculative cache.
- End-to-End Speedup: The net performance gain, calculated as
Speedup = 1 / ( (1/γ) + (C_verification / C_autoregressive) ), whereCrepresents cost.
Frequently Asked Questions
A speculative KV cache is a memory structure that stores the key-value pairs for a candidate token sequence during drafting, enabling efficient reuse during the target model's parallel verification pass.
A speculative KV cache is a temporary memory buffer that stores the key-value (KV) pairs generated by a draft model for a sequence of candidate tokens, allowing the target model to reuse these pre-computed attention states during its parallel verification pass. During the drafting phase, the smaller draft model runs autoregressively, and for each token it generates, the corresponding keys and values for all transformer layers are computed and stored in this cache. In the subsequent verification phase, the target model receives the entire candidate sequence as a batch. Instead of recomputing the KV pairs for the shared prefix from scratch, it can load the pre-computed KV states for the draft tokens directly from the speculative cache, performing a single, efficient forward pass to score all candidates. This reuse eliminates redundant computation, making the verification step significantly faster than generating the same tokens autoregressively with the target model alone.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The speculative KV cache is a core component of speculative decoding. These related terms define the broader system of models, mechanisms, and metrics that enable this inference acceleration technique.
Draft Model
A draft model is a smaller, faster language model used in speculative decoding to generate a short sequence of candidate tokens. Its primary objective is to predict the larger target model's likely outputs with high accuracy. Key characteristics include:
- Architecture: Often a distilled or quantized version of the target model.
- Speed: Must run significantly faster than the target model to offset the verification cost.
- Acceptance Rate: Its effectiveness is measured by how many of its proposed tokens are accepted by the target model.
Target Model
The target model is the primary, larger, and more accurate language model whose outputs the system aims to accelerate. In speculative decoding, it performs a verification forward pass on the batch of tokens proposed by the draft model. It computes probability distributions for each position in the candidate sequence and accepts a token if it matches its own predicted token or meets a probabilistic criterion. The target model's computational graph and KV cache are the primary bottlenecks the technique seeks to optimize.
Token Verification
Token verification is the critical parallel scoring step in speculative decoding. Instead of generating tokens one-by-one, the target model processes the entire candidate sequence (e.g., 3-5 tokens) in one batched forward pass. It compares its own predicted token at each position against the draft model's proposal. A token is accepted if the target model's probability for that token meets a threshold (often if it's the most likely token). This batched verification must be cheaper than generating the same number of tokens autoregressively for a net speedup.
Acceptance Rate
The acceptance rate is the percentage of tokens proposed by the draft model that are accepted by the target model during verification. It is the single most important metric determining the efficacy of speculative decoding. A high acceptance rate means fewer rollbacks to autoregressive generation by the target model. The theoretical speedup is approximately 1 / (1 - acceptance_rate). Factors influencing acceptance rate include draft model quality, task difficulty, and the speculative factor (length of the candidate sequence).
Verification Forward Pass
A verification forward pass is a single, batched inference step through the target model that scores all tokens in a speculative candidate sequence. This pass reuses the speculative KV cache for the known prefix and computes attention for the new candidate positions in parallel. The computational cost of this pass is the primary overhead of speculative decoding. The speedup is achieved because the cost of this single batched pass is less than the cost of multiple sequential autoregressive passes the target model would need to generate the same number of tokens.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us