TL;DR
Memory Grafting introduces a highly efficient way to scale language model capacity by reusing frozen hidden states from large, pre-trained "grafting" models as an offline external memory bank. By retrieving these high-quality representations via an $O(1)$ longest-match suffix lookup, smaller recipient models achieve significant performance gains during pre-training with minimal computational and inference overhead.
What Problem Does This Paper Address?
Scaling large language models (LLMs) traditionally demands massive increases in both parameter counts and training tokens, leading to skyrocketing engineering and computational costs. To mitigate this, researchers have turned to sparse architectures like Mixture-of-Experts (MoE) or conditional memory systems (such as Engram), which look up entries in a massive external table at each token step rather than executing heavy computations.
However, existing conditional memory methods suffer from a major bottleneck: they learn their memory tables entirely from scratch during pre-training. As the memory module scales to dominate the model's total parameter count (e.g., exceeding 70%), training efficiency sharply declines. The authors address this limitation by asking a clever question: Why learn these representations from scratch when a large, pre-trained model has already mastered them?
Methods
The authors propose Memory Grafting, a framework that shifts the burden of memory construction offline. The pipeline consists of two main phases:
- Offline Construction: The authors identify high-frequency $n$-grams from a corpus. They pass these phrases through a large, pre-trained "grafting model" (e.g., Qwen3.5-35B) and extract the hidden states of the final token from an intermediate layer. These vectors are saved as a frozen, exact $n$-gram-indexed memory bank.
- Online Forward & Retrieval: During the pre-training of a smaller recipient model, the system performs an exact longest-match suffix lookup to find the given context in the frozen memory bank.
- Match: If an $n$-gram matches, the frozen representation is retrieved and integrated into the recipient model via lightweight projection layers and an adaptive query-key gating mechanism.
- Miss (Fallback): If no match is found, the system seamlessly falls back to a standard, trainable hash-based Engram memory layer to ensure full coverage over arbitrary text.
Because the exact lookup operates with an expected complexity of $O(1)$ relative to the memory bank size, it adds virtually no computational overhead during training or inference.
Datasets
- Pre-training Corpus: Subsets of the Nemotron-CC dataset (a 50B-token subset for the 0.92B recipient model and a 100B-token subset for the 2.8B recipient model).
- Evaluation Benchmarks: The models were evaluated using the
lm-evaluation-harnessacross 9 standard downstream tasks: ARC-Challenge, ARC-Easy, BoolQ, Social IQA, RACE, LAMBADA, WinoGrande, PIQA, and HellaSwag.
Key Insights and Ideas
- The "Aha" Layer Match: The choice of which layer to extract memory from in the grafting model is critical. Intermediate layers (around 10% to 60% of the model depth) yield the best results. Deeper layers provide representations that are too abstract and tightly coupled to the donor model's specific internal mechanics, making them difficult for a smaller recipient model to utilize.
- Memory Geometry Matters: Not all pre-trained models make good donors. Models like Qwen3.5 and DeepSeek-V2 exhibit high-dimensional, stable, and discriminative memory geometries. In contrast, models like GLM-4.7-Flash produce highly anisotropic (nearly collinear) vectors, which significantly limits downstream performance gains.
- Representation Alignment: Centered Kernel Alignment (CKA) analysis revealed that grafting memory actually alters the recipient model's internal representation space. It forces shallower layers of the recipient model to exhibit features similar to much deeper layers of the large donor model early on.
Key Results
- 2.8B Parameter Scale: When training a 2.8B total / 0.55B activated parameter MoE backbone on 100B tokens, Memory Grafting achieved an average benchmark score of 53.86%, outperforming both the vanilla MoE baseline (51.95%) and the vanilla Engram baseline (52.43%).
- 0.92B Parameter Scale: Varing the donor model showed consistent improvements. Grafting from Qwen3.5-35B-A3B yielded the highest average score of 46.98% (compared to 45.62% for MoE and 45.03% for Engram).
- High Efficiency: Despite offloading a massive external memory bank (up to 24 GB of frozen parameters), Memory Grafting maintained 0.92× training throughput and 0.95× inference throughput relative to the MoE baseline, while keeping memory consumption virtually unchanged (0.97×).
Limitations and Future Work
- Lack of Direct Comparison to Knowledge Distillation (KD): The authors note that a full comparison against from-scratch online knowledge distillation was omitted due to extreme compute constraints (online KD would require running the massive teacher model forward pass for every single training token, increasing compute costs by ~5×).
- Future Directions: Promising next steps include scaling the memory bank to even larger $n$-gram counts and higher orders, exploring alternative non-additive residual updates, and applying Memory Grafting to post-training or continual learning scenarios to inject domain-specific knowledge without risking catastrophic forgetting.
Summary updated