Abstract
Large Language Models (LLMs) are typically constrained by the "memory wall," requiring substantial DRAM to store model weights. This paper presents a breakthrough method for running LLMs on devices with limited memory by utilizing flash memory as the primary storage. By exploiting activation sparsity and optimizing hardware-specific data access patterns, the authors achieve up to a 25x speedup on GPUs and 4-5x on CPUs. This approach enables models to run effectively on devices with only half the required DRAM, significantly expanding the feasibility of on-device AI.
Introduction
The deployment of Large Language Models (LLMs) on consumer hardware is primarily limited by memory capacity. For instance, a 7-billion parameter model requires approximately 14GB of DRAM for half-precision weights, exceeding the capacity of many smartphones and entry-level laptops. While flash memory offers abundant storage, its lower bandwidth compared to DRAM makes naive weight loading during inference prohibitively slow. This research addresses the challenge of bridging the bandwidth gap between slow flash storage and fast processors to enable practical "off-RAM" inference.
Methods
The proposed inference engine treats flash memory as primary storage and DRAM as a dynamic cache. The system is built on four key technical pillars:
1. Low-Rank Predictors
LLMs utilizing ReLU activations exhibit significant sparsity, with often less than 10% of neurons firing for a given input. The authors employ small, low-rank models to predict active neurons in the subsequent layer, allowing the system to load only essential weights from flash.
2. Windowing and Re-use
To minimize data transfers, the system maintains a "sliding window" of recently activated neurons in DRAM. This exploits temporal locality, as certain neurons are frequently reused across consecutive tokens, significantly reducing the volume of data that needs to be fetched from storage.
3. Row-Column Bundling
Flash memory throughput is maximized with large, sequential reads. The authors bundle corresponding columns of "up-projection" and rows of "down-projection" matrices, doubling the chunk size and maximizing flash performance.
4. Optimized DRAM Management
A custom memory allocator manages weights by stacking new data and replacing expired neurons, avoiding the overhead of frequent re-allocation and memory fragmentation.
Results and Insights
The "LLM in a flash" method demonstrates that hardware-aware algorithmic design can overcome physical memory limitations.
Performance Gains
The method achieved significant latency reductions across various hardware and model configurations. On Apple M1/M2 chips and NVIDIA RTX 4090 GPUs, speedups reached 20x-25x compared to naive loading. For an OPT 6.7B model on an M1 Max, I/O latency per token was reduced from 2100ms to 87ms.
Key Insights
- Sparsity as a Resource: Sparsity is leveraged as a hardware optimization tool. "Relufying" models can further enhance this effect.
- Hardware-Awareness: Designing for the specific characteristics of NAND flash (high sequential throughput vs. high random access latency) is essential for real-world performance.
- Look-ahead Prediction: Active neurons can be predicted using the current layer's attention output, allowing computation and memory loading to overlap.
Limitations and Future Work
While promising, the current approach focuses on single-batch inference. Future research is needed to scale these techniques to multi-batch server scenarios. Additionally, the impact on total energy consumption and thermal management due to extended inference times requires further study. The management of the Key-Value (KV) cache, which also consumes significant DRAM in long sequences, remains an area for optimization. Finally, combining these methods with quantization could potentially enable even larger models (e.g., 70B) to run on standard mobile devices.
Summary updated