前言
隨著大模型應用場景的不斷拓展,arm cpu 憑借其獨特優勢在大模型推理領域的重要性日益凸顯。它在性能、功耗、架構適配等多方面發揮關鍵作用,推動大模型在不同場景落地
1. CPU對比
星睿 O6 CPU 采用 Armv9 架構,集成了 Arm?v9 CPU 核心、Arm Immortalis? GPU 及安謀科技 “周易” NPU 等。其中,“周易” NPU 算力可達 30TOPS,在處理 AI 相關任務時,異構的架構能讓 CPU、GPU、NPU 協同工作,加速 AI 模型的運行。驍龍 8 Elite 采用 2+6 架構設計,首次運用專為智能手機打造的第二代自研 Oryon CPU 架構。兩顆超大核頻率為 4.32GHz,六顆大核頻率為 3.53GHz,每個 CPU 叢集都配備了較大緩存,還引入全新的數據時序預取器以及全新的性能內核設計,在通用計算性能上表現強勁。
這里我們讓二者通過llama.cpp跑同樣模型的推理速度對比
2. 星瑞O6跑llama.cpp
參閱:https://aijishu.com/a/1060000000507877
3. 驍龍8 Elite跑llama.cpp
3.1 依賴安裝
## 1.安裝[termux](https://termux.dev/en/)app,配置ssh,## 2.安裝編譯環境
apt update && apt upgrade -y
apt install git cmake
3.2 不開啟klelidiAI優化
cmake -B build
cmake --build build --config Release -j
3.2 驗證模型正確性
還是使用“星瑞” O6 評測 —— CPU llama.cpp不同優化速度對比轉換的模型
taskset -c 0,3,4,5,6,7 ./build_kle/bin/llama-cli -m asserts/Qwen2.5-3B-Instruct-Q4_0.gguf -c 4096 -t 6 --conversation
打印信息
> hello
Hello! How can I assist you today? Do you have any questions or topics you'd like to discuss?>
llama_perf_sampler_print: sampling time = 2.79 ms / 32 runs ( 0.09 ms per token, 11477.76 tokens per second)
llama_perf_context_print: load time = 498.94 ms
llama_perf_context_print: prompt eval time = 592.82 ms / 9 tokens ( 65.87 ms per token, 15.18 tokens per second)
llama_perf_context_print: eval time = 1711.00 ms / 22 runs ( 77.77 ms per token, 12.86 tokens per second)
llama_perf_context_print: total time = 6498.13 ms / 31 tokens
Interrupted by user
3.3 不開啟klelidiAI優化的benchmark
taskset -c 0,1,2,3,4,5,6,7 ./build/bin/llama-bench -m asserts/Qwen2.5-3B-Instruct-Q4_0.gguf -p 128 -n 128 -t 8
用[0,2,3,4,5,6,7]7個核心的結果
model | size | params | backend | threads | test | t/s |
---|---|---|---|---|---|---|
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 7 | pp128 | 63.59 ± 0.31 |
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 7 | tg128 | 10.87 ± 0.37 |
用8個核心的結果
model | size | params | backend | threads | test | t/s |
---|---|---|---|---|---|---|
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 8 | pp128 | 72.39 ± 1.43 |
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 8 | tg128 | 9.99 ± 1.02 |
3.5 開啟kleidiai優化的benchmark
kleidiai已經集成到llama.cpp的后端,只需要編譯時給定正確的選項就行。
cmake -B build_kle -DGGML_CPU_KLEIDIAI=ON
cmake --build build_kle --config Release -j
benchmark命令: taskset -c 0,2,3,4,5,6,7 ./build_kle/bin/llama-bench -m asserts/Qwen2.5-3B-Instruct-Q4_0.gguf -p 128 -n 128 -t 7
用[0,2,3,4,5,6,7]7個核心的結果
model | size | params | backend | threads | test | t/s |
---|---|---|---|---|---|---|
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 7 | pp128 | 61.55 ± 0.10 |
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 7 | tg128 | 10.41 ± 0.13 |
用8個核心的結果
model | size | params | backend | threads | test | t/s |
---|---|---|---|---|---|---|
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 8 | pp128 | 69.05 ± 0.88 |
qwen2 3B Q4_0 | 1.69 GiB | 3.09 B | CPU | 8 | tg128 | 9.68 ± 0.16 |
打印中有load_tensors: CPU_KLEIDIAI model buffer size = 1488.38 MiB
和KLEIDIAI = 1
表明編譯選項正確打開。
4.總結
從推理速度來看:星瑞O6在同樣的核心數量時,推理速度更快。而且星瑞O6共有12個CPU核。
5.疑問
- 從主頻來看高通的主頻更高,理論上推理速度應該更快。
- 不知道用高通的qnn cpu后端能否比llama.cpp推理更快。