How to Evaluate LLM Generation Speed and Optimize It with Speculative Decoding

    Comparing "tokens per second" between LLM deployments is rarely apples-to-apples: latency, decoding throughput, system throughput, precision, and concurrency all change the picture. This article explains how to measure LLM inference speed with a consistent methodology, why autoregressive decoding is often memory-bandwidth-bound, and how speculative decoding—a draft-and-verify approach using a cheap draft model plus the target model—can accelerate generation. It covers acceptance and rejection rules, the factors that determine whether the speedup materializes, engineering concerns such as KV cache management and memory overhead, and how to run reproducible benchmark comparisons before deciding whether the optimization fits your workload.

    1. Agree on the Measurement Before Discussing Speed

    “What’s your generation speed in tokens/s?” is a common question when deploying large language models. But even for models of similar size, different tests can produce very different numbers. The reason is not just hardware: input length, output length, numerical precision, concurrency, inference implementation, and whether acceleration strategies are used all matter.

    A token here means the basic unit of text the model processes and generates. One token does not necessarily correspond to a single Chinese character, an English word, or a punctuation mark, so token speed cannot be directly equated with the reading speed a user experiences in words or characters.

    To compare inference performance properly, at minimum distinguish these metrics:

    1.1 Time to First Token (TTFT)

    TTFT is the time from sending a request to receiving the first output token. It typically includes request queuing, input processing, and the first generation step.

    For interactive applications, TTFT directly determines whether the system feels responsive. A system whose subsequent output is fast but that takes a long time before starting to answer still delivers a poor experience.

    1.2 Decoding-Stage Throughput

    Decoding throughput describes how fast the model generates tokens after output begins. To avoid mixing in the first-generation overhead, use a measurement like:

    Decoding speed = (number of tokens generated after the first token) ÷ (corresponding generation time)

    State clearly where timing starts and stops. If input processing, network transfer, and queuing are all included, what you get is end-to-end effective throughput, not pure decoding speed.

    1.3 System-Level Throughput

    System throughput is the total number of output tokens completed per unit of time when multiple requests run together. It measures service capacity, but it cannot replace the per-user generation speed.

    Raising concurrency or batch size may increase system throughput while extending the waiting time for individual requests. So “how many tokens per second the system outputs” and “how many tokens per second a given user receives” must be discussed separately.

    In addition, speculative decoding may return multiple tokens at once, so streaming output arrives in groups. In that case, besides average speed, also observe the waiting time between consecutive output chunks, so obvious pauses aren’t hidden by the average.

    2. Why Traditional Token-by-Token Generation Hits a Bottleneck

    Autoregressive language models generate text by predicting the next token given the existing context. Every new token requires a computation over the current context, after which the token is appended and prediction continues.

    Inference generally has two stages:

    • Prefill stage: process the user’s input and build the internal state for subsequent generation.
    • Token-by-token decoding stage: repeatedly predict the next token, gradually building the answer.

    In small-batch decoding, each step produces very little new content but may require reading a large amount of model weights. Performance is therefore often limited by memory bandwidth and data movement rather than raw compute.

    The attention KV cache reuses partial computation of the historical context, reducing redundant work, but it does not eliminate the serial dependency of token-by-token generation. The longer the context, the more cache capacity and access cost matter.

    This raises a natural question: can we guess several future tokens first, then have the large model verify them in one pass, reducing the number of sequential large-model steps?

    3. Speculative Decoding: Draft First, Then Verify

    The core idea of speculative decoding is to split generation into two roles:

    • Draft model: computationally cheap, quickly produces a short sequence of candidate tokens.
    • Target model: verifies the candidates and decides which tokens enter the final output.

    You can think of it as “propose candidates cheaply, confirm them expensively.” It resembles candidate recall and fine-grained filtering in search systems, but it is not retrieving existing answers—it is predicting possible future token sequences.

    Suppose the draft model proposes n consecutive candidate tokens. In a single verification forward pass, the target model computes the positions corresponding to these candidates and obtains the prediction distribution at the next position for continuing generation. The target model is not unconditionally generating n+1 final tokens at once; it computes the prediction distributions along the candidate path in a batch.

    If the candidates satisfy the acceptance condition, multiple tokens are committed in one step. If a position is rejected, only the previously accepted prefix is kept, a corrected token is produced at the rejection point, and the draft candidates after it are discarded.

    This mechanism exploits two properties:

    1. The draft model’s cost of generating candidates is relatively low.
    2. Verifying the target model over several given positions typically utilizes the hardware better than executing independent decoding steps one at a time.

    So the speedup does not come from “the large model doing less computation,” but from a change in how computation is organized: cheap prediction work buys a larger effective advance per target-model round.

    4. Understanding “Accept” and “Reject” Precisely

    “Accept when guessed right, recompute when wrong” is fine for intuition but too imprecise for implementation. Acceptance rules are closely tied to the generation strategy.

    4.1 Deterministic Generation

    In deterministic settings, such as greedily picking the highest-probability token at each step, you can check whether each draft candidate matches what the target model would choose under the corresponding valid prefix.

    As soon as a position mismatches, the subsequent draft is built on an invalid prefix and cannot be used directly. The system keeps the confirmed prefix and resumes generation from the point of divergence.

    4.2 Stochastic Sampling

    With random sampling, “is the candidate the highest-probability token” cannot be the acceptance criterion, or the target model’s original output distribution would be altered.

    Standard exact speculative sampling combines the draft distribution and the target distribution for the acceptance decision. For a candidate token x, a common acceptance probability is:

    Acceptance probability = min(1, target model’s probability of x ÷ draft model’s probability of x)

    If rejected, the next token is sampled from the corresponding correction distribution rather than simply asking the draft to guess again. When the algorithmic conditions hold and distributions are handled correctly, this approach preserves the target sampling distribution instead of trading generation quality for speed.

    This also means sampling temperature, candidate truncation, and probability normalization must be consistent and correct. Implementation errors can introduce distribution biases in output that otherwise looks normal.

    5. Why It Sometimes Accelerates Significantly, and Sometimes Barely Helps

    Whether speculative decoding pays off depends on how much effective output each extra round of work buys.

    A simplified relationship helps:

    Average cost per token ≈ total time of one round of drafting, verification, and state management ÷ number of effective tokens output per round

    This is not a precise performance prediction formula, but it helps locate the main factors.

    5.1 The Draft Model Must Be Cheap Enough

    If the draft model is too large, drafting time may cancel out the decoding savings at the target model. If both models compete for compute, bandwidth, or cache on the same device, the benefit may shrink further.

    So don’t just look at the draft model’s parameter count—measure its actual generation cost on your hardware at your context length.

    5.2 The Acceptance Rate Must Be High Enough

    The closer the draft model’s predictions are to the target model’s, the longer the accepted consecutive prefixes after verification tend to be.

    Acceptance rates vary by task. Highly formatted, stable text is usually easier to predict; open-ended creative writing, complex reasoning, or inputs with large distribution shifts make long accepted prefixes harder. These are only general tendencies and cannot substitute for actual testing.

    Beyond the overall acceptance rate, record the distribution of accepted prefix lengths per round: a rejection early in the candidate sequence and one near the end have different effects on effective progress.

    5.3 Longer Drafts Are Not Always Better

    Drafting more tokens at once means a potentially larger advance, but also higher drafting and verification cost. If rejections frequently occur at the first few positions, the computation on later candidates is easily wasted.

    A reasonable approach is to test several candidate lengths and compare end-to-end request performance rather than blindly chasing longer drafts. You can also adapt the length based on recent acceptance behavior, but factor in the overhead of the control logic.

    5.4 Batching and Concurrency Change the Picture

    At low concurrency, speculative decoding may improve device utilization. At high concurrency, existing batching already keeps the device fairly busy, and extra drafting may not raise total throughput further.

    A configuration suited to single-user interaction is not necessarily suited to a high-concurrency service. Be explicit about whether the optimization goal is lower response latency or higher capacity per unit of resource.

    6. Caching, Scheduling, and Data Movement Determine Real-World Results

    The algorithm explains the direction of the speedup; the engineering implementation determines whether it materializes.

    6.1 Commit and Roll Back Caches Correctly

    After the target model verifies candidates, it must distinguish accepted state from unaccepted state. When a draft is partially rejected, the entire candidate sequence’s cache cannot be treated as valid context.

    The draft model also needs to sync to the finally confirmed prefix. Otherwise, the next round may generate candidates based on already-rejected content, causing state errors or wasted computation.

    6.2 Minimize Data Movement and Synchronization

    If the draft and target models are on different devices, candidate transfer, probability exchange, and synchronization waits can all consume time. Whether cross-device deployment is faster must be measured with communication overhead included.

    Even on the same device, frequent memory allocation, repeated movement of small data blocks, or fine-grained scheduling can erode the theoretical advantage.

    6.3 Control Extra Memory Usage

    Introducing a draft model usually means extra weight and cache memory. When memory is tight, the system may be forced to reduce batch size, shorten context, or swap data in and out, hurting overall service capacity.

    Performance evaluations should report throughput, latency, and peak memory usage together—not just a single speed number.

    7. How to Run a Reproducible Comparison

    An anecdote of speed going from roughly 40 tokens/s to nearly 120 tokens/s is a useful clue from one run, but without hardware, input length, concurrency, and measurement methodology, it cannot be treated as a general benchmark—let alone a promise of a fixed speedup multiple.

    Professional tests should use controlled, same-environment comparisons.

    7.1 Fix the Baseline Conditions

    At minimum, record:

    • Target model size, numerical precision, and quantization method.
    • Number of accelerators, available memory, and runtime environment.
    • Input token length, output cap, and stopping conditions.
    • Concurrency and batching strategy.
    • Generation strategy and sampling settings.
    • Whether request queuing, network transfer, and text decoding time are included.

    7.2 Set Up Baseline and Optimized Groups Simultaneously

    The baseline group generates directly with the target model; the optimized group enables speculative decoding with everything else held as constant as possible.

    Warm up before testing to avoid polluting results with initialization, weight loading, and first-run preparation. Repeat each group multiple times and report medians and tail latencies rather than cherry-picking the fastest run.

    7.3 Cover Different Workloads

    The test set should include short inputs, long inputs, short answers, and long answers, covering content typical of your actual business. A single prompt may happen to produce a very high acceptance rate and won’t represent real traffic.

    For random generation, the two configurations may produce different output lengths. Report actual output lengths, and if necessary add fixed-length generation tests, so length differences don’t distort the speed comparison.

    7.4 Verify Correctness

    Beyond performance, confirm that stop-token handling, cache rollback, streaming output order, and length limits behave correctly. In deterministic mode, check output consistency; in sampling mode, combine algorithm-level implementation review with statistical testing—don’t conclude the optimization is broken just because a single sample differs.

    8. From “Speed Numbers” to “Optimization Decisions”

    The value of speculative decoding lies in using cheap drafts to buy batched verification from the target model, lowering the average cost per effective output token. It is not a fixed acceleration switch that applies to every task and every piece of hardware.

    In practice, follow this order:

    1. Clarify the target metric: distinguish single-request speed, time to first token, and system throughput.
    2. Measure the existing system to confirm whether the bottleneck is decoding, queuing, input processing, or data movement.
    3. Choose a sufficiently cheap drafting setup and measure candidate acceptance behavior.
    4. Tune candidate length and check cache, scheduling, and memory overhead.
    5. Compare gains under real workloads, and keep a regular generation path as a fallback for cases where speculative decoding doesn’t fit.

    What truly matters is not just “how many tokens per second,” but whether—under the same resources, the same quality requirements, and the same measurement methodology—the system can consistently reduce waiting time, increase service capacity, and keep the added complexity under control. Only when all of these are verified does an acceleration result have reproducible, transferable engineering value.