> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/meru/install/amd.md).

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

Unslothを使ってAMD GPU上で大規模言語モデル（LLM）をファインチューニングする方法を学びましょう。

AMDハードウェアで、NVIDIA不要、メモリ使用量を約70%削減しながらLLMを最大2倍高速にファインチューニングできます。Unslothは、WindowsとLinuxの両方でAMD Radeon RDNA 3/3.5/4（RX 6000～9000シリーズ）をサポートするほか、MI300X（192GB）などのデータセンターGPUにも対応しています。

{% stepper %}
{% step %}

#### **ワンラインインストーラー**

AMDにUnslothをインストールする最も簡単な方法は、次のものをダウンロードすることです。 [デスクトップアプリ](https://unsloth.ai/docs/jp/desktop.md).

<a href="https://unsloth.ai/download/windows" class="button secondary" data-icon="windows">Windows版をダウンロード</a><a href="https://unsloth.ai/download/linux" class="button secondary" data-icon="linux">Linux版をダウンロード</a>\
\
手動でインストールする場合：

**Linux：**

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

**Windows（PowerShell）：**

```powershell
irm https://unsloth.ai/install.ps1 | iex
```

以下の手順は、必要な依存関係とともにAMD環境にUnsloth Pythonライブラリをインストールしたいユーザー向けです。
{% endstep %}

{% step %}

#### **新しい隔離環境を作成する（任意）**

以下の手順はLinux向けです。Windowsでは、上記のデスクトップアプリまたはPowerShellインストーラーを使用してください。AMD版のWindows用PyTorchを自動的にインストールします。

システムパッケージに影響を与えないよう、隔離環境を作成してください。使用しているPythonのバージョンも確認しましょう。たとえば、 `python3`, `python3.12`, `python3.13` などがあります。Python 3.10～3.13に対応しています。

{% code overflow="wrap" %}

```bash
apt update && apt install python3.13-venv -y
python3.13 -m venv unsloth_env
source unsloth_env/bin/activate
pip install uv
```

{% endcode %}
{% endstep %}

{% step %}

#### **PyTorchをインストールする**

PyPIで入手できるのはNVIDIA（CUDA）版のPyTorchのみです。そのため、まず、お使いのROCmバージョンに合ったPyTorchインデックスからROCm版をインストールしてください。次のコマンドでバージョンを確認します。 `amd-smi version` （ `ROCm version:` の行）、その後、次を実行します。

{% code overflow="wrap" %}

```bash
uv pip install "torch<2.15" torchvision torchaudio \
    --index-url https://download.pytorch.org/whl/rocm7.2 --upgrade --force-reinstall
```

{% endcode %}

rocm7.2を `rocm7.2` お使いのROCmバージョンに変更してください。利用可能なインデックスタグは `rocm6.0` から `rocm6.4` までと、 `rocm7.0` から `rocm7.2`です。ROCm 6.5～6.9では `rocm6.4`を使用し、ROCm 7.3以降では `rocm7.2`を使用します。ROCm 6.0以降が必要です。

または、次のコマンドでタグを自動選択できます。

{% code overflow="wrap" %}

```bash
ROCM_VER="$(amd-smi version 2>/dev/null | sed -n 's/.*ROCm version: \([0-9]*\.[0-9]*\).*/\1/p' | head -n 1)"
[ -n "$ROCM_VER" ] || ROCM_VER="$(cut -d. -f1,2 /opt/rocm/.info/version 2>/dev/null)"
case "$ROCM_VER" in
    6.[0-4]|7.[0-2]) ROCM_TAG="rocm$ROCM_VER" ;;
    6.*) ROCM_TAG="rocm6.4" ;;
    *) ROCM_TAG="rocm7.2" ;;
esac
echo "ROCm ${ROCM_VER:-unknown}: using $ROCM_TAG"
uv pip install "torch<2.15" torchvision torchaudio \
    --index-url "https://download.pytorch.org/whl/$ROCM_TAG" --upgrade --force-reinstall
```

{% endcode %}

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FTVWdHJi4m8thLmCwOocd%2Fimage.png?alt=media&amp;token=c3c2dc1d-a405-4998-96ec-8dc320e3e4ce" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### **Unslothをインストールする**

PyPI版のUnslothは `torch`に依存しているため、通常のインストールでは、インストールしたばかりのROCm版PyTorchがPyPIのCUDA版に置き換えられる可能性があります。これを防ぐには、インストール済みのPyTorchを固定し、 `uv pip` （通常の `pip`):

{% code overflow="wrap" %}

```bash
uv pip freeze | grep -E '^(torch|torchvision|torchaudio)==' > torch-pins.txt
echo "triton ; sys_platform == 'never'" >> torch-pins.txt
echo "xformers ; sys_platform == 'never'" >> torch-pins.txt
uv pip install "unsloth[amd]" --overrides torch-pins.txt
```

{% endcode %}

`torch-pins.txt` には `torch==...+rocm...` という行が含まれているはずです。最後の2行は、PyPIの `triton` がPyTorchに付属するTritonを上書きしてインストールされるのを防ぎ、PyPIの `xformers`（NVIDIA GPU専用にビルドされています）をインストールしないようにします。

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fe0HmhIq3WvgX4hMh5B8N%2Fimage.png?alt=media&amp;token=8376914f-e8b8-4a84-bee9-83c80ed5ad92" alt="" width="547"><figcaption></figcaption></figure></div>

