# Speculative decoding for 2x faster generation



Learn how to use speculative decoding to double your LLM inference speed on Podstack by using small draft models to accelerate large target models.



Inference · 2026-07-02 · 3 min read



In the world of Large Language Models (LLMs), speed is often the bottleneck between a prototype and a production-ready application. While high-end GPUs offer massive throughput, the autoregressive nature of LLMs—generating one token at a time—means that even the most powerful hardware spends a significant amount of time waiting for memory transfers.

Speculative decoding has emerged as one of the most effective techniques to break this bottleneck, often yielding a 2x or even 3x speedup without sacrificing model quality.

## The Bottleneck: Memory Bound Generation

Standard LLM generation is "memory-bound." To generate a single token, the GPU must load every single parameter of the model from VRAM into its compute cores. For a 70B parameter model, this is a massive overhead for a tiny amount of computation.

Speculative decoding flips the script. It uses a smaller, much faster "draft" model to predict the next few tokens in a sequence. Then, the larger "target" model verifies these tokens in a single parallel forward pass. If the draft model is correct, the target model can accept multiple tokens at once, effectively bypassing the one-token-at-a-time limit.

## How Speculative Decoding Works

The process follows three main steps:
1.  **Drafting:** A small model (e.g., a 1.5B model) generates a sequence of $K$ candidate tokens.
2.  **Verification:** The large target model (e.g., a 70B model) performs a single forward pass on all $K$ tokens.
3.  **Acceptance:** The system compares the outputs. If the target model agrees with the draft, those tokens are kept. If they diverge, the system corrects the first mismatch and restarts.

Because the draft model is significantly smaller, its generation is nearly "free" in terms of time. As long as the draft model is reasonably accurate, the overall wall-clock time drops significantly.

## Implementation with vLLM and Podstack

One of the most robust ways to implement speculative decoding is using the `vLLM` engine. It supports speculative decoding natively. On Podstack, you can deploy this as a serverless endpoint or run it as a managed job.

Here is how you can configure a vLLM server to use a Llama-3-70B model as the target and a Llama-3-8B model as the draft.

```python
import os
from podstack import PodstackClient

# Initialize Podstack client using your API key
client = PodstackClient(api_key=os.getenv("PODSTACK_API_KEY"))

# Define the deployment configuration
# We use 'speculative_model' to point to our fast drafter
deployment_config = {
    "model": "meta-llama/Meta-Llama-3-70B-Instruct",
    "gpu": "A100-80GB",
    "engine_args": {
        "speculative_model": "meta-llama/Meta-Llama-3-8B-Instruct",
        "num_speculative_tokens": 5,
        "use_v2_block_manager": True
    }
}

# Deploy a serverless inference endpoint on Podstack
endpoint = client.endpoints.create(
    name="llama-speculative-fast",
    config=deployment_config,
    min_replicas=1
)

print(f"Endpoint active at: {endpoint.url}")
```

Alternatively, if you prefer the API, you can launch a worker directly:

```text
Podstack does not ship a command-line interface. Use the console, the Python package `podstack-sdk`, or the API at https://podstack.ai/api/v1 with a `ps_live_` key.
```

## Practical Tips for Maximum Performance

To get the most out of speculative decoding, keep these three factors in mind:

1.  **Model Alignment:** The draft and target models should ideally share the same tokenizer. Using a Llama-3-8B model to draft for a Llama-3-70B model is highly effective because they were trained on similar data distributions and use identical tokenization.
2.  **Draft Length ($K$):** Setting `num_speculative_tokens` too high (e.g., 10+) can actually slow down generation if the draft model is inaccurate, as the overhead of verifying many rejected tokens adds up. Usually, a value between 4 and 6 is the sweet spot.
3.  **Batch Size:** Speculative decoding provides the most benefit at low batch sizes (like real-time chat). As the batch size increases, the GPU becomes compute-bound rather than memory-bound, and the relative gains of speculative decoding diminish.

## Why Use Speculative Decoding on Podstack?

Optimizing LLM inference isn't just about the algorithm; it’s about the underlying infrastructure. Podstack is designed specifically for these high-performance workloads.

*   **Per-Second Billing:** Speculative decoding reduces the time your GPU is active. Since Podstack bills by the second, faster generation directly translates to lower costs.
*   **On-Demand Scalability:** You can spin up A100s or H100s via the Podstack API the moment you need to run a high-throughput verification task.
*   **Serverless Efficiency:** By deploying speculative models as serverless endpoints, you ensure that you aren't paying for idle time, but when a request hits, it’s processed at 2x the standard speed.

By combining the architectural advantages of speculative decoding with the elastic, per-second compute of Podstack, developers can deliver sub-second latency for even the largest open-source models.
