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

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

Cogito v2.1 LLM 是世界上最强的开源模型之一，使用 IDA 训练。v1 还提供 4 种尺寸：70B、109B、405B 和 671B，让你可以选择最适合自己硬件的大小。

{% 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-zhi-shi/dynamic-3.0-ggufs.md) 用于获得最先进的 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. 2 个基于 Llama 的 Dense 模型——70B 和 405B
2. 2 个基于 Llama 4 Scout（109B）和 DeepSeek R1（671B）的 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.7 位动态量化**</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
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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/zh/mo-xing/tutorials/cogito-v2-how-to-run-locally.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
