LLM Inference Acceleration for Hybrid Models: Optimizing the Prefill and Decode Stages
This article explains how to accelerate inference for hybrid large language models by separating prefill and decode optimizations. It covers why the fixed-length recurrent state in hybrid architectures still consumes substantial GPU memory, how a write-only memory path can reduce prefill compute while keeping base weights frozen, and how storing the recurrent state in a low-rank factorized form lowers memory and bandwidth pressure during decoding. It also summarizes reported throughput gains, accuracy validation, and practical rollout guidance for long-context, high-concurrency agent workloads.
1. Background: The Memory Cost of Hybrid Architectures Is Underestimated
Mainstream LLM inference architectures are shifting from pure attention toward hybrid designs: a small number of softmax attention layers hold the KV Cache that grows with context length, while a large number of linear attention or state space layers maintain a fixed-length recurrent state. The motivation is clear—trade a controlled amount of GPU memory for long-context capability.
One point that is often overlooked in engineering practice is that a “fixed-length” recurrent state does not mean a “small” one. In one class of hybrid LLMs, the recurrent state for a single request occupies roughly the equivalent of about 4,500 tokens when measured against attention cache. As concurrent requests increase and the prefix cache stays resident, this memory competes with active requests for resources, directly limiting the maximum batch size and therefore throughput.
So optimization has to be considered on two sides:
- Prefill: compute-intensive, with heavy deep-layer computation, but most of that computation is not for predicting the next token.
- Decode: memory- and bandwidth-intensive, since every generated token requires reading and writing the recurrent state once.
2. Core Insight: Writing Memory Takes Far Less Compute Than Predicting
Prefill has one structural fact: only the output of the last input token is used to predict the first response token. Every other token exists to “write” information into each layer’s KV Cache and recurrent state, so later generation steps can read it.
This means the deep computation that serves “writing memory” is not equally important as the deep computation that serves “predicting the next token.” A common industry technique is early exit: feed shallow hidden states straight into the output head for prediction. The acceleration approach discussed here takes a different path—feed shallow hidden states directly into the write path of the subsequent layers, skipping the remaining deep computation and keeping only what is needed to write memory.
The difference can be expressed with illustrative code:
# Traditional early exit: shallow -> output head, for predictionh = layers[0:31](x)logits = output_head(h) # serves prediction only# Write-path acceleration: shallow -> write branch of later layers, to fill memoryh = layers[0:31](x)for layer in layers[31:48]:layer.write_memory_only(h) # updates KV / recurrent state only
On hybrid LLMs, the feasibility of this “shallow write, deep memory” approach has been systematically validated: researchers measured the compute difference between the write path and the prediction path across multiple trained hybrid models and multiple checkpoints, and used that difference to cut prefill compute. The key engineering constraint is that the original model weights stay frozen throughout, and the added lightweight write components are trained via distillation, so the base model does not need to be retrained and the migration cost is low.
3. Decode-Side Optimization: Store the Recurrent State as a Low-Rank Decomposition
The second optimization is on the decode side. The observation is that the recurrent state read and written at each step usually has a dominant component close to a fixed direction, with the remainder showing low-rank structure. Given that structure, there is no need to move it around repeatedly in dense form.
The approach is to store the state in that decomposed form (dominant direction plus low-rank residual) and let the model read and update directly in this representation, avoiding the per-step “decompress—compute—recompress” round trip. The compression results are representative: for one hybrid model, the per-request recurrent state dropped from 113.2MB to 29.2MB right after compression, averaging about 43.4MB over the full compression cycle.
For an inference engine, this brings three benefits:
- Lower memory usage, allowing higher concurrency and longer context;
- Lower bandwidth pressure from per-step state reads and writes, making decoding more stable;
- Reduced memory contention with active requests and the prefix cache, giving more flexibility in batch scheduling.
4. Results and Accuracy: Throughput Gains and Quality Checks
On a single flagship-class GPU, a mainstream inference serving framework, and long-context real workloads such as coding-agent session traces, this approach raised peak throughput per GPU for a hybrid LLM by 16%–42%; at comparison points aligned by P90 user end-to-end output rate, the throughput gain was 23%–42%.
Accuracy was validated as well: quality evaluations covering multiple models and multiple checkpoints verified whether “less prefill compute plus compressed decode state” introduces any perceptible loss. Because the base weights are frozen and only the added components take part in distillation training, the accuracy risk stays within a controllable range.
It is worth stressing that these numbers come from specific hardware, a specific framework, and specific workloads. They are measured results for this approach and should not be extrapolated into a guaranteed benefit in any environment.
5. Engineering Implementation Notes
- Profile first: measure the actual share of the recurrent state and the KV Cache to confirm whether the bottleneck is memory or compute.
- Roll out in stages: enable the prefill write-path optimization first and watch time-to-first-token and quality; then enable decode state compression.
- Align monitoring: use P90 end-to-end output rate rather than average throughput as the acceptance metric, so long-tail behavior is not hidden by averages.
- Stay cache-compatible: once the state representation changes, the prefix cache hit and reuse logic must be adapted accordingly.
- Keep a rollback path: the added components and the compression switch should be disableable at runtime to ease fault isolation.
6. Conclusion
Optimizing inference for hybrid-architecture LLMs is essentially about separating two things that have been mixed together: prediction and writing memory. In prefill, do less deep prediction computation; in decode, store and move less recurrent state. Neither path depends on retraining the base model, and both have clear accuracy validation methods. For teams that need to squeeze more per-GPU throughput out of long-context, high-concurrency agent scenarios, this is a general engineering pattern worth adding to the inference engine iteration roadmap; in inference serving practice on platforms such as Baidu AI Cloud, this kind of methodology—staged, rollback-capable, and validated by P90—applies equally well.
