# Anleitung: LLMs auf AMD-GPUs mit Unsloth feinabstimmen

Sie können jetzt LLMs mit Unsloth auf Ihrem eigenen lokalen AMD-Setup feinabstimmen. Unsloth unterstützt AMD Radeon RX, MI300X (192 GB) GPUs und mehr.

{% stepper %}
{% step %}
**Erstellen Sie eine neue isolierte Umgebung (optional)**

Um keine Systempakete zu beschädigen, können Sie eine isolierte pip-Umgebung erstellen. Erinnerung: Überprüfen Sie, welche Python-Version Sie haben! Es könnte sein `pip3`, `pip3.13`, `python3`, `python.3.13` usw.

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

Installieren Sie die neueste PyTorch-, TorchAO- und Xformers-Version von <https://pytorch.org/> Überprüfen Sie Ihre ROCM-Version über `amd-smi version` dann ändern Sie `https://download.pytorch.org/whl/rocm7.0` um sie anzupassen.

{% code overflow="wrap" %}

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

{% endcode %}

Wir haben auch einen einzelnen Terminalbefehl geschrieben, um die korrekte ROCM-Version zu extrahieren, falls das hilfreich ist.

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

Installieren Sie die dedizierte AMD-Branch von Unsloth:

{% 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://797013937-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 %}
**Beginnen Sie mit der Feinabstimmung mit Unsloth!**

Und das war's. Probieren Sie einige Beispiele in unseren [**Unsloth-Notebooks**](https://unsloth.ai/docs/de/los-gehts/unsloth-notebooks) Seite!

Sie können unsere dedicated [Feinabstimmung](https://unsloth.ai/docs/de/los-gehts/fine-tuning-llms-guide) oder [Verstärkungslernen](https://unsloth.ai/docs/de/los-gehts/reinforcement-learning-rl-guide) Anleitungen ansehen.

<figure><img src="https://797013937-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: Verstärkungslernen auf AMD-GPUs

Sie können unser :ledger:[gpt-oss RL auto win 2048](https://github.com/unslothai/notebooks/blob/main/nb/gpt_oss_\(20B\)_Reinforcement_Learning_2048_Game_BF16.ipynb) Beispiel auf einer MI300X (192 GB) GPU verwenden. Das Ziel ist, das 2048-Spiel automatisch mit RL zu spielen und zu gewinnen. Das LLM (gpt-oss 20b) entwickelt automatisch eine Strategie, um das 2048-Spiel zu gewinnen; wir bewerten gewinnende Strategien mit hoher Belohnung und erfolglose Strategien mit niedrigen Belohnungen.

{% 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 im Laufe der Zeit nach etwa 300 Schritten oder so!

Das Ziel für RL ist es, die durchschnittliche Belohnung zu maximieren, um das 2048-Spiel 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 verwendeten eine AMD MI300X-Maschine (192 GB), um das 2048-RL-Beispiel mit Unsloth auszuführen, und es funktionierte gut!

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

Sie können auch unser :ledger:[Notebook zur automatischen Kernel-Generierung für RL](https://github.com/unslothai/notebooks/blob/main/nb/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%" %}
Das Prompt, das wir verwendet haben, um diese Kernel automatisch zu erstellen, war:

{% code overflow="wrap" %}

````
Erstellen Sie eine neue schnelle Matrixmultiplikationsfunktion, die nur nativen Python-Code verwendet.
Sie erhalten eine Liste von Listen mit Zahlen.
Geben Sie Ihre neue Funktion in Backticks im folgenden Format aus:
```
python
def matmul(A, B):
    return ...
```
````

{% endcode %}
{% endcolumn %}

{% column width="50%" %}
Der RL-Prozess lernt zum Beispiel, wie man den Strassen-Algorithmus anwendet, um schnellere Matrixmultiplikation in Python zu erreichen.

<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:AMD Free One-Click-Notebooks

AMD stellt One-Click-Notebooks mit **kostenlosen 192GB VRAM MI300X-GPUs** über ihre Dev Cloud zur Verfügung. Trainieren Sie große Modelle völlig kostenlos (keine Anmeldung oder Kreditkarte erforderlich):

* [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) - Inferenz
* Reinforcement-Learning-Notebook:

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

Sie können jedes Unsloth-Notebook verwenden, indem Sie voranstellen ***<https://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb>*** in [unsloth-notebooks](https://unsloth.ai/docs/de/los-gehts/unsloth-notebooks "mention") indem Sie den Link ändern von <https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_(270M).ipynb> zu <https://oneclickamd.ai/github/unslothai/notebooks/blob/main/nb/Gemma3_(270M).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&#x26;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&#x26;token=3a8aeb01-62a7-4d55-89a9-98526052e305" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}
