> 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).

# Anleitung zum Fine-Tuning von LLMs auf AMD-GPUs mit Unsloth

LLMs bis zu 2x schneller feinabstimmen mit \~70 % weniger Speicher auf AMD-Hardware, ganz ohne NVIDIA. Unsloth unterstützt AMD Radeon RDNA 3/3.5/4 (RX 6000–9000-Serie) sowohl unter Windows als auch Linux sowie Rechenzentrums-GPUs einschließlich der MI300X (192 GB).

{% stepper %}
{% step %}

#### **Einzeilen-Installer**

**Einfachste Installation:** Überspringe alle Schritte unten mit dem Einzeilen-Installer; er erkennt deine AMD-GPU automatisch, installiert ROCm-optimiertes PyTorch, bitsandbytes und startet Unsloth Studio:

**Linux:**

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

**Windows (PowerShell):**

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

Die manuellen Schritte unten sind für Nutzer gedacht, die die Unsloth-Python-Bibliothek auf AMD mit den erforderlichen Abhängigkeiten installieren möchten.
{% endstep %}

{% step %}

#### **Erstelle eine neue isolierte Umgebung (optional)**

Um keine Systempakete zu beschädigen, kannst du eine isolierte pip-Umgebung erstellen. Denk daran, zu prüfen, welche Python-Version du hast! Es könnte `pip3`, `pip3.13`, `python3`, `python.3.13` usw.

