# Aider Polyglot 上的 Unsloth Dynamic GGUF

我们很高兴展示 Unsloth Dynamic GGUFs 如何让量化像 [DeepSeek-V3.1](/docs/zh/mo-xing/tutorials/deepseek-v3.1-how-to-run-locally.md) （671B）这样的 LLM 到仅 **1-bit** 或 **3 位**，同时仍然能够超越像 **GPT-4.5、GPT-4.1** （2025年4月）和 **Claude-4-Opus** （2025年5月）这样的 SOTA 模型。

此前， [我们已经演示了](/docs/zh/ji-chu/unsloth-dynamic-2.0-ggufs.md) Unsloth Dynamic GGUFs 如何在 5-shot MMLU 和 KL 散度上优于其他量化方法。现在，我们展示它们在使用 **Aider Polyglot** **基准**

<div><figure><img src="/files/3d75b0063b3aff66275abe8924298c78ad250be6" alt="" width="563"><figcaption><p>Thinking Aider 基准</p></figcaption></figure> <figure><img src="/files/c7d89f68b1da30c734e8e2f834090909d9b9c510" alt="" width="563"><figcaption><p>No Thinking Aider 基准</p></figcaption></figure></div>

### ⭐**关键结果**

* 我们的 **1-bit** Unsloth Dynamic GGUF 将 DeepSeek-V3.1 从 **671GB → 192GB（体积减少 75%）** 压缩到如此程度，并且在 no-thinking 模式下大幅优于 GPT-4.1（2025年4月）、GPT-4.5 和 DeepSeek-V3-0324。
* **3 位** Unsloth DeepSeek-V3.1（thinking）GGUF：优于 Claude-4-Opus-20250514（thinking）。
* **5-bit** Unsloth DeepSeek-V3.1（non-thinking）GGUF：性能与 Claude-4-Opus-20250514（non-thinking）相当。
* Unsloth Dynamic GGUFs 的表现始终优于其他非 Unsloth Dynamic imatrix GGUFs
* 其他非 Unsloth 的 1-bit 和 2-bit DeepSeek-V3.1 量化，以及在没有选择性层量化的情况下的标准 1-bit 量化，要么加载失败，要么输出胡言乱语并陷入循环。这凸显了 Unsloth Dynamic GGUFs 能够在很大程度上保留准确性，而其他方法甚至无法正常工作。

