在树莓派上进行 DeepSeek 模型的分布式推理
note
本文档由 AI 翻译。如您发现内容有误或有改进建议,欢迎通过页面下方的评论区,或在以下 Issue 页面中告诉我们:https://github.com/Seeed-Studio/wiki-documents/issues
简介
本文档解释了如何使用 distributed-llama 在多台树莓派 AI Box 上部署 DeepSeek 模型。在本文档中,我使用了一台 8GB 内存的树莓派 作为 根节点,以及 三台 4GB 内存的树莓派 作为 工作节点 来运行 DeepSeek 8B 模型。推理速度达到了 6.06 tokens 每秒。
准备硬件
reComputer AI R2130 |
---|
![]() |
准备软件
更新系统:
打开一个终端,按下 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
在根节点和工作节点上安装 distributed-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 台树莓派推理 DeepSeek Llama 8b 模型的结果。

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