LLM Inference Without Full-Network Reads: Less Compute per Layer for Memory Writes, 42% Higher Throughput
This article presents a vendor-neutral engineering framework for optimizing large language model inference without modifying original model weights. It explains how to decouple memory writes from next-token prediction during prefill, compress recurrent states using low-rank plus principal-direction decomposition, and integrate the approach into a general inference stack. It also covers evaluation methodology, applicability boundaries, and common misconceptions, showing how these techniques reduce prefill compute and decoding-side state memory while improving throughput.
1. Background: Why Reading the Entire Network Is Wasteful
In long-context inference, code completion, and multi-turn AI Agent conversations, the cost structure is shifting. Compute used to be dominated by decoding (generating one token at a time). Today, a large share of compute is consumed by the prefill stage: an input of tens of thousands of tokens must complete a full forward pass across all layers to write the key-value cache (KV Cache) and recurrent state for repeated reads during subsequent generation.
There is an often-overlooked asymmetry here: the deep computation required to “write memory for future generation” can be far less than the deep computation required to “predict the next token.” Predicting the next word requires the model to use its full representational capacity, whereas writing memory mainly projects, normalizes, and stores existing representations—a relatively mechanical task. Binding these two tasks into the same full forward pass forces every token to “read the entire network.”
This article discusses a class of hybrid architecture LLMs (inter-layer hybrid attention combined with recurrent/linear state updates, with 48 layers as an example). It presents a vendor-neutral engineering optimization framework that reduces both prefill compute and decoding-side state memory through lightweight new components and distillation training, while keeping all original model weights frozen.
2. Core Idea 1: Decoupling Memory Writes from Next-Token Prediction
2.1 Reassigning Responsibilities Across Layers
Let the total number of model layers be L (in the example, L=48), and choose a split layer k (in the example, k=31). When processing the input:
- Tokens at positions
0 .. n-2run only the firstklayers; - A lightweight “memory write component” generates the KV Cache and recurrent state for the remaining
L-klayers; - The last position
n-1still runs allLlayers to produce the first prediction distribution; - During generation, each new token still goes through all
Llayers, keeping the output-quality path unchanged.
The control flow is illustrated below (pseudocode):
def prefill_separated(hidden, k, L, write_mem):# hidden: [n, d], input embeddingsh = run_layers(hidden, layers=0..k) # first k layers, all tokenskv_tail, state_tail = write_mem(h, k, L) # lightweight component writes deep-layer memoryh_last = run_layers(hidden[-1:], layers=0..L)# only the last token goes through all layersreturn h_last, merge_cache(kv_tail, state_tail)
2.2 Why It Works: Measurable and Verifiable
This difference is not an assumption. It can be measured directly on an already-trained hybrid LLM: with a fixed input, compare the downstream generation distribution differences (such as KL divergence, top-1 agreement rate, and task metric gaps) between “deep-layer caches written by a full forward pass” and “deep-layer caches written by the lightweight component.” If the differences remain controlled across multiple models and checkpoints, the approximation is functionally equivalent.
2.3 Training Approach: Frozen Backbone Plus Distilled New Components
- Original model weights remain unchanged, avoiding precision drift and compliance risk;
- The new components learn through distillation what the deep-layer caches should look like, with teacher signals coming from intermediate outputs of the original model’s full forward pass;
- The loss can be combined as:
L = λ1 * L_cache + λ2 * L_state + λ3 * L_task, whereL_taskconstrains the last all-layer path using the real next token.
3. Core Idea 2: Low-Rank Plus Principal-Direction Compression of Recurrent States
3.1 Observation
During each read and write step, recurrent/linear states typically have a dominant component close to a fixed direction (viewable as a long-term bias or mean flow), while the rest is low-rank structure. This means storing the state as a dense matrix is redundant.
3.2 Representation and Update
Decompose the state S as:
S ≈ u * v^T + A * B^T
Here, u is the principal direction (obtained per layer from statistics and frozen or slowly updated), and A and B are low-rank factors. The model reads and updates directly in this decomposed form, avoiding materializing the full matrix at every step.
# State read: do not expand the full matrixdef read_state(u, v, A, B, q):return (q @ v) * u + (q @ B) @ A.T# State update: update only low-rank factors and scalar coefficientsdef update_state(u, v, A, B, k, g):v = v + g * kA, B = lowrank_update(A, B, k, g)return u, v, A, B
3.3 Magnitude of Gains (Illustrative)
In the example configuration, the recurrent state per request drops from about 113.2MB to 29.2MB immediately after compression, averaging about 43.4MB over the full compression cycle. For high-concurrency scenarios, this directly translates to more concurrent sessions and fewer state swaps in and out.
4. Engineering Implementation: Integration into a General Inference Stack
- Graphs and kernels: Implement layer splitting and state decomposition as custom operators in the inference engine to avoid scheduling overhead from Python-level loops;
- Batching strategy: During prefill, split “first k layers batched” and “last token all layers” into two batches to reduce blocking between long and short requests;
- Cache management: Design a dedicated memory pool for decomposed states, reclaiming them by request lifecycle and using paged caching to reduce fragmentation;
- Numerical stability: Low-rank updates require orthogonalization and periodic re-orthogonalization to prevent factor drift; the principal direction should be maintained with sliding statistics;
- Observability: Add instrumentation in the monitoring and alerting system for split-layer hits, compression ratio, state error, and P90 end-to-end output rate.
5. Evaluation Methodology: Dual-Track Validation of Throughput and Accuracy
- Throughput side: On general GPU instances and mainstream inference frameworks, using coding-agent conversation traces as the workload, report the peak throughput improvement per GPU (16%–42% in the example). At the comparison point of the same P90 user end-to-end output rate, the throughput improvement range is 23%–42%. Emphasize that an “equal-latency comparison point” better reflects real user experience than peak throughput alone.
- Accuracy side: Cover quality evaluation across five models and six checkpoints, reporting task metric gaps and distribution distances. Since the backbone is frozen, accuracy risk mainly comes from approximation errors of the new components.
- Ablation: Separately disable “split-layer memory writes” and “state compression” to quantify their individual contributions and mutual interference.
6. Applicability Boundaries and Common Misconceptions
- Not applicable: Very short inputs, single-shot generation, and scenarios highly sensitive to the first-token distribution, where gains are limited;
- Use with caution: For tasks with extremely high requirements on cache numerical precision, increase the low-rank rank or shorten the re-orthogonalization cycle;
- Misconception 1: Assuming all deep computation can be skipped—the last token and the generation stage must go through all layers;
- Misconception 2: Treating compression as lossless—always use task metrics, not compression ratio alone, as the acceptance criterion.
7. Conclusion
Separating “writing memory” from “reading the entire network” and using structured decomposition to carry recurrent states is an effective path to optimize both prefill compute and decoding memory without changing model weights. For teams deploying inference services on general compute and container platforms such as Baidu AI Cloud, along with object storage, logging, and monitoring and alerting capabilities, this method can serve as a general engineering paradigm for capacity planning and cost optimization: first measure the asymmetry, then reassign responsibilities across layers, and finally close the loop with dual-track evaluation.