**为什么选择** [**Aider Polyglot**](https://aider.chat/docs/leaderboards/) **基准？** Aider 是衡量 LLM 在写作、编码、遵循指令以及无需人工干预地应用更改方面表现如何的最全面指标之一，因此它也是现实世界使用中最难且最有价值的基准之一。

{% hint style="success" %}
该 **关键优势** 使用 Unsloth 套件和模型的一个关键优势在于，我们积极参与 ***修复关键漏洞*** 在主要模型中。我们已与以下团队直接合作： [Qwen3](https://www.reddit.com/r/LocalLLaMA/comments/1kaodxu/qwen3_unsloth_dynamic_ggufs_128k_context_bug_fixes/), [Meta（Llama 4）](https://github.com/ggml-org/llama.cpp/pull/12889), [Mistral（Devstral）](https://app.gitbook.com/o/HpyELzcNe0topgVLGCZY/s/xhOjnexMCB3dmuQFQ2Zq/~/changes/618/basics/tutorials-how-to-fine-tune-and-run-llms/devstral-how-to-run-and-fine-tune), [Google（Gemma 1–3）](https://news.ycombinator.com/item?id=39671146) 和 [Microsoft（Phi-3/4）](https://simonwillison.net/2025/Jan/11/phi-4-bug-fixes)，贡献了显著提升准确性的关键修复。
{% endhint %}

## 🦥Unsloth 动态量化

{% hint style="success" %}
**动态 1 bit 会将重要层以 8 或 16 bit 保存，而将不重要层量化到 1、2、3、4、5 或 6 bit。**
{% endhint %}

在 2024年11月，我们的 [4-bit Dynamic](https://unsloth.ai/blog/dynamic-4bit) Quants 展示了你可以仅通过 <mark style="background-color:green;">**选择性量化层**</mark>，在很大程度上恢复 QLoRA 微调与模型准确性。之后我们研究了 [DeepSeek-R1](/docs/zh/mo-xing/tutorials/deepseek-r1-how-to-run-locally.md)的架构并应用了类似方法，其中我们将某些层量化到低至 1-bit，而将重要层保留为更高位宽（6、8-bit）。这一方法迅速流行起来，并被证明对 MoE 模型尤其有效，使动态量化事实上成为 MoE 量化的默认方案。

当我们的 Dynamic GGUFs 与 [imatrix 校准数据集](https://unsloth.ai/docs/zh/ji-chu/unsloth-dynamic-2.0-ggufs/pages/e658f01212ed739b6cc1648a22333767661730a1#whats-new-in-dynamic-v2.0)配合使用时效果更佳，该数据集专为聊天和编码性能而设计。所有这些使得在不灾难性损失质量的情况下实现了极端的 LLM 压缩。

例如，在 Qwen2-VL-2B-Instruct 中，简单粗暴地将所有层量化到 4bit 会导致模型无法理解下面的图像。那是一列火车，不是海岸景色！

{% columns %}
{% column %}

<figure><img src="/files/5199eadfa42c95696a7cb446c6b4058078ae159a" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column %}

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

我们也在 <https://docs.unsloth.ai/basics/unsloth-dynamic-2.0-ggufs> 中展示了 Gemma 3 和 Llama 4 Scout 的动态基准，说明了我们的方法有多么有效：

{% columns %}
{% column %}

<figure><img src="/files/40a049be9b0a730b8fd26233c09fc676bf08f25f" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column %}

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

### ⚙️基准设置

对于我们的 DeepSeek-V3.1 实验，我们将不同位宽的 **Unsloth Dynamic GGUFs** 与以下对象进行比较：

* **全精度、未量化的 LLM** 包括 GPT 4.5、4.1、Claude-4-Opus、DeepSeek-V3-0324 等。
* ***其他*****&#x20;动态 imatrix V3.1 GGUFs**
* ***半*****动态** （部分选择性层量化）imatrix V3.1 GGUFs， **用于消融实验**.

基准实验主要由以下人员完成： [David Sluys](https://www.linkedin.com/in/david-sluys-231348208/) （在 [Aider Discord](https://discord.com/channels/1131200896827654144/1408293692074360914)上的 neolithic5452），他是 Aider Polyglot 评测中值得信赖的社区贡献者。测试大约运行了 3 次并取中位数平均分，按照惯例报告 Pass-2 准确率。Aider 的 Discord 中有一些可复现的基准代码片段。

<details>

<summary>展开以查看推理模型的 Aider 基准</summary>

| 模型                               | 准确率      |
| -------------------------------- | -------- |
| GPT-5                            | 86.7     |
| Gemini 2.5 Pro（6月）               | 83.1     |
| o3                               | 76.9     |
| DeepSeek V3.1                    | 76.1     |
| **（3 bit）DeepSeek V3.1 Unsloth** | **75.6** |
| Claude-4-Opus（5月）                | 72       |
| o4-mini（High）                    | 72       |
| DeepSeek R1 0528                 | 71.4     |
| **（2 bit）DeepSeek V3.1 Unsloth** | **66.7** |
| Claude-3.7-Sonnet（2月）            | 64.9     |
| **（1 bit）DeepSeek V3.1 Unsloth** | **57.8** |
| DeepSeek R1                      | 56.9     |

</details>

<details>

<summary>展开以查看非推理模型的 Aider 基准</summary>

| 模型                               | 准确率      |
| -------------------------------- | -------- |
| DeepSeek V3.1                    | 71.6     |
| Claude-4-Opus（5月）                | 70.7     |
| **（5 bit）DeepSeek V3.1 Unsloth** | **70.7** |
| **（4 bit）DeepSeek V3.1 Unsloth** | **69.7** |
| **（3 bit）DeepSeek V3.1 Unsloth** | **68.4** |
| **（2 bit）DeepSeek V3.1 Unsloth** | **65.8** |
| Qwen3 235B A22B                  | 59.6     |
| Kimi K2                          | 59.1     |
| **（1 bit）DeepSeek V3.1 Unsloth** | **55.7** |
| DeepSeek V3-0324                 | 55.1     |
| GPT-4.1（2025年4月）                 | 52.4     |
| ChatGPT 4o（2025年3月）              | 45.3     |
| GPT-4.5                          | 44.9     |

</details>

DeepSeek V3.1 同时具有推理和非推理模式，我们两者都进行了测试。对于非推理模式，我们可以清晰看到下面动态量化的表现趋势：动态 5-bit 在 Aider Pass-2 上达到 70.7%，而动态 1-bit 达到 55.7%。就尺寸和准确率而言，3-bit 和 4-bit 都极其强大！

<figure><img src="/files/c7d89f68b1da30c734e8e2f834090909d9b9c510" alt=""><figcaption></figcaption></figure>

## :sparkler:与其他量化方案的比较

我们还在社区提供的其他动态 imatrix GGUFs 上运行了 Aider Polyglot 基准，并将其与我们的结果进行比较。为了确保 **公平比较**，我们采取以下做法：

1. 我们为每个 Unsloth 量化选择大小和位类型相近的文件。
2. 我们使用我们的 **固定聊天模板** 如果社区量化无法执行基准测试。我们发现一些社区量化 `{"code":500,"message":"split method must have between 1 and 1 positional arguments and between 0 and 0 keyword arguments at row 3, column 1908"}`，而使用我们的固定聊天模板就能修复这一问题。

我们看到，Unsloth 动态量化在与同模型大小和同量化类型的其他社区量化相比时表现非常出色！

<figure><img src="/files/dac3d4106ae2ef4b36f759c805ce4633fccae9b4" alt=""><figcaption></figcaption></figure>

<details>

<summary>展开查看与其他量化的原始数值数据比较</summary>

<table><thead><tr><th width="109.25">量化</th><th width="171.25006103515625">量化大小（GB）</th><th>Unsloth 准确率 %</th><th>对比准确率 %</th></tr></thead><tbody><tr><td>IQ2_XXS</td><td>164</td><td></td><td>43.6</td></tr><tr><td>TQ1_0</td><td>170</td><td>50.7</td><td></td></tr><tr><td>IQ1_M</td><td>206</td><td>55.7</td><td></td></tr><tr><td>IQ2_M</td><td>215</td><td></td><td>56.6</td></tr><tr><td>IQ2_XXS</td><td>225</td><td>61.2</td><td></td></tr><tr><td>IQ2_M</td><td>235</td><td>64.3</td><td></td></tr><tr><td>Q2_K_L</td><td>239</td><td></td><td>64.0</td></tr><tr><td>Q2_K_XL</td><td>255</td><td>65.8</td><td></td></tr><tr><td>IQ3_XXS</td><td>268</td><td>65.6</td><td>65.6</td></tr><tr><td>IQ3_XXS</td><td>279</td><td>66.8</td><td></td></tr><tr><td>Q3_K_S</td><td>293</td><td></td><td>65.2</td></tr><tr><td>Q3_K_XL</td><td>300</td><td>68.4</td><td></td></tr><tr><td>IQ4_XS</td><td>357</td><td>69.2</td><td></td></tr><tr><td>IQ4_XS</td><td>360</td><td></td><td>66.3</td></tr><tr><td>Q4_K_XL</td><td>387</td><td>69.7</td><td></td></tr><tr><td>Q4_K_M</td><td>405</td><td>69.7</td><td></td></tr><tr><td>Q4_K_M</td><td>409</td><td></td><td>67.7</td></tr><tr><td>Q5_K_M</td><td>478</td><td></td><td>68.9</td></tr><tr><td>Q5_K_XL</td><td>484</td><td>70.7</td><td></td></tr></tbody></table>

</details>

### :cake:动态量化消融

我们也做了一些消融实验，以确认我们的校准数据集和动态量化方法是否真的有效。Unsloth 动态方法的诀窍是将 **重要层量化到更高位宽** 比如 8bits，而 **不重要层则保留在较低位宽，如 2bits**.

为了测试我们的方法，我们将特定张量保留在较低精度，例如 4bit 与更高精度进行对比。如下所示，我们将 `attn_k_b` 张量保留在 4bit（半动态）而不是 8bit（当前 Unsloth），仅仅将量化大小增加约 100MB 左右（<0.1%），准确率就会显著提升！

{% hint style="success" %}
`attn_k_b` 而 DeepSeek V3.1 中其他张量都极其重要 / 对量化非常敏感，应当保留更高精度以维持准确率！
{% endhint %}

<figure><img src="/files/d47bddf3ab275294bc0ac8fec2f2d07e0721a154" alt=""><figcaption></figcaption></figure>

### :bug:聊天模板 Bug 修复

在测试 DeepSeek-V3.1 量化版本时，我们发现一些低位宽量化没有正确包裹 `<think> </think>` 或出现了一些奇怪的格式。这导致一些社区量化在低位宽下无法工作，因此造成了不公平的比较。我们发现 llama.cpp 对 minja（更简单版本的 jinja）的使用不接受 `.split`中的位置参数。我们必须将：

```
{%- set content = content.split("</think>", 1)[1] -%}
```

改为下面这样：

```
{%- set splitted = content.split("</think>") -%}
{%- set content = splitted[1:] | join("</think>") -%}
```

查看 [这里](https://huggingface.co/unsloth/DeepSeek-V3.1-GGUF?chat_template=default\&format=true) 用于我们的固定聊天模板，或者 [这里](https://huggingface.co/unsloth/DeepSeek-V3.1/raw/main/chat_template.jinja) 用于原始 jinja 文件。

### :bar\_chart:Pass Rate 1

Aider 主要报告 pass rate 2。我们也报告 pass rate 1，以比较相同大小的社区量化。我们看到，我们的动态量化在与其他相近大小的社区量化相比时表现好得多，尤其是在小于 2 bit 和大于 4 bit 的情况下。3 bit 和 4 bit 的表现也同样很好。

<figure><img src="/files/0845ce7a9cbfc6d80cf44d26faca0844a0b5c09d" alt=""><figcaption></figcaption></figure>

## :computer:运行 DeepSeek V3.1 动态量化

请前往我们的 [DeepSeek V3.1 指南](/docs/zh/mo-xing/tutorials/deepseek-r1-how-to-run-locally/deepseek-r1-dynamic-1.58-bit.md) ，或者若想快速获取动态 2bit 版本，请执行：

```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-quantize llama-cli llama-gguf-split llama-mtmd-cli llama-server
cp llama.cpp/build/bin/llama-* llama.cpp
```

然后使用 `llama.cpp` 即可直接下载权重。我们也已设置好建议的最佳参数，例如 temperature、聊天模板等：

```bash
export LLAMA_CACHE="unsloth/DeepSeek-V3.1-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/DeepSeek-V3.1-GGUF:Q2_K_XL \\
    --jinja \
    --n-gpu-layers 99 \\
    --temp 0.6 \\
    --top-p 0.95 \
    --min-p 0.01 \
    --ctx-size 8192 \\
    --seed 3407 \
    -ot ".ffn_.*_exps.=CPU"
```


---

# Agent Instructions: 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:

```
GET https://unsloth.ai/docs/zh/ji-chu/unsloth-dynamic-2.0-ggufs/unsloth-dynamic-ggufs-on-aider-polyglot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
