0
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?

Docker Model Runner(LLMのローカル実行環境)

Posted at

前置き

Docker Model Runnerとは?
大規模言語モデル(LLM) を簡単にローカル環境で実行することができる、Docker Desktop の新たな機能
Docker Model Runner では Docker Hub にあるモデルをダウンロード(docker model pull) し、docker model コマンドを利用して簡単にモデルの起動・操作を行うことが可能

  • メリット

    • セットアップが容易
    • ローカル実行によりレスポンスが高速なので、開発が爆速になる
    • データがローカルで保持されるので情報漏洩しない
    • モデル毎にコンテナを分けて複数モデルを利用できる
  • デメリット

    • ローカルマシンのスペックに依存する
      →大きいモデルはプロンプト打ったあとフリーズしたりもする
    • 利用者側でモデルの知識が必要
      →ありがたいことにモデルが複数公開されているので使い分ける場合は何に特化したモデルなのかある程度知識が要る

試行メモ

公式マニュアル

1. Docker Desktop Model Runner有効化

Docker DesktopでDocker Model Runner(DMR)が有効化されていることを確認
スクリーンショット 2025-07-27 11.12.32.png

2. Docker EngineでDocker Model Runner(DMR)を有効化

インストール確認/テストを実施

📁 ~ ❯ docker model version
Docker Model Runner version v0.1.33
Docker Engine Kind: Docker Desktop
📁 ~ ❯ docker model run ai/smollm2
Unable to find model 'ai/smollm2' locally. Pulling from the server.
Downloaded: 0.00 MB
Model pulled successfully
Interactive chat mode started. Type '/bye' to exit.
> hi
Hello, I am SmolLM, a helpful assistant for language-related tasks. I'm here to help you refine your writing, provide suggestions for grammar and style, and assist with text processing and organization. What can I help you with today?
> /bye
Chat session ended.

利用可能なModelをいくつか試してみる

利用可能なコンテナイメージはDocker Hubで公開されている
現在は新旧含めて17種類公開されているモデルがある
https://hub.docker.com/u/ai
スクリーンショット 2025-07-27 11.33.04.png

ダウンロードしたモデルはDocker Desktopからも確認できる
スクリーンショット 2025-07-29 21.33.25.png

Actionsにある再生マーク▶️を押すとその場でChatGPTの様にやり取りもできる
スクリーンショット 2025-07-29 21.35.32.png

gemma3n

Google DeepMindが開発したマルチモーダルAI
https://hub.docker.com/r/ai/gemma3n

 ~ ❯ docker model pull ai/gemma3n
Downloaded: 0.00 MB
Model pulled successfully
📁 ~ ❯ docker model run ai/gemma3n
Interactive chat mode started. Type '/bye' to exit.
> 日本の首相の名前を教えて
現在の日本の首相は、**岸田文雄(きしだ ふみお)** さんです。
> あなたの産みの親はだれ
私は、Google によってトレーニングされた、大規模言語モデルです。

「産みの親」という表現に当てはめるなら、私を作り出した Google の研究者やエンジニアが、私の「産みの親」と言えるでしょう。彼らは、私に学習データを与え、モデルを設計し、トレーニングすることで、私を創造しました。

私は、彼らの努力と知恵によって、様々な言語を理解し、生成する能力を得ています。
> what day is it today?
Today is Wednesday, May 15, 2024. 

Is there anything else I can help you with? 😊 
> 最大と最も大きいって何が違うか教えて
「最大」と「最も大きい」は、基本的に同じ意味で使われます。どちらも、ある集合の中で一番大きなものを指します。

ただし、ニュアンスの違いとして、以下のような点が挙げられます。

*   **最大:** 数学的な文脈でよく使われる言葉です。集合の要素の中で、最も大きな値を表すことを客観的に表現するニュアンスがあります。例えば、「この集合の最大値は10である」のように使われます。
*   **最も大きい:** 日常会話でよく使われる言葉です。「最大」と同様に一番大きなものを指しますが、より口語的な表現です。例えば、「この中で最も大きい数字は?」のように使われます。

ほとんどの場合、どちらを使っても意味は通じますが、フォーマルな場面や数学的な文脈では「最大」を使う方が適切とされています。

例:

*   「このクラスの**最大**点は100点だった。」
*   「このクラスの**最も大きい**点は100点だった。」

