FlexInfer: Breaking Memory Constraint via Flexible and Efficient Offloading for On-Device LLM Inference

Hongchao Du, Shangyu Wu, Arina Kharlamova, Nan Guan, Chun Jason Xue · DOI · OpenReview

TL;DR

This paper introduces FlexInfer, a novel framework designed to enable efficient Large Language Model (LLM) inference on resource-constrained devices by intelligently offloading model parameters to slower storage. FlexInfer achieves significant performance improvements (up to 12.5x) over existing methods by employing asynchronous prefetching, balanced memory locking, and flexible tensor preservation, overcoming the memory limitations that typically hinder on-device LLM deployment.

What Problem Does This Paper Address?

Large Language Models (LLMs) have revolutionized many fields, but their massive memory footprint poses a significant challenge for deployment on edge devices like smartphones or embedded systems. These devices often lack the substantial RAM found in cloud servers, making it difficult to run LLMs locally. While existing methods like model compression, distillation, or pruning can reduce memory usage, they often compromise model performance, generality, or adaptability to varying resource constraints. Offloading model parameters to external storage is a promising avenue, but it introduces substantial I/O overhead, which can severely degrade inference speed. This paper addresses the critical need for an efficient and adaptable offloading framework that can maximize LLM performance on memory-limited devices without sacrificing model capabilities.

Methods

FlexInfer tackles the memory constraint problem through a three-pronged approach:

  • Asynchronous Prefetching: This technique aims to overlap I/O operations (loading model parameters from storage) with computation. Instead of waiting for parameters to be fully loaded before computation begins, FlexInfer initiates the loading of subsequent parameters while the current layer is being processed. This is achieved through a multi-threaded, tensor-level prefetching strategy that avoids inefficient small data transfers and maximizes bandwidth utilization. The memory footprint is primarily determined by the size of the "prefetch window," allowing for significant memory reduction.
  • Balanced Memory Locking: To further optimize memory usage and reduce I/O, FlexInfer employs a strategy to retain certain model parameters in memory. Unlike naive approaches that might lock entire layers unevenly, leading to performance bottlenecks, FlexInfer distributes memory usage more uniformly. It divides each layer into a "locked" part (kept in memory) and a "prefetched" part (loaded on demand). This balanced approach ensures consistent I/O workload across layers, enabling more efficient parallelization between I/O and computation threads.
  • Flexible Tensor Preservation: This heuristic algorithm intelligently decides which model parameters should be offloaded and which should be retained in memory, based on the available memory budget. It considers the distinct roles and sizes of attention tensors and feed-forward network (FFN) tensors. The strategy prioritizes FFN tensors when memory is abundant and attention tensors when memory is severely limited, aiming to minimize memory fragmentation and ensure that the remaining parameters across layers do not exceed the size of a single attention tensor. This adaptive approach maximizes memory utilization and balances I/O efficiency.

Datasets

Not discussed in the paper. The evaluation uses pre-trained LLM models.

Key Insights and Ideas

  • I/O is the primary bottleneck: The paper strongly emphasizes that for LLMs on memory-constrained devices, the latency introduced by loading model parameters from storage (I/O overhead) is the main performance killer, far more so than the computational cost itself.
  • Asynchronous operations are crucial: Simply offloading isn't enough; the key is to hide the I/O latency by overlapping it with computation. This is where asynchronous prefetching shines.
  • Uniformity in memory management pays off: Even when retaining some parameters in memory, an uneven distribution (e.g., locking whole layers) creates performance imbalances. Balanced locking, which distributes memory usage more evenly, leads to better overall throughput.
  • Intelligent parameter selection matters: Not all parameters are equal in their impact on inference. A flexible strategy that prioritizes certain types of tensors (attention vs. FFN) based on available memory can significantly improve efficiency.

Key Results

FlexInfer demonstrates substantial performance improvements across various LLM models (Llama2-7B, Llama2-13B, Codellama-34B, and Llama2-70B) under different memory-constrained scenarios. Compared to the baseline mmap approach, FlexInfer achieves performance improvements ranging from 4.2x to 12.5x. Ablation studies show that prefetching alone can improve performance by up to 69.9-118.8%, while balanced locking contributes significantly, especially with more available memory (up to 56.8-83.3% improvement). The flexible tensor preservation strategy also yields notable gains, outperforming simple "attention-first" or "FFN-first" strategies by up to 21.9% and 7.8% respectively.

Limitations and Future Work

The paper acknowledges that its current implementation focuses on CPU inference, as most resource-constrained devices lack powerful GPUs. While FlexInfer is designed to be generally applicable to transform-based models, its specific heuristics for tensor preservation might benefit from further refinement for models with architectures like GQA (Grouped Query Attention), where it notes that its strategy produces similar optimal results to "Attn-first" in most cases. Future work could explore extending FlexInfer to GPU-accelerated edge devices or investigating more sophisticated adaptive strategies for tensor preservation.

Summary updated

BibTeX
@inproceedings{du2025flexinfer,
  author = {Hongchao Du and Shangyu Wu and Arina Kharlamova and Nan Guan and Chun Jason Xue},
  title = {{FlexInfer: Breaking Memory Constraint via Flexible and Efficient Offloading for On-Device LLM Inference}},
  booktitle = {EuroMLSys},
  year = {2025},
  doi = {10.1145/3721146.3721961},
}
Figure