Skip to main content

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

はじめに

このwikiでは、distributed-llamaを使用して複数のRaspberry Pi AI BoxでDeepSeekモデルをデプロイする方法を説明します。この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...