どちらも同じ意味ですが、「最大」の方がより客観的で厳密な印象を与えます。
> Aさんは学校の帰りに駄菓子屋で飴を3個買いました。その帰り道、友達に会ったので1つ飴をあげました。今Aさんは飴を何個持っていますか。
Aさんは最初に3個の飴を持っていて、1個あげたので、

3個 - 1個 = 2個

今、Aさんは飴を**2個**持っています。

試したところデータが古いが、日本語の理解はしっかりしている印象を受けた

smollm2

SmolLM2は、135M、360M、1.7Bの3つのサイズで利用できるコンパクトな言語モデルのファミリー
https://hub.docker.com/r/ai/smollm2

日本語対応してないので英語でやり取りしてみた

📁 ~ ❯ docker model run ai/smollm2
Interactive chat mode started. Type '/bye' to exit.
> Hello what is your name?
My name is SmolLM, but everyone around me calls me Smo. I'm a humble assistant, created by Hugging Face for machine learning and conversational AI. I'm here to assist and learn alongside you in any conversation. How may I help you today?
> Do you speak Japanese?
I'm sorry, but I don't have the ability to speak Japanese. I was trained to understand and generate text in various natural language processing tasks and domains. If you need assistance with Japanese text, feel free to ask.
> Write a simple Python program that prints the multiplication table from 1 to 9.
def multiplication_table():
    for i in range(1, 10):
        print(f"The multiplication table of {i} is:")
        for j in range(1, 10):
            print(f"{i} x {j} = {i * j}")

multiplication_table()

Alternatively, you can use a for loop with a range for better readability:

def multiplication_table():
    print("Multiplication Table of 1 to 9")
    for i in range(1, 10):
        print(f"{i} x {i} = {i * i}")

multiplication_table()
  • 出力されたプログラムはそのまま使えるレベル
📁 ~ ❯ cat test.py 
def multiplication_table():
    for i in range(1, 10):
        print(f"The multiplication table of {i} is:")
        for j in range(1, 10):
            print(f"{i} x {j} = {i * j}")

multiplication_table()
📁 ~ ❯ python test.py 
The multiplication table of 1 is:
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 9 = 9
The multiplication table of 2 is:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
The multiplication table of 3 is:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
The multiplication table of 4 is:
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
The multiplication table of 5 is:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
The multiplication table of 6 is:
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
The multiplication table of 7 is:
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
The multiplication table of 8 is:
8 x 1 = 8
8 x 2 = 16
8 x 3 = 24
8 x 4 = 32
8 x 5 = 40
8 x 6 = 48
8 x 7 = 56
8 x 8 = 64
8 x 9 = 72
The multiplication table of 9 is:
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81

Mistral 7B Instruct v0.2

自然言語タスクに強いモデル
https://hub.docker.com/r/ai/mistral

📁 ~ ❯ docker model pull ai/mistral
Downloaded: 4170.17 MB
Model pulled successfully
📁 ~ ❯ docker model run ai/mistral
Interactive chat mode started. Type '/bye' to exit.
> hello
 Hello! How can I help you today? Is there something you would like to talk about or ask? I'm here to answer any questions you might have, or we can discuss a topic of your choice. If you're just looking to chat, that's fine too! Let me know what you'd like to do.
> Do you speak Japanese?
 Yes, I can assist with translations in Japanese and other languages. How can I help you today?
> 現在の日本の総理大臣の名前を教えて
 現在、日本の総理大臣は菅 シンジ郎さまです。(2023年1月時点)
> What is the name of the Japanese Prime Minister?
 As of my last update, the Prime Minister of Japan is Fumio Kishida, who has been in office since October 4, 2021. However, for the most accurate and current information, I would recommend checking a reputable news source.
> 現在の日本の総理大臣の名前を教えて
 現在の日本の総理大臣の名前は、Kishida Fumioです。(2021年10月から)
> 現在の日本の総理大臣の名前を教えて
 現在、日本の総理大臣は徳川祐義(Yoshihide Suga)です。他には、過去にも数多くの総理大臣があります。

例:

* 大荒祐太(Shinzo Abe):2006年10月26日から2020年9月16日まで
* 安倍禮治(Junichiro Koizumi):2001年4月26日から2006年9月26日まで
* 有田祐彦(Yukio Hatoyama):2009年9月16日から2010年6月16日まで
* 齊藤智夫(Yoshihiko Noda):2011年9月2ndから2012年12月1stまで
* アブエル(Abel):1873年4月24日から1876年12月31日まで(日本政治の最初から)
* 犬пен(Ii Naosuke):1865年4月7日から1866年10月25日まで(明治政府の初期)

