# Aider Polyglot 上的 Unsloth Dynamic GGUF

我们很高兴展示 Unsloth Dynamic GGUFs 如何让量化如下 LLM 成为可能 [DeepSeek-V3.1](/docs/zh/mo-xing/tutorials/deepseek-v3.1-how-to-run-locally.md) （671B）压缩到仅 **1 位** 或 **3 位**，并且仍然能够超越如下 SOTA 模型 **GPT-4.5、GPT-4.1** （2025 年 4 月）以及 **Claude-4-Opus** （2025 年 5 月）。

此前， [我们演示了](/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>Aider 推理基准</p></figcaption></figure> <figure><img src="/files/c7d89f68b1da30c734e8e2f834090909d9b9c510" alt="" width="563"><figcaption><p>无推理 Aider 基准</p></figcaption></figure></div>

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

* 我们 **1 位** Unsloth Dynamic GGUF 将 DeepSeek-V3.1 从 **671GB → 192GB（大小减少 75%）** 压缩，而无推理模式显著优于 GPT-4.1（2025 年 4 月）、GPT-4.5 和 DeepSeek-V3-0324。
* **3 位** Unsloth DeepSeek-V3.1（推理）GGUF：优于 Claude-4-Opus-20250514（推理）。
* **5 位** Unsloth DeepSeek-V3.1（非推理）GGUF：与 Claude-4-Opus-20250514（非推理）性能相当。
* Unsloth Dynamic GGUFs 的表现始终优于其他非 Unsloth Dynamic imatrix GGUFs
* 其他非 Unsloth 的 1 位和 2 位 DeepSeek-V3.1 量化版本，以及不带选择性层量化的标准 1 位量化，要么无法加载，要么输出胡言乱语并陷入循环。这凸显了 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 位会将重要层放在 8 位或 16 位，而将不重要层放在 1、2、3、4、5 或 6 位。**
{% endhint %}

在 2024 年 11 月，我们的 [4 位动态](https://unsloth.ai/blog/dynamic-4bit) 量化展示了仅通过 <mark style="background-color:green;">**选择性量化各层**</mark>，就能在很大程度上恢复 QLoRA 微调和模型准确率。之后我们研究了 [DeepSeek-R1](/docs/zh/mo-xing/tutorials/deepseek-r1-how-to-run-locally.md)的架构，并应用了类似方法：将某些层量化到低至 1 位，而将重要层保留为更高位数（6 位、8 位）。这种方法迅速流行起来，并已被证明对 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 上的 neolithic5452 [Aider Discord](https://discord.com/channels/1131200896827654144/1408293692074360914)）负责，他是 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 位）DeepSeek V3.1 Unsloth** | **75.6** |
| Claude-4-Opus（5 月版）            | 72       |
| o4-mini（高）                     | 72       |
| DeepSeek R1 0528               | 71.4     |
| **（2 位）DeepSeek V3.1 Unsloth** | **66.7** |
| Claude-3.7-Sonnet（2 月版）        | 64.9     |
| **（1 位）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 位）DeepSeek V3.1 Unsloth** | **70.7** |
| **（4 位）DeepSeek V3.1 Unsloth** | **69.7** |
| **（3 位）DeepSeek V3.1 Unsloth** | **68.4** |
| **（2 位）DeepSeek V3.1 Unsloth** | **65.8** |
| Qwen3 235B A22B                | 59.6     |
| Kimi K2                        | 59.1     |
| **（1 位）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 位在 Aider Pass-2 上达到 70.7%，而动态 1 位达到 55.7%。就大小和准确率而言，3 位和 4 位非常强大！

<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 动态方法的诀窍在于将 **重要层量化到更高位数** 例如 8 位，而将 **不重要层保留在更低位数，比如 2 位**.

为了测试我们的方法，我们将某些张量保留在较低精度下，例如 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:聊天模板漏洞修复

在测试 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:通过率 1

Aider 主要报告的是通过率 2。我们也报告通过率 1，以比较同大小的社区量化版本。我们发现，尤其是在低于 2 位和高于 4 位的情况下，我们的动态量化比其他类似大小的社区量化好得多。3 位和 4 位的表现同样出色。

<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) ，或者为了快速获取动态 2 位版本，执行：

```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` 直接下载权重。我们也已经设置好了最佳建议参数，例如温度、聊天模板等：

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