> 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/modelle/gemma-4/qat.md).

# Gemma 4 QAT

Führe Google-Gemma-4-QAT-Modelle lokal aus, einschließlich E2B, E4B, 12B, 26B-A4B und 31B.

Gemma 4 QAT (Quantization-Aware Training) ist Googles DeepMinds neue [Gemma 4](/docs/de/modelle/gemma-4.md) Varianten, die darauf ausgelegt sind, **den Speicherbedarf zu reduzieren und gleichzeitig die Modellqualität zu erhalten**. Dadurch ist es möglich, größere Modelle wie **Gemma 4 26B-A4B**lokal auf Consumer-GPUs mit so wenig wie **16 GB RAM**.

Gemma 4 QAT wird mit Blick auf Quantisierung trainiert, sodass das 4-Bit-Format \~**72 % weniger Speicherverbrauch** mit **nahezu originale Leistung**. 2 spezielle mobile Quants von E2B und E4B werden ebenfalls bereitgestellt, die eine Mischung aus Quantisierungsbreiten verwenden.

Konvertieren zu `Q4_0` aus QAT naiv erzielt für 26B-A4B nur 70,2 % Top-1-Genauigkeit. [Wir haben unsere Unsloth-Dynamic-Methode angewendet](#qat-analysis) um sie zu steigern auf **85,6 % (+15,6 %) und gleichzeitig** [**200 MB kleiner**](#usage-guide)!

Gemma 4 QAT umfasst: **E2B**, **E4B**, **12B, 26B-A4B**, und **31B.** Es sind multimodale Modelle mit hybrider Denkweise, die 140+ Sprachen und bis zu **256K Kontext unterstützen.**

{% columns %}
{% column %} <a href="/docs/de/modelle/gemma-4/qat.md#run-gemma-4-qat-tutorials" class="button primary">Gemma 4 QAT ausführen</a><a href="/docs/de/modelle/gemma-4/qat.md#qat-analysis" class="button secondary">QAT-Analyse</a>

**Gemma-4-E2B** QAT läuft mit 3 GB RAM, **E4B** auf 5 G&#x42;**, 12B** auf 7 G&#x42;**, 26-A4B** auf 15 GB und **31B** auf 18 G&#x42;**.**

Wir bezeichnen unsere Gemma 4 QAT GGUFs als `UD-Q4_K_XL` da wir festgestellt haben, dass q4\_0 die Genauigkeit verschlechtert, obwohl es größer ist. Siehe unsere [Gemma 4 QAT GGUFs](https://huggingface.co/collections/unsloth/gemma-4-qat).

Zum Vergleich `int4` Quantisierung sehen Sie unten die Größenunterschiede zwischen Original und QAT. QAT verwendet \~72 % weniger Speicher, während nahezu die gesamte ursprüngliche Genauigkeit erhalten bleibt:
{% endcolumn %}

{% column %}

<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%2FGLHNSIo3qe4ByThVZDzm%2Fgemma%204%20qat.png?alt=media&amp;token=ae72b8e1-def7-447c-bafc-67514354df7d" alt="" width="563"><figcaption><p>Visualisierung, wie Gemma 4 Mobile QAT funktioniert.</p></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

| Gemma 4     | QAT (int4) GGUF | Ursprüngliches BF16 | Prozentuale Änderung |
| ----------- | --------------: | ------------------: | -------------------: |
| **E2B**     |         2,62 GB |             9,31 GB |               71.86% |
| **E4B**     |         4,22 GB |             15,1 GB |               72.05% |
| **12B**     |         6,72 GB |             23,8 GB |               71.76% |
| **26B A4B** |         14,2 GB |             50,5 GB |               71.88% |
| **31B**     |         17,3 GB |             61,4 GB |               71.82% |

### Nutzungsleitfaden

Gemma 4 QAT-Varianten für E2B und E4B sind für Telefone und Laptops konzipiert, während die größeren 26B-A4B und 31B QAT Modelle jetzt auf Laptops statt nur auf leistungsstarken Heim-GPUs laufen.

Es gibt **nur eine GGUF-Datei** für jedes Gemma-4-Modell, weil wir festgestellt haben, dass höhere Präzisionen als die hochgeladene `UD-Q4_K_XL` Version die Genauigkeit verschlechtern, statt sie zu verbessern. Verwenden Sie die ursprünglichen nicht-QAT Q4\_0-Quants [hier](https://huggingface.co/collections/unsloth/gemma-4).

<figure><img src="https://797013937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FrTygbMBlZcUER9GUMzKg%2Fimage.png?alt=media&amp;token=85c3c44b-0f42-477a-9ce2-30b085e21b5c" alt="" width="563"><figcaption></figcaption></figure>

### Hardwareanforderungen

**Tabelle: empfohlene Hardwareanforderungen für Gemma 4 QAT Inference GGUF** (Einheiten = Gesamtspeicher: RAM + VRAM oder Unified Memory).

| Gemma 4 QAT     | Anforderungen |
| --------------- | ------------: |
| **E2B** QAT     |          3 GB |
| **E4B** QAT     |          5 GB |
| **12B** QAT     |          7 GB |
| **26B A4B** QAT |         15 GB |
| **31B** QAT     |         18 GB |

{% hint style="info" %}
Die Tabelle geht von \~8K Tokens Kontext aus. Der Standardwert von llama.cpp mit 256K Kontext für 26B A4B fügt \~5 GB KV-Cache hinzu. Auf speicherbegrenzten Maschinen nur mit CPU verwenden `-c 8192` oder `-c 16384`; `--fit` ignoriert derzeit neu gepackte CPU-Gewichte.
{% endhint %}

### Empfohlene Einstellungen

Die QAT-Checkpoints verwenden dieselben empfohlenen Gemma-4-Einstellungen:

* `temperature = 1.0`
* `top_p = 0.95`
* `top_k = 64`

{% hint style="info" %}
Der maximale Kontext von Gemma 4 ist **128K** für **E2B**, **E4B** und **256K** für **12B**, **26B A4B**, **31B**.
{% endhint %}

## QAT-Analyse

Wir stellten fest, dass die naive Konvertierung des QAT-Q4\_0-Checkpoints zu Q4\_0 in der llama.cpp-Welt die Genauigkeit tatsächlich verschlechterte und nicht wirklich mit dem BF16-QAT-Gitter für Q4\_0 übereinstimmte. Wir haben unsere Unsloth-Dynamic-Methode angewendet, um eine bessere Übereinstimmung zwischen dem mit llama.cpp kompatiblen Q4\_0-Format und dem echten BF16-QAT-Q4\_0-Format zu erzwingen, und es geschafft, die Quants sowohl kleiner zu machen (Q6\_K wurde für Embeddings nicht benötigt) als auch genauer!

<figure><img src="https://797013937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FcBHRs9twWiAnjgtm4EKf%2Fimage.png?alt=media&amp;token=023d7771-dba1-4a1e-a8c4-da6ac98921f7" alt=""><figcaption></figcaption></figure>

Unten ist eine Tabelle mit KLD, Top-1-%-Genauigkeit und Festplattenspeicher. Sie können sehen, dass unsere Versionen 99,9 % KLD und den mittleren KLD dramatisch verbessern. **E2B hat zum Beispiel einen mittleren KLD von 0,00173 gegenüber 0,05109 (relativ 29x besser) bei einer naiven Q4\_0-Quantisierung, und unsere ist sogar 22 % kleiner!**

Das Hauptproblem ist, dass die Konvertierung von QAT BF16 zu llama.cpps Q4\_0-Format nicht verlustfrei ist. llama.cpp verwendet F16-Skalen, während QAT BF16 BF16-Skalen verwendet, und die Skalen werden in der llama.cpp-Welt nicht optimal bestimmt.

Die naive Konvertierung erreicht 24,77 % Byte-Genauigkeit gegenüber BF16 QAT, während wir festgestellt haben, dass wir sie mit einigen Tricks auf 99,96 % steigern können!

<table><thead><tr><th width="100">Modell</th><th>Methode</th><th>Festplatte (GB)</th><th>99,9 % KLD</th><th>Mittlere KLD</th><th width="77.5999755859375">Top-1 %</th></tr></thead><tbody><tr><td>E2B</td><td>Unsloth</td><td><strong>2.62</strong></td><td>0.0557</td><td>0.00173</td><td><strong>98.16</strong></td></tr><tr><td>E2B</td><td>Q4_0</td><td>3.35</td><td>1.0513</td><td>0.05109</td><td>89.29</td></tr><tr><td>E4B</td><td>Unsloth</td><td><strong>4.22</strong></td><td>0.0536</td><td>0.00121</td><td><strong>98.54</strong></td></tr><tr><td>E4B</td><td>Q4_0</td><td>5.15</td><td>0.6722</td><td>0.03778</td><td>90.94</td></tr><tr><td>26B</td><td>Unsloth</td><td><strong>14.25</strong></td><td>2.7087</td><td>0.09788</td><td><strong>85.63</strong></td></tr><tr><td>26B</td><td>Q4_0</td><td>14.44</td><td>4.5420</td><td>0.36094</td><td>70.20</td></tr><tr><td>31B</td><td>Unsloth</td><td><strong>17.29</strong></td><td>1.3659</td><td>0.01403</td><td><strong>96.67</strong></td></tr><tr><td>31B</td><td>Q4_0</td><td>17.65</td><td>3.0030</td><td>0.09349</td><td>87.91</td></tr><tr><td>12B</td><td>Unsloth</td><td><strong>6.72</strong></td><td>9.2740</td><td>0.13288</td><td><strong>88.76</strong></td></tr><tr><td>12B</td><td>Q4_0</td><td>6.98</td><td>14.7323</td><td>0.50702</td><td>74.08</td></tr></tbody></table>

## Mobiles Mischungs-QAT

Das Gemma-4-Team hat außerdem spezielle mobile Mischungs-QAT-Versionen von Gemma-4-E2B-it und Gemma-4-E4B-it veröffentlicht. Wir haben sie ebenfalls getreu in das mit llama.cpp kompatible Format konvertiert und dabei auch nahezu die gesamte Genauigkeit wiederhergestellt. Wir verwendeten TQ2\_0 für die 2-Bit-Schichten und einen negativen Scaler.

Wir haben UD-Q2\_K\_XL-Quants für sowohl E2B als auch E4B erstellt.

|                              | E2B mobil             | E4B mobil          |
| ---------------------------- | --------------------- | ------------------ |
| Größe                        | 2,19 GB               | 3,22 GB            |
| 2-Bit-(TQ2\_0)-Tensoren      | 61 (inkl. tiefem MLP) | 2 (nur Embeddings) |
| Mittlerer KLD gegenüber BF16 | 0.00409               | 0.00102            |
| Top-1 %                      | 97.82%                | 98.76%             |
| Basis-PPL                    | \~103                 | 42.4               |

Siehe [gemma-4-E2B-it-qat-GGUF](https://huggingface.co/unsloth/gemma-4-E2B-it-qat-GGUF) und [gemma-4-E4B-it-qat-GGUF](https://huggingface.co/unsloth/gemma-4-E4B-it-qat-GGUF) für `UD-Q2_K_XL`.

## Gemma 4 QAT-Tutorials ausführen

Da Gemma 4 GGUFs in mehreren Größen vorliegen, ist der empfohlene Ausgangspunkt für die kleinen Modelle 8-Bit und für die größeren Modelle ist **Dynamisches 4-Bit**. [Gemma 4 GGUFs](https://huggingface.co/collections/unsloth/gemma-4-qat):

| [E2B](https://huggingface.co/unsloth/gemma-4-E2B-it-qat-GGUF) | [E4B](https://huggingface.co/unsloth/gemma-4-E4B-it-qat-GGUF) | [12b](https://huggingface.co/unsloth/gemma-4-12b-it-qat-GGUF) | [26B-A4B](https://huggingface.co/unsloth/gemma-4-26B-A4B-it-qat-GGUF) | [31B](https://huggingface.co/unsloth/gemma-4-31B-it-qat-GGUF) |
| ------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------- |

<a href="/docs/de/modelle/gemma-4/qat.md#unsloth-studio-guide" class="button primary">🦥 Unsloth Studio-Leitfaden</a><a href="/pages/5f03e50470f4e75e2f364ba071a97734e3604a69#llama.cpp-guide" class="button primary">🦙 Llama.cpp-Leitfaden</a>

{% columns %}
{% column %}
**Sie können Gemma 4 QAT kostenlos mit einer UI in unserem** [**Unsloth Studio**](/docs/de/neu/studio.md)✨ **Notebook ausführen und trainieren:**
{% endcolumn %}

{% column %}
{% embed url="<https://colab.research.google.com/github/unslothai/unsloth/blob/main/studio/Unsloth_Studio_Colab.ipynb>" %}
{% endcolumn %}
{% endcolumns %}

### 🦥 Unsloth Studio-Leitfaden

Gemma 4 QAT kann jetzt in [Unsloth Studio](/docs/de/neu/studio.md), unserer neuen Open-Source-Web-UI für lokale KI, ausgeführt und trainiert werden. Unsloth Studio ermöglicht es Ihnen, Modelle lokal auf **macOS, Windows**, Linux und:

{% columns %}
{% column %}

* Suchen, herunterladen, [GGUFs ausführen](/docs/de/neu/studio.md#run-models-locally) und Safetensor-Modelle
* [**Selbstheilend** Tool-Aufrufe](/docs/de/neu/studio.md#execute-code--heal-tool-calling) + **Websuche**
* [**Codeausführung**](/docs/de/neu/studio.md#run-models-locally) (Python, Bash)
* [Automatische Inferenz](https://unsloth.ai/docs/desktop#feature-deep-dive) Abstimmung der Parameter (Temp., Top-p usw.)
* Schnelle CPU- + GPU-Inferenz über llama.cpp
* [LLMs trainieren](/docs/de/neu/studio.md#no-code-training) 2x schneller mit 70 % weniger VRAM
  {% endcolumn %}

{% column %}

<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%2FVrLgXwplAMcvkU4owjPk%2F26b%20gif.gif?alt=media&amp;token=8a569952-c152-435f-b815-c9f295619587" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% stepper %}
{% step %}

#### Unsloth installieren

Führen Sie dies in Ihrem Terminal aus:

**macOS, Linux, WSL:**

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

**Windows PowerShell:**

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

{% endstep %}

{% step %}

#### Unsloth starten

**macOS, Linux, WSL und Windows:**

```bash
unsloth studio -H 0.0.0.0 -p 8888
```

Dann öffnen Sie `http://127.0.0.1:8888` (oder Ihre spezifische URL) in Ihrem Browser.
{% endstep %}

{% step %}

#### Gemma 4 QAT suchen und herunterladen

Beim ersten Start müssen Sie ein Passwort erstellen, um Ihr Konto zu sichern, und sich erneut anmelden.

Gehen Sie dann zum [Unsloth Chat](/docs/de/neu/studio/chat.md) Tab und suchen Sie in der Suchleiste nach Gemma 4 und laden Sie Ihr gewünschtes Modell und den gewünschten Quant herunter.
{% endstep %}

{% step %}

#### Gemma 4 QAT ausführen

Die Inferenzparameter sollten bei der Verwendung von Unsloth Studio automatisch gesetzt werden, Sie können sie jedoch weiterhin manuell ändern. Sie können auch die Kontextlänge, das Chat-Template und andere Einstellungen bearbeiten.

Für weitere Informationen können Sie unseren [Inferenzleitfaden für Unsloth Studio](/docs/de/neu/studio/chat.md).

<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%2FVrLgXwplAMcvkU4owjPk%2F26b%20gif.gif?alt=media&amp;token=8a569952-c152-435f-b815-c9f295619587" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

### 🦙 Llama.cpp-Leitfaden

Für diese Anleitung müssen Sie keinen Quantisierungstyp auswählen, da es nur einen gibt: `UD-Q4_K_XL`. Siehe: [Gemma 4 QAT-Sammlung](https://huggingface.co/collections/unsloth/gemma-4-qat). Für diese Tutorials werden wir [llama.cpp](llama.cpphttps://github.com/ggml-org/llama.cpp) für schnelle lokale Inferenz verwenden, besonders wenn Sie eine CPU haben.

{% stepper %}
{% step %}
Holen Sie sich die neueste `llama.cpp` **auf** [**hier auf GitHub**](https://github.com/ggml-org/llama.cpp). Sie können auch die folgenden Build-Anweisungen befolgen. Ändern Sie `-DGGML_CUDA=ON` zu `-DGGML_CUDA=OFF` wenn Sie keine GPU haben oder nur CPU-Inferenz möchten. **Für Apple-Mac-/Metal-Geräte**, setzen Sie `-DGGML_CUDA=OFF` und fahren Sie dann wie gewohnt fort – Metal-Unterstützung ist standardmäßig aktiviert.

```bash
apt-get update
apt-get install pciutils build-essential cmake curl libcurl4-openssl-dev -y
git clone https://github.com/ggml-org/llama.cpp
cmake llama.cpp -B llama.cpp/build \\
    -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-mtmd-cli llama-server llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

{% endstep %}

{% step %}
Wenn Sie `llama.cpp` um Modelle direkt zu laden, können Sie die folgenden Befehle je nach Modell befolgen. `UD-Q4_K_XL` ist der EINZIGE Quantisierungstyp. Sie können auch über Hugging Face herunterladen (Schritt 3). Das ist ähnlich wie `ollama run` . Verwenden Sie `export LLAMA_CACHE="folder"` um zu erzwingen `llama.cpp` um an einem bestimmten Speicherort zu speichern.

**26B-A4B:**

```bash
export LLAMA_CACHE=\"unsloth/gemma-4-26B-A4B-it-qat-GGUF\"
./llama.cpp/llama-cli \\
    -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

**31B:**

```bash
export LLAMA_CACHE=\"unsloth/gemma-4-31B-it-qat-GGUF\"
./llama.cpp/llama-cli \\
    -hf unsloth/gemma-4-31B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

**E4B:**

```bash
export LLAMA_CACHE=\"unsloth/gemma-4-E4B-it-qat-GGUF\"
./llama.cpp/llama-cli \\
    -hf unsloth/gemma-4-E4B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

**E2B:**

```bash
export LLAMA_CACHE=\"unsloth/gemma-4-E2B-it-GGUF\"
./llama.cpp/llama-cli \\
    -hf unsloth/gemma-4-E2B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

{% endstep %}

{% step %}
Lade das Modell über (nach der Installation von `pip install huggingface_hub hf_transfer` ). Sie können `UD-Q4_K_XL` oder andere quantisierte Versionen wie `Q8_0` wählen. Falls Downloads hängen bleiben, siehe: [Hugging Face Hub, XET-Debugging](/docs/de/grundlagen/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

```bash
hf download unsloth/gemma-4-26B-A4B-it-qat-GGUF \\
    --local-dir unsloth/gemma-4-26B-A4B-it-qat-GGUF \\
    --include "*mmproj-BF16*" \\
    --include "*UD-Q4_K_XL*" # Verwenden Sie "*UD-Q2_K_XL*" für dynamisches 2-Bit
```

{% endstep %}

{% step %}
Führen Sie das Modell dann im Konversationsmodus aus (mit Vision `mmproj-F16`):

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \\
    --model unsloth/gemma-4-26B-A4B-it-qat-GGUF/gemma-4-26B-A4B-it-qat-UD-Q4_K_XL.gguf \\
    --mmproj unsloth/gemma-4-26B-A4B-it-qat-GGUF/mmproj-BF16.gguf \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

{% endcode %}
{% endstep %}

{% step %}

### Llama-server-Bereitstellung

Um Gemma-4 auf llama-server bereitzustellen, verwenden Sie:

```bash
./llama.cpp/llama-server \\
    --model unsloth/gemma-4-26B-A4B-it-qat-GGUF/gemma-4-26B-A4B-it-qat-UD-Q4_K_XL.gguf \\
    --mmproj unsloth/gemma-4-26B-A4B-it-qat-GGUF/mmproj-BF16.gguf \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64 \\
    --alias \"unsloth/gemma-4-26B-A4B-it-qat-GGUF\" \\
    --port 8001 \
    --chat-template-kwargs '{"enable_thinking":true}'
```

{% hint style="warning" %}
Um [Denken/Schlussfolgern deaktivieren](#how-to-enable-or-disable-reasoning-and-thinking), verwenden Sie `--chat-template-kwargs '{"enable_thinking":false}'`

Wenn Sie auf **Windows** PowerShell bist, verwende: `--chat-template-kwargs "{\"enable_thinking\":false}"`

Verwenden Sie 'true' und 'false' austauschbar.
{% endhint %}
{% endstep %}
{% endstepper %}


---

# 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/modelle/gemma-4/qat.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.