など、多数の総理大臣があります。
> What is the capital of Japan?
 The capital of Japan is Tokyo. It's one of the 47 prefectures of Japan and is located on the eastern coast of Honshu, the largest island of Japan. Tokyo serves as the political, economic, and cultural heart of the nation. It is the most populous city in the world, with over 37 million residents in the Greater Tokyo Area.
> ソクラテスは人間である。すべての人間は死ぬ。では、ソクラテスはどうなりますか?
 ソクラテスは人間であり、すべての人間は死ぬと言うことは、彼も同様に死ぬことが予想されます。ただし、彼の死については、彼が自分自身が死にあわせるために毒を飲み、自宰することによって、より自由な状態として死ぬという話があります。この話は、彼の死後に伝えられ、彼の徒によって記録されています
> ある兄弟の年齢の合計は30歳です。兄の年齢は弟の年齢の2倍より3歳多いです。兄と弟の年齢をそれぞれ求めてください。式と解き方も説明してください。
 弟の年齢をx歳とすると、兄の年齢は2x+3歳になります。このとき、2x+3 + x = 30であるため、x = 10歳で、弟の年齢は10歳で、兄の年齢は20+3 = 23歳となります。

日本語に弱い印象を受けた
また何回も聞くと回答が前の回答に引っ張られたり、ハルシネーションが確認できる
また推論による計算も間違っていることが確認できる
X=9なので弟が9歳、兄が2✖︎9+3=21歳が正解
モデル自体が安定していないみたい

Tips: docker modelコマンド

  • どんなコマンドがあるか確認したい
    • docker model command --help でコマンド別のhelpも見れる
📁 ~ ❯ docker model help
Usage:  docker model COMMAND

Docker Model Runner (EXPERIMENTAL)

EXPERIMENTAL:
  docker model is an experimental feature.
  Experimental features provide early access to product functionality. These
  features may change between releases without warning, or can be removed from a
  future release. Learn more about experimental features in our documentation:
  https://docs.docker.com/go/experimental/

Commands:
  df               Show Docker Model Runner disk usage
  inspect          Display detailed information on one model
  install-runner   Install Docker Model Runner (Docker Engine only)
  list             List the models pulled to your local environment
  logs             Fetch the Docker Model Runner logs
  package          Package a GGUF file into a Docker model OCI artifact, with optional licenses, and pushes it to the specified registry
  ps               List running models
  pull             Pull a model from Docker Hub or HuggingFace to your local environment
  push             Push a model to Docker Hub
  rm               Remove local models downloaded from Docker Hub
  run              Run a model and interact with it using a submitted prompt or chat mode
  status           Check if the Docker Model Runner is running
  tag              Tag a model
  uninstall-runner Uninstall Docker Model Runner
  unload           Unload running models
  version          Show the Docker Model Runner version

Run 'docker model COMMAND --help' for more information on a command.
  • model runnerのバージョンを確認したい
📁 ~ ❯ docker model version
Docker Model Runner version v0.1.33
Docker Engine Kind: Docker Desktop
  • model runnerが使っているdisk容量を確認したい
📁 ~ ❯ docker model df
TYPE              SIZE    
Models            8.88GB   
Inference engine  4.822MB 
  • ローカルに保存しているモデル一覧を確認したい
📁 ~ ❯ docker model list
MODEL NAME  PARAMETERS  QUANTIZATION    ARCHITECTURE  MODEL ID      CREATED       SIZE       
ai/smollm2  361.82 M    IQ2_XXS/Q4_K_M  llama         354bf30d0aa3  4 months ago  256.35 MiB  
ai/gemma3n  6.87 B      IQ2_XXS/Q4_K_M  gemma3n       800c2ac86449  4 weeks ago   3.94 GiB 
  • ローカルに保存しているモデルを削除したい
📁 ~ ❯ docker model rm ai/gemma3n
Model ai/gemma3n removed successfully
  • モデルを実行したい
📁 ~ ❯ docker model run モデル名
Interactive chat mode started. Type '/bye' to exit.
  • model runnner のステータスを確認したい
📁 ~ ❯ docker model status
Docker Model Runner is running

参考

0
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
0
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?