# Cogito v2.1：如何本地运行

{% hint style="success" %}
Deep Cogito v2.1 是一个更新后的 671B MoE，截至 2025 年 11 月 19 日，它是最强大的开源权重模型。
{% endhint %}

Cogito v2.1 提供 1 种 671B MoE 尺寸，而 Cogito v2 Preview 是 [Deep Cogito](https://www.deepcogito.com/)发布的模型覆盖 4 种模型规模，范围从 70B 到 671B。通过使用 **IDA（迭代蒸馏与放大）**，这些模型通过迭代式策略改进，让模型内化推理过程来进行训练，而不是仅仅像 DeepSeek R1 那样在推理时搜索更久。

Deep Cogito 位于 [美国旧金山](https://techcrunch.com/2025/04/08/deep-cogito-emerges-from-stealth-with-hybrid-ai-reasoning-models/) （类似于 Unsloth :flag\_us:），我们很高兴为所有 4 种模型规模提供量化动态模型！所有上传都使用 Unsloth [Dynamic 2.0](/docs/zh/ji-chu/unsloth-dynamic-2.0-ggufs.md) 以获得 SOTA 的 5-shot MMLU 和 KL 散度性能，这意味着你可以在几乎不损失精度的情况下运行并微调这些量化 LLM！

**教程导航：**

<a href="https://docs.unsloth.ai/basics/tutorials-how-to-fine-tune-and-run-llms/cogito-v2-how-to-run-locally#run-cogito-671b-moe-in-llama.cpp" class="button secondary">运行 671B MoE</a><a href="https://docs.unsloth.ai/basics/tutorials-how-to-fine-tune-and-run-llms/cogito-v2-how-to-run-locally#run-cogito-109b-moe-in-llama.cpp" class="button secondary">运行 109B MoE</a><a href="https://docs.unsloth.ai/basics/tutorials-how-to-fine-tune-and-run-llms/cogito-v2-how-to-run-locally#run-cogito-405b-dense-in-llama.cpp" class="button secondary">运行 405B Dense</a><a href="https://docs.unsloth.ai/basics/tutorials-how-to-fine-tune-and-run-llms/cogito-v2-how-to-run-locally#run-cogito-70b-dense-in-llama.cpp" class="button secondary">运行 70B Dense</a>

{% hint style="success" %}
选择哪种模型规模适合你的硬件！我们为所有 4 种模型规模上传 1.58bit 到 16bit 的版本！
{% endhint %}

## :gem: 模型规模与上传

共有 4 种模型规模：

1. 基于 Llama 的 2 个 Dense 模型——70B 和 405B
2. 基于 Llama 4 Scout（109B）和 DeepSeek R1（671B）的 2 个 MoE 模型

<table data-full-width="false"><thead><tr><th>模型规模</th><th width="256.9999694824219">推荐量化与链接</th><th>磁盘大小</th><th>架构</th></tr></thead><tbody><tr><td>70B Dense</td><td><a href="https://huggingface.co/unsloth/cogito-v2-preview-llama-70B-GGUF">UD-Q4_K_XL</a></td><td><strong>44GB</strong></td><td>Llama 3 70B</td></tr><tr><td>109B MoE</td><td><a href="https://huggingface.co/unsloth/cogito-v2-preview-llama-109B-MoE-GGUF">UD-Q3_K_XL</a></td><td><strong>50GB</strong></td><td>Llama 4 Scout</td></tr><tr><td>405B Dense</td><td><a href="https://huggingface.co/unsloth/cogito-v2-preview-llama-405B-GGUF">UD-Q2_K_XL</a></td><td><strong>152GB</strong></td><td>Llama 3 405B</td></tr><tr><td>671B MoE</td><td><a href="https://huggingface.co/unsloth/cogito-v2-preview-deepseek-671B-MoE-GGUF">UD-Q2_K_XL</a></td><td><strong>251GB</strong></td><td>DeepSeek R1</td></tr></tbody></table>

{% hint style="success" %}
虽然不是必须的，但为了获得最佳性能，请确保你的 VRAM + RAM 总和等于你下载的量化版本大小。如果你的 VRAM + RAM 更少，该量化版本仍然可以运行，只是会慢得多。
{% endhint %}

## 🐳 在 llama.cpp 中运行 Cogito 671B MoE

1. 获取最新的 `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 支持默认开启。

{% code overflow="wrap" %}

```shellscript
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
cp llama.cpp/build/bin/llama-* llama.cpp
```

{% endcode %}

2. 如果你想使用 `llama.cpp` 要直接加载模型，你可以使用下面的方法：（:IQ1\_S）是量化类型。你也可以通过 Hugging Face 下载（见第 3 点）。这类似于 `ollama run` 。使用 `export LLAMA_CACHE="folder"` 来强制 `llama.cpp` 用于保存到特定位置。

{% hint style="success" %}
请试试 `-ot ".ffn_.*_exps.=CPU"` 将所有 MoE 层卸载到 CPU！这实际上允许你将所有非 MoE 层放到 1 张 GPU 上，从而提高生成速度。如果你有更多 GPU 容量，可以自定义正则表达式以适配更多层。

如果你的 GPU 内存再多一些，尝试 `-ot ".ffn_(up|down)_exps.=CPU"` 这会卸载上、下投影 MoE 层。

再试试 `-ot ".ffn_(up)_exps.=CPU"` 如果你的 GPU 内存更多一些。这样只会卸载上投影 MoE 层。

最后通过以下方式卸载所有层： `-ot ".ffn_.*_exps.=CPU"` 这使用的 VRAM 最少。

你也可以自定义正则表达式，例如 `-ot "\.(6|7|8|9|[0-9][0-9]|[0-9][0-9][0-9])\.ffn_(gate|up|down)_exps.=CPU"` 表示从第 6 层开始卸载 gate、up 和 down MoE 层。
{% endhint %}

```shellscript
export LLAMA_CACHE="unsloth/cogito-671b-v2.1-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/cogito-671b-v2.1-GGUF:UD-Q2_K_XL \
    --n-gpu-layers 99 \\
    --temp 0.6 \\
    --top-p 0.95 \
    --min-p 0.01 \
    --ctx-size 16384 \
    --seed 3407 \
    --jinja \
    -ot ".ffn_.*_exps.=CPU"
```

3. 通过以下方式下载模型（在安装 `pip install huggingface_hub hf_transfer` 之后）。你可以选择 `UD-IQ1_S`（动态 1.78bit 量化）或其他量化版本，例如 `Q4_K_M` 。我们 <mark style="background-color:green;">**建议使用我们的 2.7bit 动态量化**</mark><mark style="background-color:green;">**&#x20;**</mark><mark style="background-color:green;">**`UD-Q2_K_XL`**</mark><mark style="background-color:green;">**&#x20;**</mark><mark style="background-color:green;">**以平衡大小和准确率**</mark>。更多版本见： <https://huggingface.co/unsloth/cogito-671b-v2.1-GGUF>

{% code overflow="wrap" %}

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0" # 有时会触发限流，因此设为 0 以禁用
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/cogito-671b-v2.1-GGUF",
    local_dir = "unsloth/cogito-671b-v2.1-GGUF",
    allow_patterns = ["*UD-IQ1_S*"], # 动态 1bit（168GB）动态 2bit（251GB）请使用 "*UD-Q2_K_XL*"
)
```

{% endcode %}

4. 编辑 `--threads 32` 来设置 CPU 线程数， `--ctx-size 16384` 来设置上下文长度， `--n-gpu-layers 2` 来设置 GPU 卸载多少层。如果你的 GPU 显存不足，请尝试调整它。如果你只进行 CPU 推理，也请移除它。

## :mouse\_three\_button:在 llama.cpp 中运行 Cogito 109B MoE

1. 按照与运行上面的 [671B 模型相同的说明](#run-cogito-671b-moe-in-llama.cpp).
2. 然后运行下面的命令：

```shellscript
export LLAMA_CACHE="unsloth/cogito-v2-preview-llama-109B-MoE-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:Q3_K_XL \
    --n-gpu-layers 99 \\
    --temp 0.6 \\
    --min-p 0.01 \
    --top-p 0.9 \
    --ctx-size 16384 \
    --jinja \
    -ot ".ffn_.*_exps.=CPU"
```

## :deciduous\_tree:在 llama.cpp 中运行 Cogito 405B Dense

1. 按照与运行上面的 [671B 模型相同的说明](#run-cogito-671b-moe-in-llama.cpp).
2. 然后运行下面的命令：

```shellscript
export LLAMA_CACHE="unsloth/cogito-v2-preview-llama-405B-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/cogito-v2-preview-llama-405B-GGUF:Q2_K_XL \
    --n-gpu-layers 99 \\
    --temp 0.6 \\
    --min-p 0.01 \
    --top-p 0.9 \
    --jinja \
    --ctx-size 16384
```

## :sunglasses: 在 llama.cpp 中运行 Cogito 70B Dense

1. 按照与运行上面的 [671B 模型相同的说明](#run-cogito-671b-moe-in-llama.cpp).
2. 然后运行下面的命令：

```shellscript
export LLAMA_CACHE="unsloth/cogito-v2-preview-llama-70B-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/cogito-v2-preview-llama-70B-GGUF:Q4_K_XL \
    --n-gpu-layers 99 \\
    --temp 0.6 \\
    --min-p 0.01 \
    --top-p 0.9 \
    --jinja \
    --ctx-size 16384
```

查看 <https://www.deepcogito.com/research/cogito-v2-1> 了解更多详情


---

# 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/tutorials/cogito-v2-how-to-run-locally.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.