**Linux:** 3.13 angezeigt; jede Version 3.11–3.13 funktioniert überall (3.10 funktioniert für manuelle Installationen

{% code overflow="wrap" %}

```bash
# Linux — ersetze 3.13 durch die jeweilige Version 3.10–3.13, die du hast
apt update && apt install python3.13-venv -y
python3.13 -m venv unsloth_env
source unsloth_env/bin/activate
pip install uv
```

{% endcode %}

**Windows (PowerShell):**&#x20;

3.13 angezeigt; verwende 3.12, wenn du das Extra unsloth\[rocm72-torch291] installierst

```shellscript
py -3.13 -m venv unsloth_env
unsloth_env\Scripts\Activate.ps1
pip install uv
```

{% endstep %}

{% step %}

#### **PyTorch installieren**

Planst du, Unsloth mit einem AMD-Extra zu installieren (`unsloth[rocm72-torch291]` usw., siehe nächster Abschnitt)? Diese enthalten ein passendes PyTorch, sodass du **diesen Abschnitt überspringen kannst**. Installiere PyTorch hier nur, wenn du es selbst verwalten möchtest oder deine ROCm-Version nicht von einem Extra abgedeckt wird.

**Linux:** \
Installiere PyTorch mit ROCm-Unterstützung aus dem PyTorch-Index. Prüfe deine ROCm-Version mit `amd-smi version` (Achte auf die `ROCm-Version:` Zeile), dann ändere `https://download.pytorch.org/whl/rocm7.1` entsprechend. ROCm 6.0 oder neuer ist erforderlich.

{% code overflow="wrap" %}

```bash
uv pip install "torch>=2.4,<2.11.0" "torchvision<0.26.0" "torchaudio<2.11.0" \
    --index-url https://download.pytorch.org/whl/rocm7.1 --upgrade --force-reinstall
```

{% endcode %}

ROCm 7.2 bringt neuere Wheels mit (torch 2.11), daher verwende unter ROCm 7.2 stattdessen dies:

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

Verfügbare Index-Tags sind `rocm6.0`, `rocm6.1`, `rocm6.2`, `rocm6.3`, `rocm6.4`, `rocm7.0`, `rocm7.1`, und `rocm7.2`. ROCm 6.5–6.9 hat keine eigenen Wheels (verwende `rocm6.4`), und ROCm 7.3+ verwendet `rocm7.2`.

*Die Versionsobergrenzen verhindern, dass versehentlich torch 2.11+ geladen wird, für das es nur ROCm-7.2-Wheels gibt und das Probleme verursachen würde. Aktualisiere `rocm7.1` wie zuvor entsprechend deiner erkannten Version.*

Wir haben auch einen einzelnen Terminalbefehl geschrieben, um die richtige ROCM-Version zu ermitteln, falls das hilft.

```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>=2.4,<2.11.0" "torchvision<0.26.0" "torchaudio<2.11.0" --index-url "https://download.pytorch.org/whl/$ROCM_TAG" --upgrade --force-reinstall
```

*Hinweis: Wenn deine ROCm-Version 7.2 oder höher ist, ersetze `$ROCM_TAG` im obigen Befehl durch `rocm7.1,` existieren für 7.2+ noch keine PyTorch-Wheels.*

<div data-with-frame="true"><figure><img src="/files/aeb60beee540940ce99841bffb3fd96cc4d14417" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### **Unsloth installieren**

Installiere Unsloth mit AMD-Extras:

{% code overflow="wrap" %}

```bash
uv pip install unsloth[amd]
```

{% endcode %}

<div data-with-frame="true"><figure><img src="/files/572efe80c3f03b70a5bff5bd26c20708b6a0de23" alt="" width="547"><figcaption></figcaption></figure></div>

⚠️ Für AMD erforderlich: ROCm-kompatibles bitsandbytes installieren\
Alle ROCm-Systeme benötigen einen Pre-Release-Build von bitsandbytes; Versionen ≤ 0.49.2 haben auf jeder AMD-GPU einen NaN-Fehler beim 4-Bit-Decoding. Hinweis: Verwende `pip` nicht `uv` für diesen Schritt, `uv` da uv das Pre-Release-Wheel aufgrund einer Versionsinkongruenz im Dateinamen ablehnt.

{% code overflow="wrap" %}

```bash
# x86_64-Systeme:
pip install --force-reinstall --no-cache-dir --no-deps \
    "https://github.com/bitsandbytes-foundation/bitsandbytes/releases/download/continuous-release_main/bitsandbytes-1.33.7.preview-py3-none-manylinux_2_24_x86_64.whl"

# aarch64-Systeme: Ersetze x86_64 in der obigen URL durch aarch64

# Fallback, falls die URL nicht erreichbar ist:
# pip install --force-reinstall --no-cache-dir --no-deps "bitsandbytes>=0.49.1"
```

{% endcode %}

<div data-with-frame="true"><figure><img src="/files/13df767fbfafa443d00f5505592ce9cd64c9396c" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

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

Und das war's. Probiere einige Beispiele in unseren [**Unsloth-Notebooks**](/docs/de/loslegen/unsloth-notebooks.md) Seite!

Du kannst unsere speziellen [Fine-Tuning-](/docs/de/loslegen/fine-tuning-llms-guide.md) oder [Reinforcement-Learning-](/docs/de/loslegen/reinforcement-learning-rl-guide.md) Anleitungen ansehen. Hier ist auch ein kurzes Beispiel:

**1. Umgebungsvariablen setzen**

{% code overflow="wrap" %}

```bash
export HSA_OVERRIDE_GFX_VERSION=9.4.2  # Für AMD MI300X erforderlich
export HF_HUB_DISABLE_XET=1            # Behebt HuggingFace-Downloadprobleme auf AMD
```

{% endcode %}

***Hinweis:*** *`HSA_OVERRIDE_GFX_VERSION=9.4.2` weist ROCm an, deine GPU als gfx942 (MI300X) zu behandeln. Ohne dies können einige Kernel nicht kompiliert oder ausgeführt werden.*

**2. Modell laden und konfigurieren**

{% 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. 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="/files/adc3354d4438612b113d9e3aa6c15f4c030c852b" alt="" width="375"><figcaption></figcaption></figure></div>

***Hinweis:** Auf AMD-GPUs ist Flash Attention 2 nicht verfügbar. Unsloth weicht automatisch auf Xformers aus, das unter ROCm eine gleichwertige Leistung bietet. Die Warnung kann sicher 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-(192 GB)-GPU verwenden. Ziel ist es, das 2048-Spiel automatisch zu spielen und es mit RL zu gewinnen. Das LLM (gpt-oss 20b) entwickelt automatisch eine Strategie, um das 2048-Spiel zu gewinnen, und wir berechnen eine hohe Belohnung für erfolgreiche Strategien sowie niedrige Belohnungen für erfolglose Strategien.

{% columns %}
{% column %}

<figure><img src="/files/3a46018e75f28a684632e53082674223e1c00819" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column %}
Die Belohnung steigt nach etwa 300 Schritten oder so!

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

<figure><img src="/files/961583c207fe0de391c6bde0fd789d82d3ff3dc0" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

Wir haben eine AMD-MI300X-Maschine (192 GB) verwendet, um das 2048-RL-Beispiel mit Unsloth auszuführen, und es hat gut funktioniert!

<div><figure><img src="/files/fe87d41f3ff4deabf6b13560e8bd2f344fa0af51" alt=""><figcaption></figcaption></figure> <figure><img src="/files/3598937ce61c786c1830333e7644c2ebbd1371cc" alt=""><figcaption></figcaption></figure></div>

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

{% columns %}
{% column width="50%" %}
Der Prompt, den wir zum automatischen Erstellen dieser Kernel verwendet haben, war:

{% code overflow="wrap" %}

````
Erstelle eine neue schnelle Matrixmultiplikationsfunktion nur mit nativem Python-Code.
Du erhältst eine Liste von Listen mit Zahlen.
Gib deine neue Funktion in Backticks aus und verwende das folgende Format:
```
python
def matmul(A, B):
    return ...
```
````

{% endcode %}
{% endcolumn %}

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

<figure><img src="/files/b50d2e2061bea0b868ed0cf5c71913d82c9e7857" alt="" width="375"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

### :books:Kostenlose AMD-Notebooks mit Ein-Klick-Start

AMD bietet Notebooks mit Ein-Klick-Start an, ausgestattet mit **kostenlosen MI300X-GPUs mit 192 GB VRAM** über ihre Dev Cloud. Trainiere große Modelle völlig kostenlos (keine Anmeldung oder 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>" %}

Du kannst jedes Unsloth-Notebook verwenden, indem du voranstellst <https://amd-ai-academy.com/github/unslothai/notebooks/blob/main/nb> in [Unsloth-Notebooks](/docs/de/loslegen/unsloth-notebooks.md) indem du den Link änderst von <https://github.com/unslothai/notebooks/blob/main/nb/AMD-gpt_oss_(20B)_Reinforcement_Learning_2048_Game_BF16.ipynb>\
zu <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="/files/e04e1a3a8c617ebd14dc3ba2cc8c7428d2161cd7" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column width="66.66666666666667%" %}

<figure><img src="/files/f12dc985f881b756f2c7e47ad7dd222c0cea0586" 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 dynamically by asking a question.

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

```
GET https://unsloth.ai/docs/de/loslegen/install/amd.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
