Skip to main content

Raspberry Pi AIボックスでのDeepSeekモデルの分散推論

note

この文書は AI によって翻訳されています。内容に不正確な点や改善すべき点がございましたら、文書下部のコメント欄または以下の Issue ページにてご報告ください。
https://github.com/Seeed-Studio/wiki-documents/issues

Raspberry PiでのDeepSeekモデルの分散推論

はじめに

このWikiでは、DeepSeekモデルを複数のRaspberry Pi AIボックスにdistributed-llamaを使用してデプロイする方法を説明します。このWikiでは、8GBのRAMを搭載したRaspberry Piルートノードとして使用し、4GBのRAMを搭載した3つのRaspberry Piワーカーノードとして使用してDeepSeek 8Bモデルを実行しました。推論速度は6.06トークン/秒に達しました。

ハードウェアの準備

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つのRaspberry Piを使用してDeepSeek Llama 8bモデルを推論した結果です。

技術サポートと製品ディスカッション

弊社製品をお選びいただきありがとうございます!製品をスムーズにご利用いただけるよう、さまざまなサポートをご提供しています。お客様のニーズに応じた複数のコミュニケーションチャネルをご用意しています。

Loading Comments...