SuperAPI AI Directory

Memory Layers - Meta's method for increasing the parameters of large models without increasing compute

Author: AI小集 · Original source: AI工具集

What are Memory Layers

Memory Layers is a method introduced by Meta that adds extra parameters to a model using a trainable key-value lookup mechanism, without increasing floating point operations (FLOPs). Sparse-activation-based Memory Layers complement compute-intensive feed-forward layers, providing dedicated capacity to store and retrieve information cheaply. Memory Layers have shown significant practicality in large-scale language models, especially in factual tasks, where they can significantly improve model performance. By replacing one or more feed-forward networks (FFN) in a Transformer layer with memory layers, the model's factual accuracy and knowledge acquisition ability are significantly improved without significantly increasing computational cost.

memory layers

Main features of Memory Layers

  • Parameter expansion: Supports adding extra parameters to a model without increasing the computational burden (i.e., without increasing FLOPs), expanding the model's capacity.
  • Information storage and retrieval: Provides a dedicated mechanism to store and retrieve information.
  • Complementing dense layers: Complements compute-intensive feed-forward layers, providing dedicated capacity for information storage and retrieval based on sparse activation patterns.
  • Improving factual accuracy: In factual tasks, it significantly improves the accuracy of language models, enabling them to more accurately memorize and use facts from training data.
  • Performance improvement: Under matched compute and parameters, it enables model performance to surpass traditional dense models and mixture-of-experts models.

Technical principles of Memory Layers

  • Key-value lookup mechanism: Works based on a simple key-value lookup mechanism, where both keys and values are encoded as embedding vectors. Given a query vector q, a set of keys K and values V, the output is a soft combination of values, with weights determined by the similarity between q and the corresponding keys.
  • Sparse activation: Unlike traditional attention mechanisms, the keys and values in Memory Layers are trainable parameters rather than activation values. Since the number of keys and values is usually very large, Memory Layers require sparse lookup and updates, and only the top-k keys most similar to the query and their corresponding values participate in output computation.
  • Product key lookup: To address the bottleneck of query-key retrieval in large-scale memory, Memory Layers use product-quantized keys, using two smaller sets of keys to efficiently perform top-k lookup over the full key set.
  • Parallelized implementation: Since Memory Layers have large memory requirements, embedding lookup and aggregation are parallelized across multiple GPUs to enable large-scale scaling.
  • Shared memory parameters: Uses a shared pool of memory parameters to improve performance with multiple memory layers without increasing the number of parameters.

Project addresses of Memory Layers

Application scenarios of Memory Layers

  • Question answering systems: In question answering systems, it helps models remember and retrieve large amounts of factual information and provide accurate answers.
  • Language models: In natural language processing, it enhances the memory capability of language models, making them more effective when handling long texts and complex conversations.
  • Recommendation systems: In recommendation systems, it stores users' historical behavior and preferences to provide more personalized recommendations.
  • Knowledge graphs: In knowledge graph applications, it stores and retrieves relationships between entities, supporting complex queries and reasoning.
  • Dialogue Systems: In dialogue systems, it helps models remember the dialogue history, making conversations more coherent and natural.