> 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/zh/mo-xing/kimi-k2.6.md).

# Kimi K2.6：如何在本地运行

在你自己的本地设备上运行 Kimi-K2.6 的分步指南。

Kimi K2.6 是 Moonshot 的一个开源模型，在视觉、编码、agentic、长上下文和聊天任务上提供 SOTA 性能。这个 1T 参数的混合思维模型具有 256K 上下文长度，完整精度需要 610GB 磁盘空间，Dynamic 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 位并需要 **350GB+ 显存/内存** 配&#x7F6E;**.** 对于 **无损** Kimi K2.6，请使用 Q8（`UD-Q8_K_XL`），仅 **大 10GB** 比 Q4（`UD-Q4_K_XL`）。所有上传都使用 [Dynamic 2.0](/docs/zh/ji-chu/dynamic-3.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 时，确实是“无损”的，只存在一些机器极小量差异。其困惑度为 `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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F9aDDLGTfcKyREQKFCkfv%2Ftensor_rmse_over_eps_both_present_percent_thick_legend.png?alt=media&amp;token=2f39c305-5b12-454e-8917-5af54fe9890a" 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 %}

* 搜索、下载、 [运行 GGUF](/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）
* [自动推理](https://unsloth.ai/docs/desktop#feature-deep-dive) 参数调优（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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FFeQ0UUlnjXkDdqhcWglh%2Fskinny%20studio%20chat.png?alt=media&amp;token=c2ee045f-c243-4024-a8e4-bb4dbe7bae79" 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 配置。首次启动时，你需要创建密码以保护账户，并在之后重新登录。

然后前往 [Unsloth Chat](/docs/zh/xin/studio/chat.md) 选项卡并搜索 **Kimi-K2.6** 在搜索栏中下载你想要的模型和量化版本。确保你有足够的算力来运行模型。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FK6m0UwUjRocivKbidBCl%2Fkimi%20screenshot%2026.png?alt=media&amp;token=403731cc-ab1c-44b0-9fca-cd0745149193" 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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FTbH2CrUTG2TWwgOP74GF%2FGemma%204%20example.gif?alt=media&amp;token=56409d06-3735-4531-97c0-af9968371a26" 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` 直接加载和下载模型，就像 `ollama run`。首先，选择你想要的量化类型，例如 `Q2_K_XL`。还可以使用 `export LLAMA_CACHE="folder"` 来强制 `llama.cpp` 来保存到指定位置。注意，此下载过程可能非常慢，因此最好使用下一节中的手动下载方式。

根据你的使用场景，使用下面的某个具体命令：

**思考模式：**

```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/Kimi-K2.6-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`）之后。如果下载卡住，请查看： [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="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FdBDLDaRXybr9JMCs33bC%2Fkimibench.jpg?alt=media&amp;token=040ea87d-09e8-452c-bfb2-4231305a20d2" alt="" width="563"><figcaption></figcaption></figure></div>


---

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