ローカルLLMを活用した推論モデルの立ち上げ方法(Ollama)

OllamaでLocal LLMを試してみます。 使用環境はMacBook Air M4 24GB memoryです。

Ollamaのインストールと起動

brew install ollamaでOllamaをインストールします。

> brew install ollama
==> Downloading https://formulae.brew.sh/api/formula.jws.json
==> Downloading https://formulae.brew.sh/api/cask.jws.json
Warning: Treating ollama as a formula. For the cask, use homebrew/cask/ollama or specify the `--cask` flag. To silence this message, use the `--formula` flag.
==> Downloading https://ghcr.io/v2/homebrew/core/ollama/manifests/0.6.3
############################################################################################# 100.0%
==> Fetching ollama
==> Downloading https://ghcr.io/v2/homebrew/core/ollama/blobs/sha256:8c64d981bae4647d8e0be78d3603915
############################################################################################# 100.0%
==> Pouring ollama--0.6.3.arm64_sequoia.bottle.tar.gz
==> Caveats
To start ollama now and restart at login:
  brew services start ollama
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/ollama/bin/ollama serve
==> Summary
🍺  /opt/homebrew/Cellar/ollama/0.6.3: 8 files, 26.1MB
==> Running `brew cleanup ollama`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

バックグラウンドで動かさず/opt/homebrew/opt/ollama/bin/ollama serveで起動します。

> /opt/homebrew/opt/ollama/bin/ollama serve
Couldn't find '/Users/tworks55/.ollama/id_ed25519'. Generating new private key.
Your new public key is:

ssh-ed25519 AAABC3NzaC1lZDI1NTE5ABBAIDBgj2VfuhVMdVtVYwQRcd4UrskPjUQBdFQsEWuNo7WM

2025/03/31 21:48:27 routes.go:1230: INFO server config env="map[HTTPS_PROXY: HTTP_PROXY: NO_PROXY: OLLAMA_CONTEXT_LENGTH:2048 OLLAMA_DEBUG:false OLLAMA_FLASH_ATTENTION:false OLLAMA_GPU_OVERHEAD:0 OLLAMA_HOST:http://127.0.0.1:11434 OLLAMA_KEEP_ALIVE:5m0s OLLAMA_KV_CACHE_TYPE: OLLAMA_LLM_LIBRARY: OLLAMA_LOAD_TIMEOUT:5m0s OLLAMA_MAX_LOADED_MODELS:0 OLLAMA_MAX_QUEUE:512 OLLAMA_MODELS:/Users/tworks55/.ollama/models OLLAMA_MULTIUSER_CACHE:false OLLAMA_NEW_ENGINE:false OLLAMA_NOHISTORY:false OLLAMA_NOPRUNE:false OLLAMA_NUM_PARALLEL:0 OLLAMA_ORIGINS:[http://localhost https://localhost http://localhost:* https://localhost:* http://127.0.0.1 https://127.0.0.1 http://127.0.0.1:* https://127.0.0.1:* http://0.0.0.0 https://0.0.0.0 http://0.0.0.0:* https://0.0.0.0:* app://* file://* tauri://* vscode-webview://* vscode-file://*] OLLAMA_SCHED_SPREAD:false http_proxy: https_proxy: no_proxy:]"
time=2025-03-31T21:48:27.986+09:00 level=INFO source=images.go:432 msg="total blobs: 0"
time=2025-03-31T21:48:27.986+09:00 level=INFO source=images.go:439 msg="total unused blobs removed: 0"
time=2025-03-31T21:48:27.986+09:00 level=INFO source=routes.go:1297 msg="Listening on 127.0.0.1:11434 (version 0.6.3)"
time=2025-03-31T21:48:28.030+09:00 level=INFO source=types.go:130 msg="inference compute" id=0 library=metal variant="" compute="" driver=0.0 name="" total="16.0 GiB" available="16.0 GiB"
llama3.1-8bモデルを起動

ollama run llama3:8bで起動します。

> ollama run llama3.1:8b
pulling manifest
pulling 667b0c1932bc... 100% ▕████████████████████████████████████▏ 4.9 GB
pulling 948af2743fc7... 100% ▕████████████████████████████████████▏ 1.5 KB
pulling 0ba8f0e314b4... 100% ▕████████████████████████████████████▏  12 KB
pulling 56bb8bd477a5... 100% ▕████████████████████████████████████▏   96 B
pulling 455f34728c9b... 100% ▕████████████████████████████████████▏  487 B
verifying sha256 digest
writing manifest
success
>>> Send a message (/? for help)

メモリ使用量は問題ないようです。

質問をしてみる

ということで早速試してみます。

>>> hello
Hello! How are you today? Is there something I can help you with or would you like to chat?

>>> 日本語も大丈夫ですか?
いいえ、問題ありません。日本語でも応えます。日本語で何か質問がありましたか?

>>> 今日は何日ですか?
私には現在の日付がわかりません。ですが、日時を知りたい場合は、その地域または時間帯の日付を入力す
ると、答えることができます。また、一般的な回答として、私が作業している現在の時間帯も知らせること
ができますよ。

>>> パンテラというバンドを知っていますか?
パンテラ(PANTERA)は、アメリカ合衆国のHeavy Metalバンドでした。結成は1987年、活動は1990年から
2003年まででした。主なメンバーはテキサス州のダラス出身のヴィニー・ポランスキーとディフェレンスで
す。彼らの曲もよく知られていますね。どんな曲が好きなですか?

>>> Do you know the band called PANTERA?
Yes, I'm familiar with Pantera. They were an American heavy metal band from Texas, formed in
1987 and active until 2003. The band is known for their unique sound, which blended elements
of groove metal, hard rock, and thrash metal. Some of their most popular songs include
"Cowboys From Hell", "Mouth for War", and "Walk". They were also notable for the distinctive
vocals of Philip Anselmo (lead vocals) and Dimebag Darrell's (guitar) innovative playing
style. What do you think about Pantera?

試した環境はMacBook Air M4のMemory 24GBですが、8bならサクサク返信がきます。 ただし、回答が微妙に間違っていたり日本語がおかしかったりします。一度英語で質問すると日本語も正しい回答を返したりします。

また、当然なのかもしれませんが少し論理的に考える必要がある問題にも対応できません。

Sally (a girl) has 3 brothers. Each brother has 2 sisters. How many sisters does Sally have?

>>> Sally (a girl) has 3 brothers. Each brother has 2 sisters. How many sisters does Sally have?
Let's break this down:

* Sally herself is a sister to her 3 brothers.
* Each of her 3 brothers has 2 sisters, which means that each of their 2 sisters is also one
of Sally's sisters.

Since each brother has 2 sisters, and there are 3 brothers, the total number of sisters
(excluding Sally) is: 3 brothers × 2 sisters/brother = 6 sisters

Adding Sally herself to this count, she has a total of: 6 sisters + 1 (herself) = 7 sisters

>>> /bye

ちなにChatGPTで試してみましたが、正しい答えが返ってきました。

Sally has only one sister.

Explanation:
Sally has 3 brothers.

Each of her brothers has 2 sisters.

The two sisters are Sally and one other girl.

So, Sally has one sister in addition to herself.
モデルの削除

このモデルの実力はわかったのでひとまず削除します。

ollama listで対象を確認し、ollama rmで削除。

> ollama list
NAME           ID              SIZE      MODIFIED
llama3.1:8b    46e0c10c039e    4.9 GB    36 minutes ago

> ollama rm llama3.1:8b
deleted 'llama3.1:8b'

ひとまずOllamaの使い方はわかったので他のモデルを今度試してみます。