LLM Inference Optimization: 454 tok/s with a 27B Model on a Single GPU

    This article walks through a practical stack for pushing a single-GPU, 27B-class dense model past 450 tokens per second. It first explains why autoregressive decoding is bound by memory bandwidth rather than compute, then covers four layers of optimization: 4-bit weights and activations, draft-based speculative decoding, KV cache compression, and memory clock tuning. It also discusses how these techniques constrain and reinforce one another, a recommended order for rolling them out, and the accuracy and reproducibility risks to watch. The takeaway is that on mid-sized models, a well-tuned optimization stack can deliver gains comparable to moving up a model tier.

    1. The Technical Question Behind the Numbers

    A professional-grade GPU, a dense model with roughly 27 billion parameters, and more than 450 tokens generated per second — these numbers draw attention not because any single technique is especially exotic, but because they push four categories of inference-side optimization to fairly aggressive settings and make them work together on one card.

    One clarification first: 27 billion parameters means the 27B scale. It has nothing to do with something like “2.7 billion pixel parameters.” Parameter count determines weight footprint and compute volume; it is unrelated to image pixels. Getting the scale right is the prerequisite for every memory and bandwidth estimate that follows.

    The one conclusion worth taking away is this: on mid-sized models, the gains from an optimization stack can be comparable to switching to a larger model tier. The rest of this article works through the memory, compute, and memory-access constraints layer by layer.

    2. Finding the Bottleneck: What Actually Slows Down Decoding

    Autoregressive decoding reads every weight once for each token generated, while processing only a single token vector at a time. Arithmetic intensity is therefore extremely low, and performance is determined almost entirely by memory bandwidth rather than floating-point throughput. For a 27B model with half-precision weights, the weights alone take roughly 54GB — too much for a single card, let alone enough for high throughput.

    This leads to three general optimization directions:

    • Move fewer bits per token → low-bit quantization;
    • Make fewer model calls per step → draft-based speculative decoding;
    • Reduce the bandwidth and capacity consumed by context history → KV cache quantization and compression.

    Memory clock tuning is a fourth line. It raises the bandwidth ceiling directly, but carries the highest stability risk, so it belongs last.

    3. Layer One: 4-Bit Weights and 4-Bit Activations

    Compressing weights to 4-bit brings the 27B model’s weight footprint down to around 10GB, which is the prerequisite for running on a single card. Pushing activations down to 4-bit as well (W4A4) goes further: both operands of the matrix multiplication become low-bit, so the theoretical bandwidth and throughput gains are far larger than compressing weights alone (W4A16).

    The engineering difficulty of low-bit quantization is not the compression itself but staying accurate after it. Common industry practices include:

    1. Group-wise quantization: every 16 or 32 weights share one set of scaling factors, balancing accuracy against metadata overhead;
    2. Mixed-precision accumulation: accumulate low-bit multiply-add results in higher precision to avoid error buildup;
    3. Outlier channel protection: keep higher precision for the few channels with very large value ranges;
    4. Calibration datasets: determine scaling factors from representative text rather than relying on weight statistics alone.

    Illustrative configuration logic (pseudocode, showing only the group-wise quantization and accumulation ideas):

    1. # group_size=16 means every 16 weights share one set of scales
    2. q_w, scale = quantize(weight, bits=4, group_size=16)
    3. # low-bit multiply-add, with the accumulator kept in high precision
    4. acc = fp32_accumulate(matmul(q_w, q_x)) * scale

    Note that 4-bit activations are more sensitive to accuracy loss. In practice, evaluate perplexity and downstream task metrics on a validation set before deciding whether to enable them.

    4. Layer Two: Draft-Based Speculative Decoding

    The core idea of speculative decoding is “guess first, verify after”: a lightweight draft module proposes several candidate tokens at once, the main model verifies them in parallel, and the longest matching prefix is accepted. Because verification is a single, parallelizable forward pass, a high enough acceptance rate yields multiple tokens per step — effectively reducing the number of model calls per token.

    Three variables determine the payoff:

    • Draft length: longer drafts mean higher theoretical gains, but the acceptance rate decays as length grows, so there is an optimum;
    • Draft quality: the closer the draft distribution is to the main model, the higher the acceptance rate;
    • Batch size: the gains are most visible in small-batch, low-latency scenarios; in high-throughput batch processing, the main model is already close to compute saturation and the gains are diluted.

    The “block-level 16 draft” mentioned in the original — proposing 16 candidates at once — is a fairly aggressive setting. It only makes sense with a high acceptance rate and enough bandwidth headroom.

    5. Layer Three: KV Cache Compression

    In long-context scenarios, the KV cache consumes memory quickly and becomes the main bandwidth cost during decoding. Dropping the KV cache to 8-bit halves both its capacity and bandwidth consumption, which is a high-value step. Going further, paged memory management reduces fragmentation, and evicting low-value history entries based on attention weights is another option.

    One engineering caveat: KV cache quantization typically affects long-context tasks more than weight quantization does, so evaluation should cover long-document summarization and multi-turn conversation, not just short question answering.

    6. Layer Four: The Risk Boundary of Memory and Clock Tuning

    Raising the memory clock lifts the bandwidth ceiling, which directly helps the bandwidth-bound decoding stage. But it is runtime environment tuning, not model-side optimization, and its boundaries must be clear:

    • Gains depend on the specific hardware sample and cannot be reproduced across devices;
    • Over-tuning shows up as silent computation errors, driver resets, or non-reproducible training and inference results;
    • Production environments should prefer stable clocks and put reproducibility ahead of peak throughput.

    7. Combined Effects and Tuning Order

    The gains from the four optimizations do not simply add up; they constrain one another. Quantization reduces bandwidth pressure, which keeps aggressive draft lengths from being dragged down by memory access; the memory freed by KV compression in turn supports longer contexts and larger batches. Recommended rollout order:

    1. Measure baseline throughput, time to first token, and memory usage;
    2. Enable 4-bit weights and confirm accuracy is acceptable;
    3. Add 8-bit KV cache and re-measure long-context metrics;
    4. Add speculative decoding and sweep draft lengths to find the optimum;
    5. Finally, do environment tuning such as clocks, and keep a rollback plan.

    8. Running It in the Cloud

    To reproduce similar results in the cloud, a set of general-purpose capabilities is enough: a container platform to host the inference runtime and pin images and dependencies; object storage for model weights and calibration text; logging, monitoring, and alerting to track throughput, latency, memory, and error rates; and a message queue to smooth request spikes. Baidu AI Cloud offers these general capability categories and can serve as the foundation for this kind of inference optimization experiment.

    The final conclusion is not mysterious: high single-GPU throughput is the combined result of quantization, speculative decoding, KV compression, and environment tuning — and the methodology itself is more worth reusing than any specific set of numbers.