> 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/de/loslegen/install/amd.md).

# LLMs auf AMD-GPUs mit dem Unsloth-Leitfaden feinabstimmen

Erfahre, wie du große Sprachmodelle (LLMs) mit Unsloth auf AMD-GPUs feinabstimmst.

LLMs auf AMD-Hardware bis zu 2-mal schneller und mit etwa 70 % weniger Speicherbedarf feinabstimmen – NVIDIA ist nicht erforderlich. Unsloth unterstützt AMD Radeon RDNA 3/3.5/4 (RX-6000- bis RX-9000-Serie) unter Windows und Linux sowie Rechenzentrums-GPUs wie die MI300X (192 GB).

{% stepper %}
{% step %}

#### **Einzeiliger Installer**

Am einfachsten installierst du Unsloth auf AMD, indem du unsere [Desktop-App](https://unsloth.ai/docs/de/desktop.md).

<a href="https://unsloth.ai/download/windows" class="button secondary" data-icon="windows">Für Windows herunterladen</a><a href="https://unsloth.ai/download/linux" class="button secondary" data-icon="linux">Für Linux herunterladen</a>\
\
Für die manuelle Installation:

**Linux:**

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

**Windows (PowerShell):**

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

Die folgenden manuellen Schritte richten sich an Nutzer, die die Python-Bibliothek Unsloth mit den erforderlichen Abhängigkeiten auf AMD installieren möchten.
{% endstep %}

{% step %}

#### **Neue isolierte Umgebung erstellen (optional)**

Die folgenden Schritte gelten für Linux. Unter Windows verwendest du die Desktop-App oder den oben genannten PowerShell-Installer. Diese installieren für dich den Windows-Build von PyTorch für AMD.

Um Systempakete nicht zu beschädigen, solltest du eine isolierte Umgebung erstellen. Denk daran, deine Python-Version zu überprüfen! Sie könnte `python3`, `python3.12`, `python3.13` usw. Python 3.10 bis 3.13 werden unterstützt.

{% 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 installieren**

Auf PyPI gibt es nur den NVIDIA-Build (CUDA) von PyTorch. Installiere daher zuerst den ROCm-Build aus dem PyTorch-Index, der zu deiner ROCm-Version passt. Überprüfe diese mit `amd-smi version` (die Zeile `ROCm version:` ), dann:

{% 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 %}

Ersetze `rocm7.2` durch deine ROCm-Version. Verfügbare Index-Tags sind `rocm6.0` bis `rocm6.4` sowie `rocm7.0` bis `rocm7.2` . Für ROCm 6.5 bis 6.9 wird `rocm6.4`verwendet, für ROCm 7.3 oder neuer `rocm7.2`. Erforderlich ist ROCm 6.0 oder neuer.

Oder lass mit diesem Befehl automatisch den passenden Tag auswählen:

{% 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://797013937-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 installieren**

Unsloth auf PyPI hängt von `torch`ab. Bei einer einfachen Installation kann daher das gerade installierte ROCm-PyTorch durch die CUDA-Version von PyPI ersetzt werden. Um das zu verhindern, pinne dein installiertes PyTorch und installiere mit `uv pip` (nicht mit einfachem `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` sollte eine Zeile mit `torch==...+rocm...` enthalten. Die letzten beiden Zeilen verhindern, dass PyPIs `triton` über das mit PyTorch gelieferte Triton installiert wird, und überspringen PyPIs `xformers`, das nur für NVIDIA-GPUs erstellt wurde.

<div data-with-frame="true"><figure><img src="https://797013937-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 aktualisieren**

Aktualisiere nur Unsloth, mit denselben Pins:

{% code overflow="wrap" %}

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

{% endcode %}

Führe `uv pip install -U unsloth` oder `--force-reinstall` nicht ohne die Pins aus: Beide lösen PyTorch erneut über PyPI auf und ersetzen deinen ROCm-Build durch die CUDA-Version. Falls das bereits passiert ist, meldet `import unsloth` eine AMD-GPU, aber keinen nutzbaren HIP-Beschleuniger: Führe den obigen PyTorch-Schritt und anschließend diesen Schritt erneut aus.
{% endstep %}

{% step %}

#### **Starte das Fine-Tuning mit Unsloth!**

Und das war's. Probiere einige Beispiele auf unserer Seite [**Unsloth-Notebooks**](https://unsloth.ai/docs/de/loslegen/unsloth-notebooks.md) aus!

Hier findest du unsere speziellen Anleitungen für [Fine-Tuning](https://unsloth.ai/docs/de/loslegen/fine-tuning-llms-guide.md) oder [bestärkendes Lernen](https://unsloth.ai/docs/de/loslegen/reinforcement-learning-rl-guide.md) . Hier ist außerdem ein kurzes Beispiel:

**1. Umgebungsvariablen festlegen**

{% code overflow="wrap" %}

```bash
export HF_HUB_DISABLE_XET=1            # Fixes HuggingFace download issues on AMD
```

{% endcode %}

**2. Modell laden und konfigurieren**

{% 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. Trainieren**

{% 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://797013937-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>

***Hinweis:** Flash Attention 2 ist standardmäßig nicht auf AMD-GPUs installiert. Daher verwendet Unsloth stattdessen die integrierte SDPA-Attention von PyTorch. Die Warnung kann gefahrlos ignoriert werden.*
{% endstep %}
{% endstepper %}

### :1234: Reinforcement Learning auf AMD-GPUs

Du kannst unser :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) Beispiel auf einer MI300X-GPU (192 GB) verwenden. Ziel ist es, das Spiel 2048 automatisch zu spielen und mit RL zu gewinnen. Das LLM (gpt-oss 20b) entwickelt automatisch eine Strategie, um das Spiel 2048 zu gewinnen. Für erfolgreiche Strategien berechnen wir eine hohe Belohnung, für gescheiterte Strategien eine niedrige.

{% columns %}
{% column %}

<figure><img src="https://797013937-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 %}
Die Belohnung steigt nach etwa 300 Schritten mit der Zeit an!

Ziel des RL ist es, die durchschnittliche Belohnung zu maximieren, um das Spiel 2048 zu gewinnen.

<figure><img src="https://797013937-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 %}

Wir haben das RL-Beispiel für 2048 mit Unsloth auf einem AMD-MI300X-System (192 GB) ausgeführt – und es hat gut funktioniert!

<div><figure><img src="https://797013937-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://797013937-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>

Du kannst auch unser :ledger:[Notebook für RL zur automatischen Kernel-Generierung](https://github.com/unslothai/notebooks/blob/main/nb/AMD-gpt_oss_\(20B\)_GRPO_BF16.ipynb) ebenfalls mit gpt-oss verwenden, um automatisch Matrixmultiplikations-Kernels in Python zu erstellen. Im Notebook werden außerdem mehrere Methoden vorgestellt, um Reward Hacking entgegenzuwirken.

{% columns %}
{% column width="50%" %}
Der Prompt, den wir zur automatischen Erstellung dieser Kernels verwendet haben, lautete:

{% code overflow="wrap" %}

````
Create a new fast matrix multiplication function using only native Python code.
You are given a list of list of numbers.
Output your new function in backticks using the format below:
```
python
def matmul(A, B):
    return ...
```
````

{% endcode %}
{% endcolumn %}

{% column width="50%" %}
Der RL-Prozess lernt beispielsweise, wie der Strassen-Algorithmus für eine schnellere Matrixmultiplikation in Python angewendet wird.

<figure><img src="https://797013937-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:Kostenlose AMD-Notebooks mit einem Klick

AMD stellt über seine Dev Cloud Notebooks mit **kostenlosen MI300X-GPUs mit 192 GB VRAM** bereit. Trainiere große Modelle völlig kostenlos (keine Anmeldung und keine Kreditkarte erforderlich):

* [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) - Inferenz
* [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>" %}

Um ein AMD-Notebook aus den [Unsloth-Notebooks](https://unsloth.ai/docs/get-started/unsloth-notebooks)zu öffnen, ersetze `https://github.com/` in der URL durch `https://amd-ai-academy.com/github/`. Der Rest der URL bleibt unverändert.

Probiere das **Reinforcement-Learning-Notebook für gpt-oss 20B zu 2048**. [Auf GitHub ansehen](https://github.com/unslothai/notebooks/blob/main/nb/AMD-gpt_oss_%2820B%29_Reinforcement_Learning_2048_Game_BF16.ipynb) oder [in der AMD Developer Cloud öffnen](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://797013937-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://797013937-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/de/loslegen/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.
