Fast-weight Product Key Memory
Tianyu Zhao, Llion Jones
TL;DR
This work tackles the storage-computation trade-off in sequence modeling by transforming Product Key Memory (PKM) into Fast-weight Product Key Memory (FwPKM), a dynamic memory that updates during both training and inference via chunk-level gradient descent on a local memorization objective. By updating keys and values as fast weights and incorporating lookahead targets, marginal-entropy addressing, and gating, FwPKM acts as a high-fidelity episodic memory that complements semantic memory from slow-weight layers. Empirical results show significant perplexity reductions on long-context datasets and strong generalization to 128K-token contexts in Needle in a Haystack, with iterative readouts further boosting retrieval fidelity. The approach opens a path toward hybrid memory systems that combine large, sparse storage with rapid, context-specific updates, albeit with notable engineering and kernel-performance challenges to achieve broader scalability.
Abstract
Sequence modeling layers in modern language models typically face a trade-off between storage capacity and computational efficiency. While Softmax attention offers unbounded storage at prohibitive quadratic costs, linear variants provide efficiency but suffer from limited, fixed-size storage. We propose Fast-weight Product Key Memory (FwPKM), a novel architecture that resolves this tension by transforming the sparse Product Key Memory (PKM) from a static module into a dynamic, "fast-weight" episodic memory. Unlike PKM, FwPKM updates its parameters dynamically at both training and inference time via local chunk-level gradient descent, allowing the model to rapidly memorize and retrieve new key-value pairs from input sequences. Experiments reveal that FwPKM functions as an effective episodic memory that complements the semantic memory of standard modules, yielding significant perplexity reductions on long-context datasets. Notably, in Needle in a Haystack evaluations, FwPKM generalizes to 128K-token contexts despite being trained on only 4K-token sequences.
