llama.cpp是一个高性能的开源大语言模型推理框架,由开发者Georgi Gerganov基于 Meta 的 LLaMA 模型开发,使用纯C/C++ 实现,旨在让大语言模型能够在各种硬件平台上高效运行,特别是消费级设备和边缘设备。
主要特点:
Vulkan是由Khronos Group主导开发的下一代跨平台图形与计算API,于 2016年正式发布。它被视为OpenGL的继任者,专注于提供更低开销、更细粒度硬件控制 和多平台支持,适用于游戏引擎、专业图形工具和高性能计算场景。
核心特性
跨平台兼容性
显式硬件控制
多线程友好设计
统一图形与计算
现代GPU功能支持
git clone https://github.com/ggml-org/llama.cpp.git
sudo apt install cmake gcc g++
瑞莎星睿O6搭载Mali-G720-Immortalis GPU。可以使用GGGML_VULKAN
打开Vulkan相关编译选项。
cmake -B build -DGGML_VULKAN=ON
cmake --build build --config Release -j8
这里以 DeepSeek-R1-Distill-Qwen-1.5B 为例子。
请使用 git LFS 克隆仓库
git lfs install
git clone https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
:::tip
推荐使用python3.11以上版本
:::
cd llama.cpp
pip3 install -r ./requirements.txt
python3 convert_hf_to_gguf.py DeepSeek-R1-Distill-Qwen-1.5B/
cd build/bin
./llama-quantize DeepSeek-R1-Distill-Qwen-1.5B-F16.gguf DeepSeek-R1-Distill-Qwen-1.5B-Q4_K_M.gguf Q4_K_M
cd build/bin
./llama-cli -m DeepSeek-R1-Distill-Qwen-1.5B-Q4_K_M.gguf
> hi, who are you
<think>
</think>
Hi!I'm DeepSeek-R1, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.
radxa@orion-o6:~/llama.cpp$ ./build/bin/llama-bench -m ~/models/DeepSeek-R1-Distill-Qwen-1.5B-Q4_K_M.gguf -t 8
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = Mali-G720-Immortalis (Mali-G720-Immortalis) | uma: 1 | fp16: 1 | warp size: 16 | shared memory: 32768 | matrix cores: none
| model | size | params | backend | ngl | threads | test | t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | ------: | ------------: | -------------------: |
| qwen2 1.5B Q4_K - Medium | 1.04 GiB | 1.78 B | Vulkan | 99 | 8 | pp512 | 232.45 ± 0.22 |
| qwen2 1.5B Q4_K - Medium | 1.04 GiB | 1.78 B | Vulkan | 99 | 8 | tg128 | 21.93 ± 0.67 |
通过与CPU推理对比,使用Mali GPU + Vulkan,可以使得llama.cpp Prefill阶段的速度提升明显,同时也能减少宝贵CPU资源占用。