The Second Dimension of LLM Sparsity: Conditional Memory
This article examines conditional memory, an approach that treats sparsity as two orthogonal dimensions—conditional computation and conditional memory—rather than relying on Mixture-of-Experts (MoE) alone. It explains why mainstream Transformer architectures lack a native knowledge-lookup primitive, how a conditional memory module turns lookup into an O(1) operation, the U-shaped scaling pattern observed when splitting capacity between memory and computation, why memory modules improve reasoning more than factual recall, and how to validate and operate such a design in practice. The article is vendor-neutral and focuses on general technical design, scaling behavior, and engineering deployment.
When people discuss sparsification of large language models, the industry has long concentrated on the Mixture-of-Experts (MoE) path: a gating network activates only part of the parameters, trading conditional computation for expanded capacity. A recent piece of work, produced by a research team in collaboration with a university and released with a reference implementation, raises a question that is easy to overlook: mainstream Transformer architectures have no native “knowledge lookup” primitive, so the model can only simulate retrieval inefficiently through a chain of matrix multiplications. That work splits sparsification into two orthogonal dimensions—conditional computation and conditional memory—and proposes a concrete design called a conditional memory module. This article does not discuss any specific product; it breaks down the design logic, scaling behavior, and engineering deployment from a general technical perspective.
1. Background: Retrieval Disguised as Computation
When humans read and encounter a familiar place name, term, or code snippet, they usually retrieve it directly from memory instead of deriving it on the spot. Current mainstream language models have no such mechanism. Knowledge is diffused across the network as distributed weights, so any factual recall has to be “recomputed” through multiple layers of nonlinear transformations.
This leads to three structural costs:
- Wasted compute: retrieval is essentially a table lookup, yet it is implemented as floating-point operations that scale with depth.
- Capacity coupling: to store more facts, you can only scale up the parameters as a whole, so inference cost is linearly bound to the amount of knowledge.
- Depth crowding: shallow layers are forced to carry a large amount of fact reconstruction work, compressing the “effective depth” left for abstraction and reasoning.
MoE eases the decoupling of parameter count from compute, but it does not solve the decoupling of knowledge from computation. That is precisely the gap conditional memory aims to fill.
2. Core Idea: Making Lookup an O(1) Operation
The starting point of conditional memory is to give the model an addressable static knowledge table, so that when an input hits a given key, the value is fetched directly rather than passing through the full forward computation. Four key design points summarize the approach:
- A modernized n-gram embedding. Classic n-grams only count local co-occurrence; this work upgrades them into learnable, addressable memory units, where the key is obtained by hashing a local token sequence and the value is a trainable vector.
- Constant-time addressing. The lookup path does not grow with model depth; complexity is O(1), decoupled from sequence length and layer count.
- Division of labor with attention. Local dependencies are handled by lookup, while attention focuses on global context modeling, freeing up capacity.
- Complementarity with expert layers. Experts handle “how to compute,” memory handles “what is known,” and the two are connected in series rather than replacing each other.
Illustrative pseudocode can express this division of labor:
# Pseudocode: illustrates only the order of collaboration between conditional memory and the expert layerdef block(x, tokens):# 1) Local key construction: hash a combination of neighboring tokens into a bucket idkey = hash_ngram(tokens, n=3) % num_buckets# 2) O(1) lookup: fetch the static memory vector on a hitmem = embedding_table[key] # shape: [d]gate = sigmoid(W_gate @ x) # scalar gate that decides injection strengthx = x + gate * mem# 3) Global modeling: attention handles long-range dependenciesx = attention(x)# 4) Conditional computation: the expert layer performs the nonlinear transformationx = moe_experts(x)return x
The genuinely hard part in engineering is not the lookup itself but key collisions and load balancing: the number of hash buckets is limited, popular n-grams crowd out capacity, and cold entries are barely updated. Common mitigations include multiple hashing, frequency-tiered capacity allocation, and sparse regularization on the memory vectors, so that high-frequency knowledge receives a larger quota.
3. Sparsity Allocation and the U-Shaped Scaling Pattern
The work formalizes “how much capacity goes to computation versus memory” as a sparsity allocation problem and observes a U-shaped pattern: under a fixed total parameter and total compute budget, neither pure memory nor pure computation is optimal; there is an intermediate ratio that performs best. As scale grows, the optimal memory share shifts slowly, but the U shape remains stable.
The value of this pattern is that it turns architecture selection from empirical tuning into a predictable engineering decision. Practical implications include:
- Under a budget constraint, fix the ratio first and the scale second, avoiding blindly piling up expert counts.
- Returns from growing memory capacity show diminishing marginal gains, so hit rate should be monitored rather than parameter count alone.
- Matched-parameter, matched-compute controlled experiments are the only reliable way to judge whether gains are real.
In an experiment scaling the memory module to roughly 27 billion parameters, overall performance was better than a pure-MoE baseline under matched parameter and compute conditions.
4. Where the Gains Come From: Why Memory Improves Reasoning
A counterintuitive observation is that although the memory module primarily targets factual knowledge, the improvements on general reasoning and code/math tasks are more pronounced. In the public data, knowledge-oriented evaluations show gains of a few points, while general reasoning and code/math tasks show larger gains. Two factors explain this:
- Increased effective depth. Shallow layers no longer spend compute reconstructing static facts, which is equivalent to making the network “deeper,” giving complex multi-step reasoning more compute budget.
- Freed attention capacity. Once local co-occurrence is handled by lookup, attention heads can focus on long-range structure, and long-context retrieval ability improves accordingly.
This also suggests evaluation methods need adjustment: looking only at knowledge QA underestimates the value of the memory module, so multi-step reasoning, long context, and code tasks should be covered as well.
5. Deployment Practice and Supporting Capabilities on Baidu AI Cloud
To validate a similar architecture in your own workloads, a four-step approach is suggested:
- Small-scale controlled comparison. Fix the compute and parameter budget, vary only the memory share, and plot the U-shaped curve to locate the optimum.
- Data-side governance. Analyze the n-gram distribution, build a high-frequency knowledge lexicon, and control the key collision rate and bucket load variance.
- Service-side decoupling. The memory table is large but accessed sparsely, so it fits an independent storage and caching layer, with high-throughput storage and distributed caching serving queries; the model itself can scale elastically on a container platform.
- Observability. Use logging and monitoring/alerting to track hit rate, bucket load, mean gate value, and tail latency; an abnormal drop in hit rate is often an early signal of data distribution drift.
On Baidu AI Cloud, this kind of validation can combine general capabilities such as object storage, distributed caching, container platforms, and monitoring/alerting: training and inference workloads are orchestrated as containers, the memory table is distributed to each instance as a read-only snapshot, and monitoring metrics are used to locate lookup hotspots during load testing. It is worth stressing that whether the gains hold depends entirely on matched-budget controlled experiments, and any architecture change should first establish a trustworthy baseline.
6. Limitations and Outlook
Conditional memory is not free of cost: a static table creates storage and distribution pressure; key construction relies on a local window, so coverage of knowledge requiring long-range coreference is limited; and if the memory update strategy is poorly designed, stale entries can easily accumulate during continued training. Reasonable directions for evolution are combining memory with retrieval-augmented generation, organizing memory in domain-specific tiers, and letting the gate learn “when to look up and when to compute.” Extending sparsification from a single computation dimension to two dimensions—computation and memory—provides a clear path toward higher intelligence density under a fixed compute budget, and is worth continued tracking and reproduction by architecture designers.
