# 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 的 2 个 MoE 模型分别为 Llama 4 Scout（109B）和 DeepSeek R1（671B）

<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）合计等于您要下载的量化文件的大小。如果您的显存 + 内存较少，量化模型仍然可以运行，只是会慢得多。
{% 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 层放在一块 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
```

GLM 4.7 的工具调用 <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.
