Abstract
Large Language Models (LLMs) are increasingly constrained by the "memory wall" when deployed on edge devices. While offloading weights to external storage provides a path to running large models on limited RAM, traditional methods like mmap suffer from severe I/O bottlenecks. This paper introduces FlexInfer, an optimized offloading framework that utilizes asynchronous prefetching and a novel balanced memory locking strategy. By ensuring a uniform I/O workload across model layers, FlexInfer achieves up to 12.5x higher inference throughput compared to standard offloading techniques, enabling high-parameter models to run efficiently on resource-constrained hardware.
Introduction
The primary barrier to local LLM deployment is the massive memory footprint required for model weights. For instance, a Llama2-70B model requires over 35GB of memory just for basic loading, far exceeding the capacity of typical smartphones or embedded systems. Current solutions generally fall into two categories: model compression (quantization/pruning) and offloading. While compression reduces size, it often degrades accuracy and lacks hardware-specific flexibility. Offloading, which uses external storage (like SSDs) as virtual RAM, preserves model quality but is typically hampered by I/O latency, often resulting in performance below 1 token per second.
FlexInfer addresses these I/O bottlenecks directly, transforming offloading-based inference into a high-performance pipeline capable of real-world utility without sacrificing model integrity.
The FlexInfer Framework
FlexInfer optimizes the data pipeline between storage and memory through three primary mechanisms:
1. Asynchronous Prefetching
To prevent the CPU from idling while waiting for data, FlexInfer implements dedicated I/O threads that "look ahead" in the model's computational graph. While the CPU processes Layer $N$, the I/O threads concurrently fetch Layer $N+1$ into a prefetch window. This overlap of computation and data transfer effectively hides storage latency.
2. Balanced Memory Locking
A critical insight of FlexInfer is the rejection of traditional layer-based locking. Standard offloading might lock the first few layers in RAM and offload the remainder, creating an "unbalanced" workload where some layers process instantly and others cause significant stalls. FlexInfer instead locks a uniform portion of every layer in RAM. This ensures that the I/O demand remains consistent throughout the entire inference pass, maintaining a smooth pipeline flow and eliminating the synchronization "hiccups" that plague traditional methods.
3. Flexible Tensor Preservation
LLM layers are composed of different tensor types, such as Attention and Feed-Forward Network (FFN) tensors. FFN tensors are typically three times larger than Attention tensors. FlexInfer employs a heuristic algorithm to determine which specific tensors should remain in RAM based on the user's specific memory budget. This allows the system to optimize for either the total number of I/O operations or the total volume of data transferred, depending on the hardware's specific constraints.
Experimental Evaluation
Methodology
The authors evaluated FlexInfer using the Llama2 series (7B, 13B, and 70B) and Codellama-34B. To simulate edge environments on high-end hardware, the researchers used an Ubuntu server (AMD 7995WX CPU) but artificially restricted available memory (1GB to 35GB) and CPU cores using cgroup and taskset. This controlled environment allowed for precise measurement of how the system scales as memory becomes increasingly scarce.
Performance Results
FlexInfer demonstrated significant performance gains over the standard mmap baseline:
- Throughput: FlexInfer outperformed
mmapby 5.2x to 12.5x across various models and memory limits. - Scalability: Unlike
mmap, which often remains stagnant due to inefficient page swapping, FlexInfer showed a clear performance increase as more RAM was allocated. For Llama2-70B, the system effectively utilized additional memory to reduce I/O overhead linearly. - Ablation Analysis: Prefetching alone accounted for a 35-60% improvement, while the addition of Balanced Memory Locking provided an additional boost of up to 83% in moderate-memory scenarios.
Discussion and Key Insights
The success of FlexInfer highlights that in memory-constrained environments, uniformity is more critical than total data residency. By distributing the I/O workload evenly across the model, the system avoids the "long tail" latency of individual slow layers. Furthermore, moving from layer-level to tensor-level management allows for a much finer granularity of control, enabling the system to adapt to specific RAM budgets (e.g., 4.5GB vs 8GB) with mathematical precision.
Limitations and Future Work
While FlexInfer represents a major step forward for CPU-based inference, several areas remain for future exploration:
- Heterogeneous Computing: Extending these strategies to mobile GPUs and NPUs is essential for modern smartphone integration.
- Dynamic Resource Allocation: The current model assumes a static memory budget. Future iterations could adjust the "locked" tensor set dynamically as available system RAM fluctuates.
- Hardware Endurance: The long-term impact of continuous, high-volume read cycles on consumer-grade flash storage lifespan warrants further investigation, though read operations are generally less damaging than writes.
Conclusion
FlexInfer demonstrates that the "memory wall" can be bypassed through intelligent I/O orchestration. By treating LLM inference as a streaming problem and prioritizing pipeline balance, FlexInfer enables large-scale models to run on modest hardware at speeds previously thought impossible for offloading-based systems.
Summary updated