> 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不要でLLMを最大2倍高速かつ約70%少ないメモリでファインチューニングできます。Unslothは、WindowsとLinuxの両方でAMD Radeon RDNA 3/3.5/4（RX 6000～9000シリーズ）およびMI300X（192GB）を含むデータセンター向けGPUをサポートします。

{% stepper %}
{% step %}

#### **1行インストーラー**

AMD 版 Unsloth をインストールする最も簡単な方法は、私たちの [デスクトップアプリ](/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にはPyTorchのNVIDIA（CUDA）版しかないため、まずお使いのROCmバージョンに合ったPyTorchインデックスからROCm版をインストールしてください。次で確認できます： `amd-smi version` （ `ROCmバージョン：` の行）、そのあと：

{% 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` をお使いの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**](/docs/jp/meru/unsloth-notebooks.md) ページ！

専用の [ファインチューニング](/docs/jp/meru/fine-tuning-llms-guide.md) または [強化学習](/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-a4-b-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>

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

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

私たちの :ledger:[gpt-oss RL auto win 2048](https://github.com/unslothai/notebooks/blob/main/nb/AMD-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/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 Sudoku
* Unsloth Studio

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

任意のUnslothノートブックは、 <https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb> を [Unslothノートブック](/docs/jp/meru/unsloth-notebooks.md) を先頭に付けることで使用できます。リンクは <https://github.com/unslothai/notebooks/blob/main/nb/AMD-gpt_oss_(20B)_Reinforcement_Learning_2048_Game_BF16.ipynb>\
を <https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb/AMD-Gemma4_(E2B)_Reinforcement_Learning_Sudoku_Game.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.
