2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

中古GPU(RTX 3060/12GB)でローカルLLM検証-2 ~ llama.cpp で TinyLlama 1.1B を試す

Last updated at Posted at 2025-05-04

前回は、Docker コンテナでGPUが使えるところまで設定出来ましたので、今回は、コンテナでローカルLLMを試していきます。
[前回記事] 中古GPU(RTX 3060/12GB)でローカルLLM検証-1 ~ 初期設定とGPUコンテナ

ローカルLLMをコンテナで試す

ChatGPT o3 に、どのLLMを試すか相談したら、次の3ルートをおススメされました。

(1)llama.cpp ルート
(2)Ollama ルート
(3)vLLM ルート

違いを表にするとこんな感じ

用途 手軽さ REST/UI バッチ性能 迷ったら
llama.cpp ◎ 軽い あり (8080) まず試す
Ollama ◎ (pull 自動) あり (11434) + WebUI GUI で遊ぶ
vLLM ○ 要 HF モデル あり (8000) ◎ 高速 API 負荷テスト

ちなみにRTX 3060 のVRAM 12 GB で動くモデルとしては、

モデル サイズ (4-bit) 備考
TinyLlama-1.1B-Chat ≈0.5 GB 英語中心。実装確認に最適
Phi-2 2.7B ≈1.2 GB 英語・数学強め
CALM2-3B-Instruct-ja ≈1.6 GB 日本語◎(ELYZA系より軽量)
open-calm-3b ≈2.4 GB 日本語汎用・Apache 2.0

こんな感じにおススメされました。もっと他にも試したいモデルはあるのですが、まずは、英語の応答でいいので、ダウンロードに認証とか要らないものをお手軽に試してみます。

llama.cpp で TinyLlama 1.1B を試す

1. モデルを取ってくる

(認証不要:公開モデルなので wget だけで取得できる)

mkdir -p ~/llm/models && cd ~/llm/models
wget -O tiny.gguf https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf

2. Docker で llama.cpp サーバーを起動

docker run --rm --gpus all \
  -v ~/llm/models:/models \
  -p 8080:8080 \
  ghcr.io/ggml-org/llama.cpp:server-cuda \
  --model /models/tiny.gguf \
  --port 8080 \
  --n-gpu-layers 35
  
# 次のような行が出れば起動成功
llama.cpp server listening at http://0.0.0.0:8080
  • -v ~/llm/models:/models … 先ほど落とした tiny.gguf をコンテナへマウント
  • --n-gpu-layers 35 … 量子化 Q4 なので 35 層を VRAM に載せてもまだ余裕がある
  • 終了は Ctrl-C で可。自動でコンテナも消えるので注意。

3. curl で推論を試す

別ターミナルを開き、curl で TinyLlama に「Which planet is known as the Red Planet?」(赤い星はどの惑星?)と聞いてみました。

curl -s http://localhost:8080/completion \
  -d '{"prompt":"<s>[INST] Which planet is known as the Red Planet? [/INST]","n_predict":32}'

JSON の content"The Red Planet, Mars, …" というテキストが返ってきていますので モデルが正しく推論できています。

ここまでで「モデルをダウンロードして動かす」目的は達成できました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?