Introduction
Running Large Language Models (LLMs) locally on mobile devices is a critical frontier for ensuring user privacy and achieving low-latency responses. This is particularly relevant for Retrieval-Augmented Generation (RAG) tasks, such as personal document assistants or UI automation agents. While Neural Processing Units (NPUs) are the most energy-efficient processors for these tasks, they present significant architectural challenges. Specifically, NPUs struggle with the dynamic nature of LLM inference, which transitions between a compute-heavy prefill phase and a memory-bound decoding phase.
The NPU Bottleneck: Static Graphs and Underutilization
Mobile NPUs typically rely on static compute graphs with fixed shapes to maximize efficiency. However, RAG workflows involve processing large context chunks (prefill) followed by generating tokens one by one (decoding). Switching between these distinct phases often requires a "teardown-and-load" process that can consume up to 29% of total latency. Furthermore, during the decoding phase, the NPU's massive parallel compute capacity often sits idle—over 70% underutilization—because generating a single token does not provide enough workload to saturate the hardware.
The sd.npu Framework
To address these bottlenecks, the authors introduce sd.npu, a framework that co-optimizes software algorithms with NPU hardware through two primary innovations:
Progressive Graph Scheduling
Instead of a global stop-and-start transition between prefill and decoding, sd.npu partitions the LLM into discrete blocks. This allows the system to overlap the loading of decoding-optimized blocks with the ongoing computation of prefill chunks. By masking the I/O overhead, the framework ensures a seamless transition between inference phases.
NPU-Tailored Speculative Decoding
Standard speculative decoding often fails on mobile due to low guess accuracy or insufficient workload. sd.npu optimizes this via:
- In-Context Distribution Calibration: It reuses the probability distributions (logits) calculated during the prefill phase to align draft tokens with the main model's expectations, significantly reducing rejection rates.
- NPU-Optimized Draft Extension: The system recycles high-confidence tokens that were previously rejected to lengthen draft sequences. This ensures the workload is large enough to saturate the NPU's matrix units.
Key Insights: The "Constant-Cost Trap"
A pivotal finding of this research is that on an NPU, verifying a short sequence of tokens costs nearly the same as verifying a long one. Consequently, efficiency is maximized not just by accurate guesses, but by long guesses that reach the hardware's saturation point—typically around 32 tokens for modern mobile NPUs. Additionally, the researchers found that approximately 38.5% of rejected tokens eventually become valid as the context evolves, a phenomenon they exploit to increase throughput without extra compute cost.
Experimental Results
The framework was evaluated on high-end smartphones (e.g., Snapdragon 8 Gen 2, Gen 3, and 8 Elite) using models like Qwen2.5 and LLaMA3.2 across tasks such as document summarization and UI automation.
- Performance:
sd.npudelivered end-to-end speedups ranging from 1.06× to 3.81× compared to standard NPU execution. - Energy Efficiency: The framework achieved up to 4.71× energy savings, making complex RAG tasks viable for "always-on" mobile use cases.
Conclusion
By bridging the gap between rigid NPU architectures and the dynamic requirements of LLMs, sd.npu provides a scalable path for high-performance, energy-efficient mobile AI. Future work will explore finer partitioning granularities and the integration of advanced quantization schemes to further push the boundaries of mobile inference.
Summary updated