2026-03-15 · Technical Blog
Introduction
The inference stage of large language models is the last barrier for AI system implementation. No matter how well a model is trained, if inference costs are too high and latency too large, it can't generate value in real business. This article introduces several key optimization directions we've practiced in production, and their actual impact on cost and performance.
Quantization: From FP16 to INT4
Compressing model weights from FP16 to INT4 is the most mature technique in inference optimization. Taking a 70B parameter model as an example, FP16 requires about 140GB of VRAM, while INT4 quantization only needs about 35GB — this means a model that originally required 2 A100s can now run on 1.
We mainly use two approaches: GPTQ and AWQ. GPTQ is slightly better on accuracy loss but slower in quantization (about 2 hours for a 70B model); AWQ is 5x faster, with accuracy loss negligible on the vast majority of tasks. For production environments, we recommend AWQ.
KV Cache Optimization
During inference, each layer of the Transformer caches previous Keys and Values (i.e., KV Cache) to avoid redundant computation. For long contexts (32K tokens), KV Cache VRAM usage can exceed the model weights themselves.
Our optimization strategies:
- PagedAttention: Managing KV Cache in pages, avoiding memory fragmentation, improving VRAM utilization by over 30%
- Sliding Window: For contexts exceeding a certain length, only keeping the most recent KVs, compressing earlier content via summarization
- MQA/GQA: Using Multi-Query or Grouped-Query Attention, reducing the number of KV heads, directly lowering cache size
Batching and Continuous Decoding
The problem with static batching: all requests in a batch must wait for the longest to complete before output. Continuous batching (in-flight batching) lets new requests join at any time and completed requests exit at any time, raising GPU utilization from 40% to over 85%.
We use vLLM's PagedAttention + continuous batching combination, achieving 120 token/s throughput per card on 8 A100s, with P99 latency controlled within 200ms.
Actual Results
Combining the above optimizations, our inference cost dropped from the initial $0.08/1K tokens to $0.012/1K tokens, and latency dropped from 3.2s to 450ms (first token). This makes large model APIs economically viable — no longer "usable but unaffordable."
Summary
Inference optimization isn't a single technique, but a set of strategies that need to work together. Quantization solves the VRAM bottleneck, KV Cache optimization solves the long context problem, and batching solves the throughput problem. Only by combining all three can large models truly move toward scaled deployment.