arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.05858cs.AI
收藏

利用NPU实现快速端侧LLM推理

Fast On-device LLM Inference with NPUs

Peking University(北京大学);Beijing University of Posts and Telecommunications(北京邮电大学)

Daliang Xu, Hao Zhang, Liming Yang, Ruiqi Liu, Gang Huang, Mengwei Xu, Xuanzhe Liu

AI总结:

针对端侧LLM推理预填充延迟高的问题,提出llm.npu系统,通过提示词、张量和块三级重构实现NPU卸载,平均预填充提速22.4倍,能耗节省30.7倍,端到端最高加速32.8倍。

摘要:

随着隐私问题日益受到关注以及移动端规模模型的进步,大型语言模型(LLM)的端侧推理引起了广泛兴趣。然而,即便是移动端规模的LLM(如Gemma-2B)也面临不可接受的高推理延迟,在屏幕UI理解等任务中,延迟通常受限于预填充阶段。我们提出了llm.npu,这是首个利用端侧神经处理单元(NPU)卸载来降低预填充延迟的LLM推理系统。llm.npu通过三个层面重构提示词和模型来提升NPU卸载效率:(1)在提示词层面,它将可变长度的提示词划分为多个固定大小的块,同时保持数据依赖关系;(2)在张量层面,它识别并提取显著离群值,以最小开销在CPU/GPU上并行运行;(3)在块层面,它根据硬件亲和性和对精度的敏感性,以乱序方式将Transformer块调度到CPU/GPU和NPU。与竞争基线相比,llm.npu平均实现了22.4倍的预填充速度提升和30.7倍的能耗节省,在端到端实际应用中最高可达32.8倍的加速。llm.npu首次实现了十亿级模型超过每秒1000个token的预填充速度。

英文摘要:

On-device inference for Large Language Models (LLMs), driven by increasing privacy concerns and advancements of mobile-sized models, has gained significant interest. However, even mobile-sized LLMs (e.g., Gemma-2B) encounter unacceptably high inference latency, often bottlenecked by the prefill stage in tasks like screen UI understanding. We present llm.npu, the first LLM inference system utilizing on-device Neural Processing Unit (NPU) offloading to reduce prefill latency. llm.npu enhances NPU offloading efficiency by re-constructing the prompt and model in three levels: (1) At prompt level, it divides variable-length prompts into multiple fixed-sized chunks while maintaining data dependencies; (2) At tensor level, it identifies and extracts significant outliers to run on the CPU/GPU in parallel with minimal overhead; (3) At block level, it schedules Transformer blocks in an out-of-order manner to the CPU/GPU and NPU based on their hardware affinity and sensitivity to accuracy. Compared to competitive baselines, llm.npu achieves 22.4x faster prefill speed and 30.7$\times$ energy savings on average, and up to 32.8x speedup in an end-to-end real-world application. For the first time, llm.npu achieves more than 1,000 tokens/sec prefilling for a billion-sized model.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