> 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 auf 16 Bit speichern, damit Sie es verwenden können für [Unsloth Studio](/docs/de/neu/studio.md), Ollama, llama.cpp und mehr!

{% tabs %}
{% tab title="Lokal" %}
Um als GGUF zu speichern, verwenden Sie 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")
```

Um an den Hugging-Face-Hub zu übertragen:

```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 aufgeführt:

```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. OK-Inferenz, OK-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 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, 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-Quantisierung in extra klein",
}
```

{% endtab %}

{% tab title="Manuelles Speichern" %}
Speichern Sie zuerst Ihr Modell in 16 Bit:

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

Dann verwenden Sie das Terminal und führen Sie Folgendes 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 folgen Sie den Schritten unter <https://rentry.org/llama-cpp-conversions#merging-loras-into-a-model> und verwenden Sie den Modellnamen "merged\_model", um nach GGUF zu mergen.
{% endtab %}
{% endtabs %}

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

Es kann vorkommen, dass Ihr Modell in Unsloth ausgeführt wird und gute Ergebnisse liefert, aber wenn Sie es auf einer anderen Plattform wie Ollama oder vLLM verwenden, sind die Ergebnisse schlecht oder Sie erhalten Kauderwelsch, endlose/unendliche Generierungen *oder* wiederholte Ausgabe&#x6E;**.**

* Die häufigste Ursache für diesen Fehler ist die Verwendung einer <mark style="background-color:blue;">**falschen Chat-Vorlage**</mark>**.** Es ist wichtig, dieselbe Chat-Vorlage zu verwenden, die beim Training des Modells in Unsloth genutzt wurde, und später auch dann, wenn Sie es in einem anderen Framework wie llama.cpp oder Ollama ausführen. Beim Inferenzieren aus einem gespeicherten Modell ist es entscheidend, die richtige Vorlage anzuwenden.
* Sie müssen das richtige `eos-Token`verwenden. Andernfalls erhalten Sie bei längeren Generierungen möglicherweise Kauderwelsch.
* Es könnte auch daran liegen, dass Ihre Inferenz-Engine ein unnötiges "Start-of-Sequence"-Token hinzufügt (oder umgekehrt eines fehlt) – stellen Sie also sicher, dass Sie beide Hypothesen überprüfen!
* <mark style="background-color:green;">**Verwenden Sie unsere Konversations-Notebooks, um die Chat-Vorlage 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 unseren** [**Notebook-Dokumentationen**](/docs/de/loslegen/unsloth-notebooks.md)

### Speichern nach GGUF / vLLM 16 Bit stürzt ab

Sie können versuchen, die maximale GPU-Nutzung während des Speicherns zu reduzieren, indem Sie `maximum_memory_usage`.

Die Voreinstellung ist `model.save_pretrained(..., maximum_memory_usage = 0.75)`. Reduzieren Sie es beispielsweise auf 0,5, um 50 % des GPU-Spitzen-speichers oder weniger zu nutzen. Dies kann OOM-Abstürze beim Speichern reduzieren.

### Wie speichere ich manuell nach GGUF?

Speichern Sie zuerst Ihr Modell über 16 Bit mit:

{% code overflow="wrap" %}

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

{% endcode %}

Kompilieren Sie 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 %}

Speichern Sie dann das Modell als 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 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/grundlagen/inference-and-deployment/saving-to-gguf.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.
