LLMをAMDのGPUで動かそう 【Ollama】

キーワード

AMD, ローカルLLM, Ollama

はじめに

本記事てはLLMを Ollama を使用して動かします。Ollamaについて詳しくは 弊社樋口の記事 をご覧ください。LLMを動かす場合NVIDIA製のGPUを用いることが一般的かと思いますが、OllamaはAMD製のGPUもサポートしているため、本記事では Radeon RX 7900 XTX でOllamaを動かします。

前提条件

本稿で使用したローカルPCのスペックは次の通りです。実用的な速度でローカルLLMを動作させたいと思ったため、スペックは高めになっています。

Ollama がサポートするAMDのGPU

Ollama はブログ記事 Ollama now supports AMD graphics cards でサポートするGPUリストを掲載しています。

  • Radeon RXシリーズ: 7900 XTX, 7900 XT, 7900 GRE, 7800 XT, 7700 XT, 7600 XT, 7600, 6950 XT 6900 XTX, 6900XT, 6800 XT, 6800, Vega 64, Vega 56
  • Radeon PRO シリーズ: W7900, W7800, W7700, W7600, W7500, W6900X, W6800X Duo, Vega II Duo, Vega II, VII, SSG
  • Instinct シリーズ: MI300X, MI300A, MI300, MI250X, MI250, MI210, MI200, MI100, MI60, MI50

Ollama のインストール

Ollamaが提供するインストールスクリプトを使用してOllamaをインストールすることができます。Dockerコンテナも提供されていますが、いきなりAMDのGPUを使用してOllamaコンテナを動かすのはチャレンジングに思われたため、本稿ではコンテナは使用しません。

curl -fsSL https://ollama.com/install.sh | sh

注意点として、GPUの有無でインストールスクリプトの動作が変わります。GPUを取り付けた状態でインストールを行なってください。

お好みのモデルを動かす

一度AMDのGPUを取り付けた状態でインストールを行なってしまえば、AMDのGPUを使用するからといって特別な作業は必要ありません。通常通りの方法でOllamaを使えば勝手にGPUが使用されます。

$ ollama run qwen3:30b
>>> exp(x) を x で不定積分するとどうなりますか?
<think>
...

But wait, let me check if there's any possible mistake here. For example, if I had a different exponent, like e^{kx}, then the integral would be (1/k)e^{kx} + C. But in this case, k is 1, so it's just e^x + 
C. That makes sense. So if someone confuses the integral of e^x with something else, like maybe e^x divided by something, but no, since the derivative of e^x is e^x, the integral should be the same function.

Another check: if I differentiate e^x + C, I get e^x, which is the original function. So that's correct. Therefore, the answer is e^x plus the constant of integration.

I think that's solid. I don't see any errors in the reasoning. All the methods point to the same conclusion. So yeah, the indefinite integral of e^x dx is e^x + C.
</think>

exp(x) を x で不定積分すると、以下のように求められます。

---

### 積分の結果

$$
\int e^x \, dx = e^x + C
$$

ここで、$ C $ は積分定数(任意の定数)です。

---

### 説明

- $ e^x $ の導関数は $ e^x $ です。
- したがって、$ e^x $ の不定積分(逆の操作)は $ e^x $ になります。
- 積分定数 $ C $ は、積分の結果に存在する任意の定数を表します。

---

### 補足

- 他の関数(例: $ e^{kx} $)の積分は $ \frac{1}{k}e^{kx} + C $ となります。
- しかし、$ k = 1 $ の場合、$ \frac{1}{k} = 1 $ なので、結果は $ e^x + C $ になります。

---

### 結論

$$
\boxed{e^x + C}
$$

GPUが使用されていることを確認する

rocm-smi コマンドでGPUの使用状況を確認することができます。GPUが使用されていれば Temp (温度) や AvgPwr (平均消費電力) が上昇します。

$ sudo apt install rocm-smi
$ rocm-smi


========================= ROCm System Management Interface =========================
=================================== Concise Info ===================================
GPU  Temp (DieEdge)  AvgPwr  SCLK     MCLK     Fan     Perf  PwrCap  VRAM%  GPU%  
0    66.0c           327.0W  2965Mhz  1249Mhz  26.67%  auto  327.0W   82%   100%  
====================================================================================
=============================== End of ROCm SMI Log ================================

速度ベンチマーク

touch-spさんの記事 OllamaのベンチマークをとるプログラムをOllama Python Libraryを使って書き換えました を参考に、次のPythonコードで速度ベンチマーク (トークン/秒) を行いました:

from ollama import Client
import sys

client = Client(
  host="http://localhost:11434"
)

def client_chat():
    response = client.chat(
        model=sys.argv[1],
        messages=[
            {
                "role": "user",
                "content": "東京から大阪までの移動手段を提案してください。"
            },
        ],
    )

    return response.eval_count, response.eval_duration

if __name__ == "__main__":

    total_tokens = 0
    total_time = 0
    for _ in range(3):
        eval_count, eval_duration = client_chat()
        total_tokens += eval_count
        total_time += eval_duration    
    rate = (total_tokens / total_time) * 10**9

    print(f"tokens per second: {rate:.2f} tokens/second")

結果

モデル量子化トークン/秒
deepseek-r1:8bQ4_K_M70.21
deepseek-r1:14bQ4_K_M47.76
qwen3:14bQ4_K_M49.76
qwen3:30bQ4_K_M36.72

まとめ

本稿ではAMDのGPUを使いOllamaを動かしました。特にAMDのGPUを使うからといって難しい点はなかったと思います。これからAMDのGPUを使ってローカルLLMを試そうとしている人の参考になればと思います。

新規CTA