在 Raspberry Pi AI box 和工业盒子上进行 DeepSeek 模型的分布式推理
简介
本 wiki 解释了如何使用 distributed-llama 在多个 Raspberry Pi AI 盒子上部署 DeepSeek 模型。在本 wiki 中,我使用了一个配备 8GB RAM 的 Raspberry Pi 作为根节点,以及三个配备 4GB RAM 的 Raspberry Pi 作为工作节点来运行 DeepSeek 8B 模型。推理速度达到了每秒 6.06 个 token。
准备硬件
| reComputer AI R2130 | reComputer AI Industrial R2145 | reComputer Industrial R20xx | reComputer Industrial R21xx |
|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
准备软件
更新系统:
使用 Ctrl+Alt+T 打开终端并输入如下命令:
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
sudo apt update
sudo apt full-upgrade
在根节点和工作节点上安装分布式 llama
使用 Ctrl+Alt+T 打开终端并输入如下命令来安装 distributed-llama:
git clone https://github.com/b4rtaz/distributed-llama.git
cd distributed-llama
make dllama
make dllama-api
在工作节点上运行
然后输入如下命令使工作节点开始工作:
cd distributed-llama
sudo nice -n -20 ./dllama worker --port 9998 --nthreads 4
在根节点上运行
创建并激活 python 虚拟环境
cd distributed-llama
python -m venv .env
source .env/bin/acitvate
安装必要的库
pip install numpy==1.23.5
pip install tourch=2.0.1
pip install safetensors==0.4.2
pip install sentencepiece==0.1.99
pip install transformers
安装 deepseek 8b q40 模型
git lfs install
git clone https://huggingface.co/b4rtaz/Llama-3_1-8B-Q40-Instruct-Distributed-Llama
在根节点上运行分布式推理
注意:
--workers 10.0.0.139:9998 10.0.0.175:9998 10.0.0.124:9998是工作节点的 IP 地址。
cd ..
./dllama chat --model ./Llama-3_1-8B-Q40-Instruct-Distributed-Llama/dllama_model_deepseek-r1-distill-llama-8b_q40.m --tokenizer ./Llama-3_1-8B-Q40-Instruct-Distributed-Llama/dllama_tokenizer_deepseek-r1-distill-llama-8b.t --buffer-float-type q80 --prompt "What is 5 plus 9 minus 3?" --nthreads 4 --max-seq-len 2048 --workers 10.0.0.139:9998 10.0.0.175:9998 10.0.0.124:9998 --steps 256
注意: 如果您想测试推理速度,请使用以下命令。
cd ..
./dllama inference --model ./model/dllama_model_deepseek-r1-distill-llama-8b_q40.m --tokenizer ./model/dllama_tokenizer_deepseek-r1-distill-llama-8b.t --buffer-float-type q80 --prompt "What is 5 plus 9 minus 3?" --nthreads 4 --max-seq-len 2048 --workers 10.0.0.139:9998 10.0.0.175:9998 10.0.0.124:9998 --steps 256
结果
以下是使用 4 个 Raspberry Pi 进行 DeepSeek Llama 8b 模型推理的结果。

技术支持与产品讨论
感谢您选择我们的产品!我们在这里为您提供不同的支持,以确保您使用我们产品的体验尽可能顺畅。我们提供多种沟通渠道,以满足不同的偏好和需求。



