見出し画像

M3 Mac で Ollamaを使ってLLMsを動かしてみる

2014年のMacbook Proから2023年秋発売のMacbook Proに乗り換えました。せっかくなので,こちらでもLLMsをローカルで動かしたいと思います。

どうやって走らせるか以下の記事を参考にしました。

あと、以下な動画も参考にしました。


いろいろ悩みましたが、今回の選択肢は,Ollamaにします。

下記記事をみるとDockerを使わないとGPUがうまく動かないようです。

Mac の場合

Ollama は、GPU アクセラレーションを使用してモデルの実行を処理します。これは、アプリケーションと対話するための単純な CLI と REST API の両方を提供します。

始めるには、 Ollama をダウンロードしてインストールするだけです。

Ollama でモデルの GPU アクセラレーションを有効にするために、macOS 用の Docker Desktop と一緒に Ollama を実行することをお勧めします。

上のページの該当箇所の翻訳

なので、なので,下の記事を参考に,Dockerをまず入れてみました。

記事と違ったのは,サインインするか,サインインしないで続けるかの画面が最後にあったところです。私はサインインをせずに続けました。あと立場と利用目的のアンケート画面がありました。

しかし、ここで素人の自分は躓いてしまします。
Dockerを一緒に動かすってどういうことか分かりません。Dockerを立ち上げておいて、Ollamaを走らせればいいのか、Dockerの中でOllamaを走らせればいいのか分かりません。

しょうがないから、とりあえずDockerを立ち上げたまま、動画のとおりに、Ollamaをダウンロードして、インストールして、立ち上げました。(タスクバーにアイコンが出るときと出ないときがあって困ってます。)

とりあえず、LLama と mistral はコンソール画面で動きました。

走らせるコマンド

ollama run llama2

使えるモデル一覧はこちら。

走らせたいモデルのところをクリックするとコピペができるページがあります。以下mistralの場合。

ollama run mistral

Ollamaのコマンド ollama -h でヘルプ


ollama -h
Large language model runner

Usage:
 ollama [command]

Available Commands:
 serve       Start ollama
 create      Create a model from a Modelfile
 show        Show information for a model
 run         Run a model
 pull        Pull a model from a registry
 push        Push a model to a registry
 list        List models
 cp          Copy a model
 rm          Remove a model
 help        Help about any command

Flags:
 -h, --help      help for ollama
 -v, --version   version for ollama

Use "ollama [command] --help" for more information about a command.


% ollama run --help            
Run a model

Usage:
 ollama run MODEL [PROMPT] [flags]

Flags:
 -h, --help         help for run
     --insecure     Use an insecure registry
     --nowordwrap   Don't wrap words to the next line automatically
     --verbose      Show timings for response

せっかくだから,以前にwindowsでだめだった70Bのモデルが動くかを試したところ動きました。

LLama70Bの実行例

ollama run llama2:70b --verbose
>>> hello    Hello! How can I assist you today? Is there a specific topic you're interested in discussing or asking about?
total duration:       4.002413833s
load duration:        4.389625ms
prompt eval count:    1 token(s)
eval count:           27 token(s)
eval duration:        3.991253
seval rate:            6.76 tokens/s

>>> Tell me how to have good sleep      Sure, here are some tips for improving your sleep:1. Stick to a sleep schedule: Go to bed and wake up at the same time every day, evenon weekends.2. Create a bedtime routine: Develop a calming pre-sleep routine that signals your body that it's time to wind down. This could include activities such as reading a book, taking a warm bath, or practicing relaxation techniques like deep breathing ormeditation.3. Make your sleep environment comfortable: Keep your bedroom cool, dark, and quiet,and invest in a comfortable mattress and pillows. Consider using blackout curtains, earpl^[[Bugs, or a white noise machine to create an ideal sleep environment.4. Limit exposure to screens before bedtime: The blue light emitted by smartphones, tablets, and computers can suppress the production of melatonin, the hormone that regulates sleep. Try to avoid screens for at least an hour before bedtime or use blue light filtering glasses or apps.5. Avoid caffeine and alcohol: Both substances can disrupt sleep patterns. Caffeine can make it harder to fall asleep, while alcohol can cause you to wake up during thenight.6. Exercise regularly: Regular physical activity can help improve sleep quality, butavoid vigorous exercise within a few hours of bedtime as it can actually interfere with sleep.7. Manage stress: Engage in stress-reducing activities, such as yoga or meditation, to help clear your mind before bed.8. Avoid naps: Napping can make it harder to fall asleep at night, so try to limit naps to 20-30 minutes and avoid napping close to bedtime.9. Get some morning sunlight: Exposure to natural light in the morning helps regulate your circadian rhythms, which can help you feel more alert during the day and sleep better at night.10. Consider trying relaxation techniques: Techniques like progressive muscle relaxation, visualization, or mindfulness meditation can help calm your mind and body before sleep.Remember, it may take some time to figure out what works best for you, so be patientand experiment with different combinations of these tips. If you continue to struggle with sleep, consult with a healthcare professional for further guidance.

total duration:       1m3.349645875s
load duration:        3.997875ms
prompt eval count:    27 token(s)
prompt eval duration: 1.481449s
prompt eval rate:     18.23 tokens/s
eval count:           525 token(s)
eval duration:        1m1.773805s
eval rate:            8.50 tokens/s

>>> Send a message (/? for help)

M3マックのスペックは上で察してください。

dockerを使わないとGPUが動かないという説明もあったのですが,プロセスを見てみると,Ollama Helper (GPU) というのが動いているので,動いているんじゃないかなと思います。

最後ですが,Dockerにはこんなものもあるという記事があったので,いつかチャレンジしてみたいなと思っています。


#AI #やってみた #AIでやってみた #LLM #MacbookPro


この記事が参加している募集

やってみた

この記事を最後までご覧いただき、ありがとうございます!もしも私の活動を応援していただけるなら、大変嬉しく思います。