> 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/grundlagen/inference-and-deployment/saving-to-gguf.md).

# Als GGUF speichern

Modelle für GGUF in 16 Bit speichern, damit du es für [Unsloth Studio](/docs/de/neu/studio.md), Ollama, llama.cpp und mehr verwenden kannst!

{% tabs %}
{% tab title="Lokal" %}
Um in GGUF zu speichern, verwende Folgendes, um lokal zu speichern:

```python
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "q4_k_m")
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "q8_0")
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "f16")
```

Auf den Hugging Face Hub hochladen:

```python
model.push_to_hub_gguf("hf_username/directory", tokenizer, quantization_method = "q4_k_m")
model.push_to_hub_gguf("hf_username/directory", tokenizer, quantization_method = "q8_0")
```

Alle unterstützten Quantisierungsoptionen für `quantization_method` sind unten aufgelistet:

```python
# https://github.com/ggml-org/llama.cpp/blob/master/examples/quantize/quantize.cpp#L19
ALLOWED_QUANTS = \
{
    "not_quantized"  : "Empfohlen. Schnelle Konvertierung. Langsame Inferenz, große Dateien.",
    "fast_quantized" : "Empfohlen. Schnelle Konvertierung. Akzeptable Inferenz, akzeptable Dateigröße.",
    "quantized"      : "Empfohlen. Langsame Konvertierung. Schnelle Inferenz, kleine Dateien.",
    "f32"     : "Nicht empfohlen. Behält 100 % Genauigkeit bei, ist aber extrem langsam und speicherhungrig.",
    "f16"     : "Schnellste Konvertierung + behält 100 % Genauigkeit bei. Langsam und speicherhungrig.",
    "q8_0"    : "Schnelle Konvertierung. Hoher Ressourcenverbrauch, aber im Allgemeinen akzeptabel.",
    "q4_k_m"  : "Empfohlen. Verwendet Q6_K für die Hälfte der attention.wv- und feed_forward.w2-Tensoren, sonst Q4_K",
    "q5_k_m"  : "Empfohlen. Verwendet Q6_K für die Hälfte der attention.wv- und feed_forward.w2-Tensoren, sonst Q5_K",
    "q2_k"    : "Verwendet Q4_K für die attention.wv- und feed_forward.w2-Tensoren, Q2_K für die anderen Tensoren.",
    "q3_k_l"  : "Verwendet Q5_K für die attention.wv-, attention.wo- und feed_forward.w2-Tensoren, sonst Q3_K",
    "q3_k_m"  : "Verwendet Q4_K für die attention.wv-, attention.wo- und feed_forward.w2-Tensoren, sonst Q3_K",
    "q3_k_s"  : "Verwendet Q3_K für alle Tensoren",
    "q4_0"    : "Ursprüngliche Quantisierungsmethode, 4-Bit.",
    "q4_1"    : "Höhere Genauigkeit als q4_0, aber nicht so hoch wie q5_0. Hat jedoch eine schnellere Inferenz als q5-Modelle.",
    "q4_k_s"  : "Verwendet Q4_K für alle Tensoren",
    "q4_k"    : "Alias für q4_k_m",
    "q5_k"    : "Alias für q5_k_m",
    "q5_0"    : "Höhere Genauigkeit, höherer Ressourcenverbrauch und langsamere Inferenz.",
    "q5_1"    : "Noch höhere Genauigkeit, höherer Ressourcenverbrauch und langsamere Inferenz.",
    "q5_k_s"  : "Verwendet Q5_K für alle Tensoren",
    "q6_k"    : "Verwendet Q8_K für alle Tensoren",
    "iq2_xxs" : "2,06 bpw-Quantisierung",
    "iq2_xs"  : "2,31 bpw-Quantisierung",
    "iq3_xxs" : "3,06 bpw-Quantisierung",
    "q3_k_xs" : "3-Bit-Extraklein-Quantisierung",
}
```

{% endtab %}

{% tab title="Manuelles Speichern" %}
Speichere zuerst dein Modell in 16 Bit:

```python
model.save_pretrained_merged("merged_model", tokenizer, save_method = "merged_16bit",)
```

Nutze dann das Terminal und führe aus:

{% code overflow="wrap" %}

```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 -DLLAMA_CURL=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

python llama.cpp/convert_hf_to_gguf.py FOLDER --outfile OUTPUT --outtype f16
```

