PowerInfer 是由上海交通大學 IPADS 實驗室開發的高速大語言模型 (LLM) 推理引擎,專為配備單個消費級 GPU 的個人計算機設計。該項目的核心創新在於利用 LLM 推理中固有的高局部性特徵,通過功率律分佈的神經元激活模式來優化推理性能。
傳統的 LLM 推理面臨著巨大的計算和記憶體挑戰,特別是在消費級硬體上部署大型模型時。PowerInfer 通過深入分析神經網路激活模式,發現了一個關鍵洞察:少數 "熱" 神經元在所有輸入中持續激活,而大多數 "冷" 神經元根據特定輸入而變化。
PowerInfer 的設計基於以下核心觀察:
基於熱冷神經元的特性,PowerInfer 採用創新的混合推理策略:
模型系列 | 參數規模 | 特性 |
---|---|---|
Falcon 系列 | 40B | ReLU 激活函數優化 |
Llama2 系列 | 7B/13B/70B | 全系列支持 |
ProSparse Llama2 | 7B/13B | ~90% 稀疏性,性能接近原版 |
Bamboo 系列 | 7B | 頂級性能與速度並存 |
PowerInfer 使用專門的 PowerInfer GGUF 格式,包含:
┌─────────────────┐ ┌─────────────────┐
│ 熱神經元 │───▶│ GPU │
│ (持續激活) │ │ (快速訪問) │
└─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐
│ 冷神經元 │───▶│ CPU │
│ (條件激活) │ │ (靈活計算) │
└─────────────────┘ └─────────────────┘
模型 | PowerInfer | llama.cpp | 加速比 |
---|---|---|---|
Falcon-40B | 11.2 tokens/s | 1.0 tokens/s | 11.2x |
Llama2-70B | 8.1 tokens/s | 2.7 tokens/s | 3.0x |
Llama2-13B | 24.8 tokens/s | 8.9 tokens/s | 2.8x |
模型 | PowerInfer | llama.cpp | 加速比 |
---|---|---|---|
Falcon-40B | 6.8 tokens/s | 0.85 tokens/s | 8.0x |
Llama2-70B | 5.2 tokens/s | 1.7 tokens/s | 3.1x |
git clone https://github.com/SJTU-IPADS/PowerInfer
cd PowerInfer
pip install -r requirements.txt
# NVIDIA GPU
cmake -S . -B build -DLLAMA_CUBLAS=ON
cmake --build build --config Release
# CPU only
cmake -S . -B build
cmake --build build --config Release
# 使用 huggingface-cli 下載模型
huggingface-cli download --resume-download --local-dir ReluLLaMA-7B \
--local-dir-use-symlinks False PowerInfer/ReluLLaMA-7B-PowerInfer-GGUF
# 基本推理
./build/bin/main -m ./ReluLLaMA-7B-PowerInfer-GGUF/llama-7b-relu.powerinfer.gguf \
-n 128 -t 8 -p "Once upon a time"
# 限制 VRAM 使用
./build/bin/main -m ./ReluLLaMA-7B-PowerInfer-GGUF/llama-7b-relu.powerinfer.gguf \
-n 128 -t 8 -p "Once upon a time" --vram-budget 8
特性 | PowerInfer | 傳統引擎 |
---|---|---|
硬體要求 | 消費級 GPU | 伺服器級 GPU |
記憶體效率 | 混合 CPU/GPU | 全 GPU 加載 |
推理速度 | 11.69x 提升 | 基準性能 |
成本 | 低成本 | 高成本 |
PowerInfer 的核心在於對神經網路稀疏性的深度利用:
PowerInfer 採用開源協議,歡迎社區貢獻。項目積極接受問題反饋和功能建議。
相關研究論文已發表,為大語言模型推理優化領域提供了重要的理論基礎和實踐指導。
PowerInfer 代表了大語言模型本地推理技術的重大突破。通過創新的熱冷神經元機制和 CPU/GPU 混合架構,它成功地在消費級硬體上實現了接近伺服器級別的推理性能。