# Kimi K2.6 - 如何本地运行

Kimi K2.6 是 Moonshot 推出的开源模型，在视觉、编程、Agent、长上下文和聊天任务上都能提供 SOTA 性能。这个 1T 参数的混合思考模型具有 256K 的上下文长度，完整精度需要 610GB 磁盘空间，动态 2-bit 需要 **350GB（-43% 大小）**。通过 Unsloth Dynamic 运行 Kimi K2.6 [**Kimi-K2.6-GGUFs**](https://huggingface.co/unsloth/Kimi-K2.6-GGUF) ，可在 Unsloth Studio 或 llama.cpp 上使用。

**动态 2-bit** 会将重要层提升到 8-bit，并需要 **350GB+ 显存/内存** 配&#x7F6E;**.** 对于 **无损的** Kimi K2.6，请使用 Q8（`UD-Q8_K_XL`），它只比 Q4（ **大 10GB** ）多。`UD-Q4_K_XL`。所有上传都使用 [Dynamic 2.0](/docs/zh/ji-chu/unsloth-dynamic-2.0-ggufs.md) 以获得 SOTA 量化性能。Kimi-K2.6 GGUF 也 **支持视觉。**

**表：硬件要求** （单位 = 总内存：RAM + VRAM，或统一内存）

| 测量   | 动态 2-bit | Q4     | Q8（无损） |
| ---- | -------- | ------ | ------ |
| 磁盘空间 | 340 GB   | 584 GB | 595 GB |
| 困惑度  | 2.4131   | 1.8420 | 1.8419 |

### 📊 量化分析

`UD-Q8_K_XL` 是无损的，因为 Kimi 对 MoE 权重使用 int4，对其他所有部分使用 BF16，而 `Q8_K_XL` 遵循这一点。 `UD-Q4_K_XL` 类似，只是其余张量是 `Q8_0`，因此它接近完整精度，并需要 600GB RAM/VRAM。来自其他提供方的其他非 Unsloth GGUF 可能采用 `UD-Q4_K_XL` 方法，而不是“真正无损”的 `UD-Q8_K_XL`.

我们遵循了 [jukofyork](https://github.com/jukofyork)的发现，即 `const float d = max / -7;` 而不是默认的 `const float d = max / -8;` ，仅在 MoE 层的量化过程中。这个针对 INT4 原生 MoE 的双射补丁使 `Q4_0` 量化类型将绝对误差从 1.8% 降至接近 0%（epsilon）。

不过，我们必须将其他层保留为 BF16，并在下方展示它们相对于 BF16 基线的误差图。 `UD-Q8-K_XL` 在将 Q4\_0 转换为 BF16 时，确实是“无损”的，仅存在一些机器 epsilon 级别的差异。 `UD-Q8_K_XL` 的困惑度为 1.8419 ± 0.00721，而 `UD-Q4_K_XL` 1.8420 ± 0.00720。请注意，下方的误差图是 RMSE 除以 bfloat16 epsilon，因此这是一个很小的误差尺度。

<div data-with-frame="true"><figure><img src="/files/6d4f704bd88eb4f640abe42f591cc2d05f1c622f" alt=""><figcaption><p>查看 <code>Q4_K_XL</code> （蓝色）与 <code>Q8_K_XL</code> （橙色）之间的差异，后者是无损的，并且大 10GB。</p></figcaption></figure></div>

### :gear: 使用指南

**思考模式和非思考模式需要不同设置：**

| 默认（思考模式）          | 即时模式              |
| ----------------- | ----------------- |
| temperature = 1.0 | temperature = 0.6 |
| top\_p = 0.95     | top\_p = 0.95     |

* 建议的上下文长度 = `98,304` （最多 `262,144`)

如果模型能放得下，在使用 B200 时你会获得 >40 tokens/s。我们推荐 `UD-Q2_K_XL` （350GB）作为大小/质量平衡的不错选择。最佳经验法则：RAM+VRAM ≈ 量化大小；否则它仍然可以运行，只是由于卸载会更慢。

#### Kimi K2.6 的聊天模板

运行 `tokenizer.apply_chat_template([{"role": "user", "content": "1+1 等于多少？"},])` 得到：

{% code overflow="wrap" %}

```
<|im_system|>system<|im_middle|>你是 Kimi，由 Moonshot AI 创建的 AI 助手。<|im_end|><|im_user|>user<|im_middle|>1+1 等于多少？<|im_end|><|im_assistant|>assistant<|im_middle|><think>
```

{% endcode %}

## 运行 Kimi K2.6 指南

### 🦥 在 Unsloth Studio 中运行 Kimi-K2.6

Kimi K2.6 可以在 [Unsloth Studio](/docs/zh/xin/studio.md)中运行，这是一个用于本地 AI 的开源 Web UI。 **Unsloth Studio 会自动卸载到 RAM，并检测多 GPU 配置**。使用 Unsloth Studio，你可以在本地运行模型，支持 **MacOS、Windows**、Linux 以及：

{% columns %}
{% column %}

* 搜索、下载、 [运行 GGUFs](/docs/zh/xin/studio.md#run-models-locally) 和 safetensor 模型
* [**自我修复** 工具调用](/docs/zh/xin/studio.md#execute-code--heal-tool-calling) + **网页搜索**
* [**代码执行**](/docs/zh/xin/studio.md#run-models-locally) （Python、Bash）
* [自动推理](/docs/zh/xin/studio.md#model-arena) 参数调优（temp、top-p 等）
* 通过 llama.cpp 实现快速 CPU + GPU 推理
* [训练 LLM](/docs/zh/xin/studio.md#no-code-training) 快 2 倍，VRAM 减少 70%
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/5af4df407c8134f1ff75a4d7535569361c049e51" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% stepper %}
{% step %}
**安装并启动 Unsloth**

要安装，请在终端中运行：

MacOS、Linux、WSL：

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

Windows PowerShell：

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

**启动 Unsloth**

MacOS、Linux、WSL 和 Windows：

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

然后打开 `http://localhost:8888` 在浏览器中。
{% endstep %}

{% step %}
**搜索并下载 Kimi-K2.6**

Unsloth Studio 会自动卸载到 RAM，并检测多 GPU 配置。首次启动时，你需要创建密码以保护账户，并在之后重新登录。

然后转到 [Studio Chat](/docs/zh/xin/studio/chat.md) 标签页，并在 **Kimi-K2.6** 搜索栏中搜索，下载你想要的模型和量化版本。确保你有足够的计算资源来运行该模型。

<div data-with-frame="true"><figure><img src="/files/4a9b58e74c0dcb530a3defb93176bb456955f534" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**运行 Kimi-K2.6**

在使用 Unsloth Studio 时，推理参数应会自动设置，不过你仍然可以手动更改。你也可以编辑上下文长度、聊天模板和其他设置。

有关更多信息，你可以查看我们的 [Unsloth Studio 推理指南](/docs/zh/xin/studio/chat.md).

<div data-with-frame="true"><figure><img src="/files/23fb40df7f876a1d75f48943c38802ab9e31027f" alt="" width="563"><figcaption><p>使用工具调用运行 Qwen3.6 的示例</p></figcaption></figure></div>
{% endstep %}
{% endstepper %}

### 🦙 在 llama.cpp 中运行 Kimi K2.6

本指南中我们将运行 UD-Q2\_K\_XL 量化版本，它至少需要 350GB RAM。你也可以自由更改量化类型。GGUF： [**Kimi-K2.6-GGUF**](https://huggingface.co/unsloth/Kimi-K2.6-GGUF)

对于这些教程，我们将使用 [llama.cpp](llama.cpphttps://github.com/ggml-org/llama.cpp) 进行快速本地推理，尤其是在你有 CPU 的情况下。

{% stepper %}
{% step %}
获取最新的 `llama.cpp` **在** [**GitHub 上这里**](https://github.com/ggml-org/llama.cpp)。你也可以按照下面的构建说明进行操作。将 `-DGGML_CUDA=ON` 改为 `-DGGML_CUDA=OFF` ，如果你没有 GPU，或者只想进行 CPU 推理。 **对于 Apple Mac / Metal 设备**，设置 `-DGGML_CUDA=OFF` 然后照常继续——Metal 支持默认已启用。

```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 %}
如果你想使用 `llama.cpp` 直接加载模型，你可以执行以下操作：（`Q2_K_XL`）是量化类型。你也可以通过 Hugging Face 下载（第 3 点）。这类似于 `ollama run` 。使用 `export LLAMA_CACHE="folder"` 来强制 `llama.cpp` 保存到特定位置。该模型的最大 `262,144` 上下文长度。

根据你的使用场景，使用下面的特定命令之一：

**思考模式：**

```bash
export LLAMA_CACHE="unsloth/Kimi-K2.6-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/Kimi-K2.6-GGUF:UD-Q2_K_XL \
    --temp 1.0 \
    --top-p 0.95
```

**非思考模式（即时）：**

```bash
export LLAMA_CACHE="unsloth/Qwen3.6-35B-A3B-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/Kimi-K2.6-GGUF:UD-Q2_K_XL \
    --temp 0.6 \
    --top-p 0.95 \
    --chat-template-kwargs '{"enable_thinking":false}'
```

{% endstep %}

{% step %}
通过下面的代码下载模型（在安装之后 `pip install huggingface_hub hf_transfer`）。如果下载卡住，请参见： [Hugging Face Hub，XET 调试](/docs/zh/ji-chu/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

```bash
hf download unsloth/Kimi-K2.6-GGUF \
    --local-dir unsloth/Kimi-K2.6-GGUF \
    --include "*mmproj-F16*" \
    --include "*UD-Q2_K_XL*" # 完整精度请使用 "*UD-Q8_K_XL*"
```

{% endstep %}

{% step %}
然后在对话模式下运行模型：

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Kimi-K2.6-GGUF/UD-Q2_K_XL/Kimi-K2.6-UD-Q2_K_XL-00001-of-0008.gguf \
    --mmproj unsloth/Kimi-K2.6-GGUF/mmproj-F16.gguf \
    --temp 1.0 \
    --top-p 0.95
```

{% endcode %}
{% endstep %}
{% endstepper %}

### 📊 基准测试

你可以在下方查看表格形式的更多基准测试：

<div data-with-frame="true"><figure><img src="/files/e9fdad6e5a8057007bf05c9efb3d3dc464977446" alt="" width="563"><figcaption></figcaption></figure></div>


---

# 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/mo-xing/kimi-k2.6.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.