{% endcode %}

Oder befolge die Schritte unter <https://rentry.org/llama-cpp-conversions#merging-loras-into-a-model> und verwende den Modellnamen "merged\_model", um zu GGUF zusammenzuführen.
{% endtab %}
{% endtabs %}

### Das Ausführen in Unsloth funktioniert gut, aber nach dem Export und dem Ausführen auf anderen Plattformen sind die Ergebnisse schlecht

Es kann vorkommen, dass dein Modell in Unsloth läuft und gute Ergebnisse liefert, aber wenn du es auf einer anderen Plattform wie Ollama oder vLLM verwendest, sind die Ergebnisse schlecht oder du bekommst Kauderwelsch oder endlose/unendliche Generierungen *oder* wiederholte Ausgabe&#x6E;**.**

* Die häufigste Ursache für diesen Fehler ist die Verwendung eines <mark style="background-color:blue;">**falschen Chat-Templates**</mark>**.** Es ist entscheidend, dass du dasselbe Chat-Template verwendest, das beim Training des Modells in Unsloth genutzt wurde, und später auch dann, wenn du es in einem anderen Framework wie llama.cpp oder Ollama ausführst. Bei der Inferenz eines gespeicherten Modells ist es entscheidend, das richtige Template anzuwenden.
* Du musst das richtige `eos-Token`verwenden. Andernfalls kannst du bei längeren Generierungen Kauderwelsch erhalten.
* Es könnte auch daran liegen, dass deine Inferenz-Engine ein unnötiges "Start-of-Sequence"-Token hinzufügt (oder umgekehrt keines hinzufügt), also prüfe unbedingt beide Hypothesen!
* <mark style="background-color:green;">**Verwende unsere Konversations-Notebooks, um das Chat-Template zu erzwingen – das behebt die meisten Probleme.**</mark>
  * Qwen-3 14B Konversations-Notebook [**In Colab öffnen**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(14B\)-Reasoning-Conversational.ipynb)
  * Gemma-3 4B Konversations-Notebook [**In Colab öffnen**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_\(4B\).ipynb)
  * Llama-3.2 3B Konversations-Notebook [**In Colab öffnen**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_\(1B_and_3B\)-Conversational.ipynb)
  * Phi-4 14B Konversations-Notebook [**In Colab öffnen**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Phi_4-Conversational.ipynb)
  * Mistral v0.3 7B Konversations-Notebook [**In Colab öffnen**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_\(7B\)-Conversational.ipynb)
  * **Weitere Notebooks in unserer** [**Notebook-Dokumentation**](/docs/de/loslegen/unsloth-notebooks.md)

### Beim Speichern in GGUF / vLLM 16 Bit kommt es zu Abstürzen

Du kannst versuchen, die maximale GPU-Auslastung während des Speicherns zu reduzieren, indem du `maximum_memory_usage`.

Standardmäßig ist `model.save_pretrained(..., maximum_memory_usage = 0.75)`. Reduziere es beispielsweise auf 0.5, um 50 % des GPU-Spitzenspeichers oder weniger zu nutzen. Das kann OOM-Abstürze beim Speichern verringern.

### Wie speichere ich manuell in GGUF?

Speichere zuerst dein Modell über Folgendes in 16 Bit:

{% code overflow="wrap" %}

```python
model.save_pretrained_merged("merged_model", tokenizer, save_method = "merged_16bit",)
```

{% endcode %}

Kompiliere llama.cpp wie unten aus dem Quellcode:

{% code overflow="wrap" %}

```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 -DLLAMA_CURL=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
```

{% endcode %}

Speichere dann das Modell in F16:

```bash
python llama.cpp/convert_hf_to_gguf.py merged_model \
    --outfile model-F16.gguf --outtype f16 \
    --split-max-size 50G
```

```bash
# Für BF16:
python llama.cpp/convert_hf_to_gguf.py merged_model \
    --outfile model-BF16.gguf --outtype bf16 \
    --split-max-size 50G
    
# Für Q8_0:
python llama.cpp/convert_hf_to_gguf.py merged_model \
    --outfile model-Q8_0.gguf --outtype q8_0 \
    --split-max-size 50G
```


---

# 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/grundlagen/inference-and-deployment/saving-to-gguf.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.
