Conditional Memory: The Second Dimension of Large Model Sparsification

    Current large language model sparsification heavily relies on conditional computation via Mixture of Experts (MoE), which solves compute sparsification but neglects knowledge sparsification. This article introduces "conditional memory" as a second axis of sparsification, dividing model capacity between neural computation and static memory lookup. By modernizing N-gram embeddings into an O(1) lookup module, the model not only reduces redundant computation but also frees network depth for complex reasoning. We explore the U-shaped scaling law of this approach, module design details, counterintuitive gains in reasoning tasks, engineering deployment considerations, and its future role in LLM architecture.

    I. The Problem: Sparsification Has Only Taken One Path

    Current large model capacity scaling heavily relies on the Mixture of Experts (MoE) route. Its essence is conditional computation: each input activates only a portion of the parameters, pushing the parameter count higher while keeping compute power roughly constant. However, this path only solves “compute sparsity” without addressing “knowledge sparsity.”

    The real gap lies in the fact that mainstream Transformer architectures lack a native knowledge lookup primitive. When a model needs to output a fact, a local collocation, or a fixed pattern, it can only rely on multi-layer attention and feed-forward networks to “compute” it—using a computational process to simulate what could otherwise be a constant-time table lookup. This causes a triple waste:

    1. Compute waste: High-frequency, low-entropy static knowledge is repeatedly recalculated.
    2. Depth waste: Shallow layers are forced to bear the memory reconstruction task, compressing the effective depth available for complex reasoning.
    3. Capacity mismatch: Increasing parameters primarily boosts compute capacity rather than knowledge capacity.

    II. Definition and Formalization of Conditional Memory

    Conditional memory is proposed as a complementary second axis to conditional computation: computation is activated on demand, and memory is looked up on demand. Its core is expanding “sparsity” from a one-dimensional allocation problem to a two-dimensional one—under a fixed parameter budget and compute budget, determining how much capacity goes to neural computation and how much to static memory.

    Formally, it can be abstracted as: given a total parameter budget P and a total FLOPs budget F, find the allocation ratio α that minimizes the target loss. Based on this, the research team discovered a U-shaped scaling law: neither extreme (pure compute or pure memory) is optimal; there is an optimal ratio interval that shifts with scale. The value of this law lies in transforming “what module to add” from empirical tuning into an extrapolatable capacity planning problem.

    III. Module Design: Modernizing N-gram Embeddings

    The implementation vehicle is a modernization of classic N-gram embeddings. The key engineering constraint is a lookup complexity of O(1), meaning it does not degrade as the sequence length grows. The schematic structure is as follows:

    1. # Pseudocode: Illustrative data flow, not a specific implementation
    2. class MemoryLookup(nn.Module):
    3. def __init__(self, ngram_order=3, num_shards=64, dim=128):
    4. self.order = ngram_order
    5. self.shards = nn.ModuleList([
    6. nn.EmbeddingBag(num_buckets, dim) for _ in range(num_shards)
    7. ])
    8. def forward(self, token_ids):
    9. keys = self.build_ngram_keys(token_ids, self.order) # Local dependency encoding
    10. shard = keys % len(self.shards) # Shard positioning
    11. out = 0
    12. for i, table in enumerate(self.shards):
    13. mask = (shard == i)
    14. out += mask * table(keys[mask]) # Sparse lookup
    15. return out

    The design focuses on four key points:

    • Key construction: A key is formed by combining several adjacent tokens, delegating local dependencies to table lookup rather than attention.
    • Sharding and hashing: Multi-table sharding reduces individual table size, alleviating memory pressure and improving parallelism.
    • Sparse merging: Only the hit shards’ tables participate in computation, ensuring complexity is decoupled from sequence length.
    • Gated fusion: The memory output is fused with the main backbone’s hidden state using learnable weights to avoid noise injection.

    IV. Benefit Structure: Counterintuitive Gains Beyond Knowledge Metrics

    In controlled experiments with strictly equal parameters and FLOPs, scaling the memory module to approximately 2.7 billion parameters resulted in overall performance significantly superior to the pure MoE baseline. Even more noteworthy is the distribution of gains:

    Capability Dimension Representative Evaluation Change
    Knowledge Retrieval MMLU / CMMLU +3.4 / +4.0
    General Reasoning BBH / ARC-Challenge +5.0 / +3.7
    Code & Math HumanEval / MATH +3.0 / +2.4

    Reasoning gains exceeded knowledge gains. Mechanistic analysis offers two explanations: First, after stripping static knowledge reconstruction from the shallow layers, the effective depth deepens, giving complex reasoning more usable layers. Second, after externalizing local dependencies to table lookup, attention can focus on long-range structures. This suggests that the memory module is not a knowledge patch, but a depth redistributor.

    V. Engineering Implementation Checklist

    • Memory and Bandwidth: Table lookup is a memory-access-intensive operation; it is necessary to evaluate shard layout, cache hit rates, and cross-card communication overhead.
    • Training Stability: Memory table initialization, gate saturation, and sparse gradients are major risk points; it is recommended to conduct a small-scale ratio scan first.
    • Capacity Planning: Use the U-shaped law for small-scale extrapolation; determine α before scaling up to avoid full-scale trial and error.
    • Observability: Hit rates, shard load skew, and memory/compute contribution ratios should be incorporated into routine monitoring and alerting.
    • Deployment Form: Containerized elastic scaling paired with object storage to carry large-scale parameter shards; logging and monitoring systems should cover long-tail latency.

    VI. Boundaries and Outlook

    Conditional memory does not offer universal gains: for tasks highly dependent on long-range reasoning or with low static knowledge density, the benefits may be limited. An expanding table size also brings operational complexity. A reasonable positioning is to treat it as an adjustable dimension in capacity planning, forming a complete coordinate system of sparsification together with conditional computation. As the U-shaped law is repeatedly validated at larger scales, “how to ratio computation and memory” is poised to become a standard preliminary question in next-generation architecture design.