**Unslothを更新する**

同じピン留めを使って、Unslothだけをアップグレードします。

{% code overflow="wrap" %}

```bash
uv pip install --upgrade-package unsloth --upgrade-package unsloth-zoo "unsloth[amd]" --overrides torch-pins.txt
```

{% endcode %}

ピン留めをせずに `uv pip install -U unsloth` や `--force-reinstall` を実行しないでください。どちらもPyPIからPyTorchを再解決し、ROCm版をCUDA版に置き換えてしまいます。すでにそうなっている場合は、 `import unsloth` でAMD GPUは認識されるものの、使用可能なHIPアクセラレーターが表示されません。その場合は、上記のPyTorchの手順を再実行してから、この手順を実行してください。
{% endstep %}

{% step %}

#### **Unslothでファインチューニングを始めましょう！**

これで完了です。 [**Unsloth Notebooks**](https://unsloth.ai/docs/jp/meru/unsloth-notebooks.md) ページでいくつかの例を試してみてください。

専用の [ファインチューニング](https://unsloth.ai/docs/jp/meru/fine-tuning-llms-guide.md) または [強化学習](https://unsloth.ai/docs/jp/meru/reinforcement-learning-rl-guide.md) ガイドもご覧いただけます。簡単な例も紹介します。

**1. 環境変数を設定する**

{% code overflow="wrap" %}

```bash
export HF_HUB_DISABLE_XET=1            # AMDでのHuggingFaceダウンロード問題を修正
```

{% endcode %}

**2. モデルを読み込んで設定する**

{% code overflow="wrap" %}

```python
from unsloth import FastModel

model, tokenizer = FastModel.from_pretrained(
    model_name = "unsloth/gemma-4-26b-a4b-it",
    max_seq_length = 2048,
    load_in_4bit = True,
)

model = FastModel.get_peft_model(
    model,
    r = 16,
    lora_alpha = 16,
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj"],
)
```

{% endcode %}

**3. 学習**

{% code overflow="wrap" %}

```python
from trl import SFTTrainer, SFTConfig

trainer = SFTTrainer(
    model = model,
    tokenizer = tokenizer,
    train_dataset = dataset,
    formatting_func = formatting_func,
    args = SFTConfig(
        per_device_train_batch_size = 1,
        gradient_accumulation_steps = 4,
        max_steps = 60,
        output_dir = "outputs",
        report_to = "none",
    ),
)

trainer_stats = trainer.train()
```

{% endcode %}

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FwIcg0yj5i1hSyHDLyMYG%2Fimage.png?alt=media&amp;token=a6cbe0c7-fdbf-4feb-ad7b-7ac55ba91872" alt="" width="375"><figcaption></figcaption></figure></div>

***注:** AMD GPUにはFlash Attention 2がデフォルトでインストールされていないため、Unslothは代わりにPyTorch組み込みのSDPAアテンションを使用します。この警告は無視しても問題ありません。*
{% endstep %}
{% endstepper %}

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

MI300X（192GB）GPUで実行できる :ledger:[gpt-ossによる2048 RL自動勝利](https://github.com/unslothai/notebooks/blob/main/nb/AMD-gpt_oss_\(20B\)_Reinforcement_Learning_2048_Game_BF16.ipynb) の例を用意しています。目的は、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を使い、AMD MI300X（192GB）搭載マシンで2048のRLの例を実行したところ、うまく動作しました。

<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/AMD-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内でより高速に行列乗算を行うために、Strassenアルゴリズムを適用する方法などを学習します。

<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は、 **192GBのVRAMを搭載した無料のMI300X GPU** をDev Cloud経由で提供しています。大規模モデルを完全無料でトレーニングできます（登録やクレジットカードは不要です）。

* [Qwen3（32B）](https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(32B\)_A100-Reasoning-Conversational.ipynb)
* [Llama 3.3（70B）](https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/AMD-Llama3.3_\(70B\)_A100-Conversational.ipynb)
* [Qwen3（14B）](https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/AMD-Qwen3_\(14B\)-Reasoning-Conversational.ipynb)
* [Mistral v0.3（7B）](https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/AMD-Mistral_v0.3_\(7B\)-Alpaca.ipynb)
* [GPT OSS MXFP4（20B）](https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/AMD-GPT_OSS_MXFP4_\(20B\)-Inference.ipynb) - 推論
* [Gemma4（E2B）](https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/Gemma4_\(E2B\)_Reinforcement_Learning_Sudoku_Game.ipynb) - 数独RL
* Unsloth Studio

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

AMD のノートブックを開くには、 [Unsloth Notebooks](https://unsloth.ai/docs/get-started/unsloth-notebooks)の `https://github.com/` を URL 内で `https://amd-ai-academy.com/github/`に置き換えてください。URL の残りの部分はそのままにします。

次のノートブックをお試しください： **2048 向け gpt-oss 20B 強化学習ノートブック**. [GitHub で表示](https://github.com/unslothai/notebooks/blob/main/nb/AMD-gpt_oss_%2820B%29_Reinforcement_Learning_2048_Game_BF16.ipynb) または [AMD Developer Cloud で開く](https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/AMD-gpt_oss_%2820B%29_Reinforcement_Learning_2048_Game_BF16.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&amp;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&amp;token=3a8aeb01-62a7-4d55-89a9-98526052e305" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
