
Raspberry Pi5でRakutenAI-2.0-miniを動かしてみる
はじめに
RakutenAIの2.0が出たということで、動かしてみることにしました。
今回からRakutenAI-2.0-miniというエッジコンピューティングを想定した小規模言語モデルも併せて発表されました。こうなると手元のラズパイの出番です。
というわけで、アプローチとしては、Raspberry Pi5でOllamaを使ってどのくらいのパフォーマンスがでるかを検証してみようと思います。
環境
Raspberry Pi5 / 8GB
純正ACアダプタ
Ollama 0.5.11
Open WebUI0.5.16
RakutenAI-2.0-mini
電力の給電が弱いとCPUパワーが出しきれないようで途中で落ちて再起動かかっちゃいました。
Ollamaの準備
まずはOllamaのインストールから。
curl -fsSL https://ollama.com/install.sh | sh
10GB以上使います。ここでディスクが枯渇してしまい、近くの電気屋にMicro SDを調達しなければいけないタイムロス。
モデルの準備
次、RakutenAI-2.0-miniはollamaのリポジトリには登録されていないので自分で諸々用意する必要があります。
ollamaに適したggufという形式のファイルを用意しなければならないみたい。ggufファイルはllama.cppにはいっている変換用のスクリプトで作成できるようなので、準備をしておきます。
git clone https://github.com/ggerganov/llama.cpp.git
次にモデル本体をHugging Faceから入手してきます。git cloneするのですが、その前にやることがあります。gitで巨大なファイルを扱うために必要な準備があります。いままでgitで大きなファイルは扱ってこなかったからこんなの知らなかった。
sudo apt-get install git-lfs
git lfs install
準備ができたらこちらからgit cloneします。
3GBほどあるのでしばし待ちます。
git clone https://huggingface.co/Rakuten/RakutenAI-2.0-mini-instruct
次に、Hugging Faceから落としてきたモデルをgguf形式にコンバートします。そんなに待たないです。
python3 llama.cpp/convert_hf_to_gguf.py "RakutenAI-2.0-mini-instruct" --outtype bf16
次に、Modelfileというのを準備します。よくわからないところも多いのですが、いろいろ検索しながらなんとか用意できました。MistralのModelfileを参考に用意しました。ちなみに ollama show mistral-small --modelfileでリポジトリ上のmodelfileをみることができます。
cd RakutenAI-2.0-mini-instruct/
vi Modelfile
FROM RakutenAI-2.0-mini-instruct-BF16.gguf
TEMPLATE """{{- range $index, $_ := .Messages }}
{{- if eq .Role "system" }}[SYSTEM_PROMPT]{{ .Content }}[/SYSTEM_PROMPT]
{{- else if eq .Role "user" }}
{{- if and (le (len (slice $.Messages $index)) 2) $.Tools }}[AVAILABLE_TOOLS]{{ $.Tools }}[/AVAILABLE_TOOLS]
{{- end }}[INST]{{ .Content }}[/INST]
{{- else if eq .Role "assistant" }}
{{- if .Content }}{{ .Content }}
{{- if not (eq (len (slice $.Messages $index)) 1) }}</s>
{{- end }}
{{- else if .ToolCalls }}[TOOL_CALLS][
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{- end }}]</s>
{{- end }}
{{- else if eq .Role "tool" }}[TOOL_RESULTS]{"content": {{ .Content }}}[/TOOL_RESULTS]
{{- end }}
{{- end }}"""
PARAMETER stop "[/INST]"
PARAMETER stop "[INST]"
SYSTEM You are a personal chat assistant and you have to answer user queries only using information from a set of provided documents. If none of the documents are relevant to answering the query, you may answer that you do not know. Always answer directly, succinctly, keeping a professional tone and avoiding unnecessary language.
#SYSTEM You are Mistral Small 3, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris. Your knowledge base was last updated on 2023-10-01. When you're not sure about some information, you say that you don't have the information and don't make up anything. If the user's question is not clear, ambiguous, or does not provide enough context for you to accurately answer the question, you do not try to answer it right away and you rather ask the user to clarify their request (e.g. "What are some good restaurants around me?" => "Where are you?" or "When is the next flight to Tokyo" => "Where do you travel from?")
PARAMETER temperature 0.15
Modelfileができたらcreateします。
ollama create RakutenAI-2.0-mini-instruct-BF16 -f ./Modelfile
RakutenAI-2.0-miniの実行
ollama run RakutenAI-2.0-mini-instruct-BF16
レスポンスはこんな感じ。初回はだいたい50秒ぐらいかけて返ってきました。2回目以降はだいたい30秒ぐらい。最初はモデルをオンメモリにロードするオーバーヘッドがあるんだな。

Open WebUIでブラウザ経由からRakutenAI-2.0-miniを利用する
OllamaにはChatGPTライクなWebのUIも用意されているので、これは使わない手はないです。
導入は比較的簡単で、こちらのサイトのインストラクション通りに進めばいけます。
ダウンロード。
curl -LsSf https://astral.sh/uv/install.sh | sh
そして実行。
DATA_DIR=~/.open-webui uvx --python 3.11 open-webui@latest serve

http://localhost:8080にアクセスし、ユーザー登録(ローカルに保存しているだけと思われる)を済ませると利用開始できます。

早速質問してみました。割と雑にケーキの作り方を教えてくれました。だいたい1分ちょいかけてこのくらいの文章量。

たまにとても出力が遅いことがあります。これがOpen WebUIの問題なのかRakutenAIの問題なのかはわからないですが… ただollama runコマンドのときは起きてないのでWebUIっぽいのですが、まだまだわからないことは多いです。
感想
遅いながらもラズパイ上で基本的なChatGPT相当の環境がうごいたのはちょっと感動でした。
ところで最後に…
ところで最後に…楽天モバイルのご紹介です!
今回のOllamaのインストールで約10GB、RakutenAI-2.0-miniのモデルで約3GBと、かなりのファイルサイズです。ダウンロードサイズを全く気にせずにモバイル通信でLLMを扱おうとすると、楽天モバイルほぼ一択です。2980円(税抜)でデータ無制限に使えるのでお金のことは気にせずモデルをダウンロードし放題です。
なお、本実験はRaspberry Pi 5とiPadを楽天モバイルのポケットWifiにつないで、お買い物を待つ車の中で実施しました。ラズパイにiPadからSSH or VNC接続できるので、電源さえなんとかなればどこでもできます。車内からのUSBの給電不足で途中で家に帰ったけど。
お乗り換えで14,000ポイント、新規ご契約で7,000ポイントプレゼント!
※楽天会員にログインまたは新規登録後、楽天モバイル紹介キャンペーンページに遷移します。
▼キャンペーンはこちら
https://r10.to/hUpuKk