The Second Axis of LLM Sparsity: Conditional Memory
\u200bThis article introduces conditional memory as a second, orthogonal axis of sparsity in large language models, alongside conditional computation popularized by Mixture-of-Experts (MoE). It explains why static, lookup-style knowledge and dynamic computation are mismatched in classic Transformers, how a conditional memory module performs constant-time n-gram key lookups, and how to split a fixed parameter budget between memory and experts. The article also covers the observed U-shaped performance curve, the counterintuitive finding that memory improves reasoning by freeing effective depth, and practical guidance on key design, hash collision handling, gating, budget alignment, serving, and evaluation.
\u200b## 1. Where the Problem Starts: Capacity Grows, Lookup Ability Does Not
Over the past few years, the main line of scaling large language models has been almost singular: Mixture-of-Experts (MoE). Its essence is to partition parameters into “experts,” where each token activates only a few experts. This keeps per-token computation controlled while total parameter count rises sharply. This approach solves the problem of conditional computation: different inputs take different computation paths.
However, scaling has introduced a long-overlooked structural gap: a model’s knowledge is static and lookup-based, while its computation is dynamic and serial. The classic Transformer has no native “knowledge lookup primitive.” It can only approximate a retrieval using attention and feed-forward networks: first encode the query, then compare it against a large set of candidates by similarity, and finally mix the result into the residual stream. This means a lookup that could be O(1) is implemented as a series of matrix multiplications that scale with both sequence length and hidden dimension.
The result is a resource mismatch. To remember more facts, the model is forced to add “computation,” and computation is the primary source of inference cost. Meanwhile, shallow layers are burdened with heavy fact reconstruction, compressing the “effective depth” that should be devoted to multi-step reasoning.
2. Conditional Memory: Splitting Sparsity into Two Orthogonal Dimensions
The core claim of conditional memory is that sparsity should not have only one axis, “conditional computation”; it should have an independent axis, “conditional memory.”
- Conditional computation: the input decides “which compute to use,” decoupling capacity from compute volume.
- Conditional memory: the input decides “which static knowledge entries to read,” decoupling knowledge from the computation path.
The two are complementary, not substitutes. Computation excels at composition, transformation, and multi-step derivation; memory excels at identity mapping, fact recall, and long-tail entry retrieval. Only by allocating both under the same sparsity budget can we talk about an “optimum.”
In engineering terms, the conditional memory module is designed as a modernization of the classic N-gram embedding: it uses a discretized local context (an ordered combination of word or subword identifiers) as the key, maps it to a set of trainable embedding slots, and performs the lookup in constant time without growing with context length. The illustrative code below only conveys the interface shape and is not a specific implementation:
class MemoryLookup(nn.Module):def __init__(self, vocab_size, ngram=2, num_slots=1 << 20, dim=128):super().__init__()self.ngram = ngramself.num_slots = num_slotsself.emb = nn.Embedding(num_slots, dim)def key_of(self, token_ids): # token_ids: [B, L]# Fold the n-gram into a slot index with a rolling hash; collisions are mitigated by multiple slotsh = token_ids[:, 0].clone()for i in range(1, self.ngram):h = (h * 1000003 + token_ids[:, i]) % self.num_slotsreturn hdef forward(self, token_ids):k = self.key_of(token_ids) # O(1) lookup, independent of Lreturn self.emb(k) # [B, dim]
Three engineering constraints deserve emphasis. First, discretizing the key space inevitably causes hash collisions, which must be suppressed through slot count, multiple hashes, and gating. Second, memory reads must be gated; otherwise static entries will pollute the context. Third, slot scale directly determines memory and parameter budget, and must share the same total budget as the compute side.
3. How to Split the Sparsity Budget: Formalization and the U-Shaped Pattern
Once formalized, let the total parameter budget be fixed at P, with a fraction r allocated to memory and 1−r allocated to computation (experts). The goal is to maximize the target metric on the validation set. The empirical conclusion is that performance follows a U-shaped curve with respect to r: both extremes are worse, and an optimum exists in the middle.
The explanation for this pattern is intuitive:
- r too small: the model still uses compute to simulate retrieval, shallow layers keep doing fact reconstruction, and long-tail knowledge is learned poorly.
- r too large: memory entries are plentiful, but composition and reasoning ability are limited, and multi-step tasks lose points.
- Middle region: memory handles identity mapping, computation focuses on transformation and derivation, and the boundary between them is clear.
The practical implication is that r is not hyperparameter mysticism but a one-dimensional problem that can be scanned. In practice, scan r on a small-scale proxy model, observe the crossover point between knowledge-type and reasoning-type metrics, then extrapolate to the target scale. Also keep controlled experiments at equal parameter count and equal FLOPs; otherwise conclusions will be contaminated by budget differences.
4. The Counterintuitive Benefit: Memory Improves Reasoning
Under strict controls of equal parameter count and equal compute, scaling the memory module to a larger parameter size yields overall performance better than a pure conditional-computation baseline. More notably, the distribution of gains is striking: knowledge-type benchmarks improve markedly, while general reasoning, code, and math tasks improve even more.
The mechanistic explanation is the “effective depth” hypothesis: when static facts are provided by the memory module via lookup, shallow layers no longer need to repeatedly reconstruct entity attributes and common collocations, so the “net compute depth” left in the residual stream for multi-step transformations becomes longer. By analogy to engineering practice, this is like peeling the cache layer out of business logic, leaving the main path with only true business orchestration: a shorter chain and more stable latency.
The takeaway for developers: if your bottleneck is “facts won’t stick,” adding a memory module is a direct gain; if the bottleneck is a “broken reasoning chain,” the gain may also come from memory, because what it frees is depth budget, not just knowledge entries.
5. Implementation Notes and Common Pitfalls
- Key design: too small an n underfits the context, while too large an n explodes the slots; subword-level tokenization is usually more stable than word-level.
- Collision handling: the trio of multiple hashes, slot sharding, and frequency pruning prevents high-frequency keys from monopolizing capacity.
- Gating and residuals: read results should be injected after scalar or vector gating to prevent early layers from being dominated by static noise.
- Budget alignment: reported results must state equal parameter count and equal compute; otherwise they are not comparable.
- Serving: memory parameters are large and sparsely accessed, making them suitable for tiered loading and hit-rate observation alongside general cloud capabilities such as object storage, caching, container platforms, and logging with monitoring and alerting; on the training side, focus on distributed sharding and communication overhead.
- Evaluation design: knowledge-type, reasoning-type, and code and math tasks should be examined separately; looking only at an aggregate score can easily mask structural changes.
6. Conclusion
The value of conditional memory is not “adding another module,” but that it expands the coordinate system of sparsity from one dimension to two: computation and memory each handle what they are good at, and budget allocation shifts from guesswork to a scannable, explainable curve. For teams doing model architecture selection, this offers a low-cost validation path: first confirm the U-shaped inflection point at small scale, then decide whether to incorporate the memory axis into the next-generation architecture design.
