# Unsloth ガイドで AMD GPU 上の LLM をファインチューニングする

Unslothを使って、ローカルのAMD環境でLLMをファインチューニングできるようになりました。UnslothはAMD Radeon RX、MI300X（192GB）GPUなどをサポートしています。

{% stepper %}
{% step %}
**新しい隔離環境を作成する（任意）**

システムのパッケージを壊さないように、隔離されたpip環境を作成できます。お使いのPythonバージョンを確認することを忘れないでください！以下の可能性があります `pip3`, `pip3.13`, `python3`, `python.3.13` など。

{% code overflow="wrap" %}

```bash
apt install python3.10-venv python3.11-venv python3.12-venv python3.13-venv -y

python -m venv unsloth_env
source unsloth_env/bin/activate
```

{% endcode %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FCqOhjYTr4GqQ90ToPEig%2Famd1.png?alt=media&#x26;token=d8f96a07-90be-4d93-b848-ad182c262d1f" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**PyTorchをインストール**

最新のPyTorch、TorchAO、Xformersを以下からインストールしてください <https://pytorch.org/> ROCMバージョンを確認するには `amd-smi version` 次に変更します `https://download.pytorch.org/whl/rocm7.0` に合わせてください。

{% code overflow="wrap" %}

```bash
uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm7.0 --upgrade --force-reinstall
```

{% endcode %}

また、必要であれば正しいROCMバージョンを抽出する単一のターミナルコマンドも用意しました。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FJ1VZQ9QhzWFizDceg3ye%2Famd2.png?alt=media&#x26;token=937d1eba-3c7e-4c73-b6a6-9a9450d0e4ac" alt=""><figcaption></figcaption></figure>

```bash
ROCM_TAG="$({ command -v amd-smi >/dev/null 2>&1 && amd-smi version 2>/dev/null | awk -F'ROCm version: ' 'NF>1{split($2,a,"."); print "rocm"a[1]"."a[2]; ok=1; exit} END{exit !ok}'; } || { [ -r /opt/rocm/.info/version ] && awk -F. '{print "rocm"$1"."$2; exit}' /opt/rocm/.info/version; } || { command -v hipconfig >/dev/null 2>&1 && hipconfig --version 2>/dev/null | awk -F': *' '/HIP version/{split($2,a,"."); print "rocm"a[1]"."a[2]; ok=1; exit} END{exit !ok}'; } || { command -v dpkg-query >/dev/null 2>&1 && ver="$(dpkg-query -W -f="${Version}\n" rocm-core 2>/dev/null)" && [ -n "$ver" ] && awk -F'[.-]' '{print "rocm"$1"."$2; exit}' <<<"$ver"; } || { command -v rpm >/dev/null 2>&1 && ver="$(rpm -q --qf '%{VERSION}\n' rocm-core 2>/dev/null)" && [ -n "$ver" ] && awk -F'[.-]' '{print "rocm"$1"."$2; exit}' <<<"$ver"; })"; [ -n "$ROCM_TAG" ] && uv pip install torch torchvision torchaudio --index-url "https://download.pytorch.org/whl/$ROCM_TAG" --upgrade --force-reinstall
```

{% endstep %}

{% step %}
**Unslothをインストール**

Unslothの専用AMDブランチをインストール：

{% code overflow="wrap" %}

```bash
pip install --no-deps unsloth unsloth-zoo
pip install --no-deps git+https://github.com/unslothai/unsloth-zoo.git
pip install "unsloth[amd] @ git+https://github.com/unslothai/unsloth"
```

{% endcode %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Frz8GOvVgST7beQ8pmgmC%2Famd3.png?alt=media&#x26;token=03a12c20-af1d-4b98-9aaf-18ccc6a1d4a4" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Unslothでファインチューニングを開始！**

以上です。いくつかの例を私たちの [**Unslothノートブック**](https://unsloth.ai/docs/jp/meru/unsloth-notebooks) ページで試してみてください！

私たちの専用の [ファインチューニング](https://unsloth.ai/docs/jp/meru/fine-tuning-llms-guide) または [強化学習](https://unsloth.ai/docs/jp/meru/reinforcement-learning-rl-guide) ガイドを見ることができます。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FlDpKitaEagbh0Er8wJFC%2Famd4.png?alt=media&#x26;token=f54448fe-0719-464f-bbd1-d73f82aedfc0" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### :1234: AMD GPUでの強化学習

私たちの :ledger:[gpt-oss RL auto win 2048](https://github.com/unslothai/notebooks/blob/main/nb/gpt_oss_\(20B\)_Reinforcement_Learning_2048_Game_BF16.ipynb) の例はMI300X（192GB）GPUで使用できます。目標は2048ゲームを自動でプレイし、RLで勝利することです。LLM（gpt-oss 20b）は2048ゲームに勝つ戦略を自動的に考案し、勝利する戦略には高い報酬を、失敗する戦略には低い報酬を与えます。

{% columns %}
{% column %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-2bc5a2e25a51781fd945ab9e87e73821ed4eb6c9%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column %}
報酬は約300ステップ前後で時間とともに増加します！

RLの目標は、2048ゲームで勝つために平均報酬を最大化することです。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-8d7ea897fd57156a796e4f74aa2e3b60afe9d405%2F2048%20Auto%20Win%20Game%20Reward.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

私たちはUnslothで2048のRL例を実行するためにAMD MI300X（192GB）マシンを使用し、うまく動作しました！

<div><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-174890aa5f63632ebe6f3f212f1ced0d0e8dc381%2FScreenshot%202025-10-17%20052504.png?alt=media" alt=""><figcaption></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-f907ba596705496515fdfb39b49d649697317ca7%2FScreenshot%202025-10-17%20052641.png?alt=media" alt=""><figcaption></figcaption></figure></div>

また、私たちの :ledger:[自動カーネル生成RLノートブック](https://github.com/unslothai/notebooks/blob/main/nb/gpt_oss_\(20B\)_GRPO_BF16.ipynb) もgpt-ossとともに使用して、Pythonで行列乗算カーネルを自動生成できます。このノートブックは報酬ハッキングに対抗するための複数の手法も提供します。

{% columns %}
{% column width="50%" %}
これらのカーネルを自動生成するために使用したプロンプトは次のとおりです：

{% code overflow="wrap" %}

````
ネイティブなPythonコードのみを用いて、新しい高速な行列乗算関数を作成してください。
あなたには数値のリストのリストが与えられます。
以下の形式でバッククォート内に新しい関数を出力してください：
```
python
def matmul(A, B):
    return ...
```
````

{% endcode %}
{% endcolumn %}

{% column width="50%" %}
RLプロセスは、例えばPython内でより高速な行列乗算を行うためにストラッセンアルゴリズムを適用する方法を学習します。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-ddb993e5d2c986794ede1f2b0d08897469b78506%2Fimage%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt="" width="375"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

### :books:AMDの無料ワンクリックノートブック

AMDはDev Cloudを通じて、以下を備えたワンクリックノートブックを提供しています： **無料の192GB VRAM MI300X GPU** で大規模モデルを完全に無料で（サインアップやクレジットカード不要で）トレーニングできます：

* [Qwen3（32B）](https://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/Qwen3_\(32B\)_A100-Reasoning-Conversational.ipynb)
* [Llama 3.3（70B）](https://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/Llama3.3_\(70B\)_A100-Conversational.ipynb)
* [Qwen3（14B）](http://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/Qwen3_\(14B\)-Reasoning-Conversational.ipynb)
* [Mistral v0.3（7B）](http://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_\(7B\)-Alpaca.ipynb)
* [GPT OSS MXFP4（20B）](http://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/Kaggle-GPT_OSS_MXFP4_\(20B\)-Inference.ipynb) - 推論
* 強化学習ノートブック：

{% embed url="<https://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/gpt_oss_(20B)_Reinforcement_Learning_2048_Game_BF16.ipynb>" %}

任意のUnslothノートブックを使用するには、先頭に次を付けてください ***<https://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb>*** に [unsloth-notebooks](https://unsloth.ai/docs/jp/meru/unsloth-notebooks "mention") リンクを次のように変更して <https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_(270M).ipynb> に <https://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/Gemma3_(270M).ipynb>

{% columns %}
{% column width="33.33333333333333%" %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F7NNi4jLKvmZoRnLel9Kg%2Fimage.png?alt=media&#x26;token=0379eda9-569c-4614-afb5-ffec463a7676" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column width="66.66666666666667%" %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FRfKS1GAW7BqL9lGNTcxh%2Fimage.png?alt=media&#x26;token=3a8aeb01-62a7-4d55-89a9-98526052e305" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/jp/meru/install/amd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
