# NVIDIA Nemotron 3 Nano - 如何运行指南

NVIDIA 发布 **Nemotron-3-Nano-4B**，一个 4B 开放混合 MoE 模型，遵循 [Nemotron-3-Super-120B-A12B](/docs/zh/mo-xing/nemotron-3/nemotron-3-super.md) 和 Nemotron-3-Nano-30B-A3B。Nemotron 家族专为快速、准确的编程、数学和智能体工作负载而设计。它们具有 **100万 token 上下文** 窗口，并且在推理、聊天和吞吐量基准测试中都具有竞争力。

Nemotron-3-Nano-4B 可在以下配置上运行： **5GB** 的 RAM、VRAM 或统一内存。Nemotron-3-Nano-30A3B 可在以下配置上运行： **24GB** RAM。现在可以通过以下方式在本地对 Nemotron 3 进行微调： [Unsloth](https://github.com/unslothai/unsloth)。感谢 NVIDIA 为 Unsloth 提供首日支持。

<a href="/pages/744e7d433d981b3fd86d1a7ad5e4f1d406c1c0eb#run-nemotron-3-nano-4b" class="button primary">Nemotron-3-Nano-4B</a><a href="/pages/744e7d433d981b3fd86d1a7ad5e4f1d406c1c0eb#run-nemotron-3-nano-30b-a3b" class="button primary">Nemotron-3-Nano-30B-A3B</a><a href="https://docs.unsloth.ai/models/nemotron-3#fine-tuning-nemotron-3-nano-and-rl" class="button secondary">Nemotron 3 微调</a>

| [Nemotron-3-Nano-**4B**-GGUF](https://huggingface.co/unsloth/NVIDIA-Nemotron-3-Nano-4B-GGUF) | [Nemotron-3-**Nano-30B-A3B**-GGUF](https://huggingface.co/unsloth/Nemotron-3-Nano-30B-A3B-GGUF) |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |

### ⚙️ 使用指南

NVIDIA 建议在推理中使用以下设置：

{% columns %}
{% column %}
**通用聊天/指令（默认）：**

* `temperature = 1.0`
* `top_p = 1.0`
  {% endcolumn %}

{% column %}
**工具调用用例：**

* `temperature = 0.6`
* `top_p = 0.95`
  {% endcolumn %}
  {% endcolumns %}

**对于大多数本地使用场景，请设置：**

* `max_new_tokens` = `32,768` 改为 `262,144` 用于最多 100 万 token 的标准提示
* 随着你的 RAM/VRAM 允许，可增加该值以进行深度推理或长文本生成。

聊天模板格式可通过使用下面内容找到：

{% code overflow="wrap" %}

```python
tokenizer.apply_chat_template([
    {"role" : "user", "content" : "What is 1+1?"},
    {"role" : "assistant", "content" : "2"},
    {"role" : "user", "content" : "What is 2+2?"}
    ], add_generation_prompt = True, tokenize = False,
)
```

{% endcode %}

{% hint style="success" %}
由于该模型使用 NoPE 训练，你只需要更改 `max_position_embeddings`。该模型不使用显式位置嵌入，因此不需要 YaRN。
{% endhint %}

#### Nemotron 3 聊天模板格式：

{% hint style="info" %}
Nemotron 3 使用 `<think>` ，token ID 为 12；并使用 `</think>` ，token ID 为 13，用于推理。使用 `--special` 查看 llama.cpp 的 token。你可能还需要 `--verbose-prompt` 以查看 `<think>` ，因为它是预先添加的。
{% endhint %}

{% code overflow="wrap" lineNumbers="true" %}

```
<|im_start|>system\n<|im_end|>\n<|im_start|>user\nWhat is 1+1?<|im_end|>\n<|im_start|>assistant\n<think></think>2<|im_end|>\n<|im_start|>user\nWhat is 2+2?<|im_end|>\n<|im_start|>assistant\n<think>\n
```

{% endcode %}

## 🖥️ 运行 Nemotron-3-Nano-4B

根据你的用例，你需要使用不同的设置。一些 GGUF 之所以最终大小相近，是因为模型架构（例如 [gpt-oss](/docs/zh/mo-xing/gpt-oss-how-to-run-and-fine-tune.md)）的维度不能被 128 整除，因此部分内容无法量化到更低位宽。

该模型的 4 位版本需要约 3GB RAM。8 位版本需要 5GB。

### 🦥 Unsloth Studio 指南

Nemotron 3 可以在以下环境中运行和微调： [Unsloth Studio](/docs/zh/xin/studio.md)，我们新的用于本地 AI 的开源网页界面。使用 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）
* [自动推理](/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
```

{% endstep %}

{% step %}

#### 启动 Unsloth

**MacOS、Linux、WSL、Windows：**

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

<div data-with-frame="true"><figure><img src="/files/7fd4b2ed7fb55df6d31b4dd1ce1181d57613709b" alt="" width="375"><figcaption></figcaption></figure></div>

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

{% step %}

#### 搜索并下载 Nemotron-3-Nano-4B

首次启动时，你需要创建密码以保护你的账户，并可在稍后重新登录。随后你会看到一个简短的引导向导，用于选择模型、数据集和基本设置。你可以随时跳过。

然后前往 [Studio Chat](/docs/zh/xin/studio/chat.md) 选项卡，在搜索栏中搜索 Nemotron-3-Nano-4B，并下载你想要的模型和量化版本。

<div data-with-frame="true"><figure><img src="/files/17795aa11a068d2ca7a0c6bec4b176c4ee039538" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### 运行 Nemotron-3-Nano-4B

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

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

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

### Llama.cpp 教程：

在 llama.cpp 中运行的说明（我们将使用 8 位以接近全精度）：

{% stepper %}
{% step %}
获取最新的 `llama.cpp` 在 [GitHub 这里](https://github.com/ggml-org/llama.cpp)。你也可以按照下面的构建说明操作。将 `-DGGML_CUDA=ON` 改为 `-DGGML_CUDA=OFF` 如果你没有 GPU，或者只想进行 CPU 推理。

{% code overflow="wrap" %}

```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
```

{% endcode %}
{% endstep %}

{% step %}
你可以直接从 Hugging Face 拉取。随着你的 RAM/VRAM 允许，可以将上下文增加到 100 万。

以下内容适用于 **通用指令** 用例：

```bash
./llama.cpp/llama-cli \
    -hf unsloth/NVIDIA-Nemotron-3-Nano-4B-GGUF:Q8_0 \\
    --ctx-size 16384 \
    --temp 1.0 --top-p 1.0
```

以下内容适用于 **工具调用** 用例：

```bash
./llama.cpp/llama-cli \
    -hf unsloth/NVIDIA-Nemotron-3-Nano-4B-GGUF:Q8_0 \\
    --ctx-size 32768 \\
    --temp 0.6 --top-p 0.95
```

{% endstep %}

{% step %}
通过以下方式下载模型（在安装 `pip install huggingface_hub hf_transfer` 之后）。你可以选择 `Q8_0` 或其他量化版本。

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/NVIDIA-Nemotron-3-Nano-4B-GGUF",
    local_dir = "unsloth/NVIDIA-Nemotron-3-Nano-4B-GGUF",
    allow_patterns = ["*Q8_0*"],
)
```

{% endstep %}

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

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/NVIDIA-Nemotron-3-Nano-4B-GGUF/NVIDIA-Nemotron-3-Nano-4B-Q8_0.gguf \\
    --ctx-size 16384 \
    --seed 3407 \
    --prio 2 \
    --temp 0.6 \\
    --top-p 0.95
```

{% endcode %}

另外，请按需调整 **上下文窗口** 。确保你的硬件能够处理大于 256K 的上下文窗口。将其设置为 1M 可能会触发 CUDA OOM 并导致崩溃，因此默认值为 262,144。
{% endstep %}
{% endstepper %}

## 🖥️ 运行 Nemotron-3-Nano-30B-A3B

根据你的用例，你需要使用不同的设置。一些 GGUF 之所以最终大小相近，是因为模型架构（例如 [gpt-oss](/docs/zh/mo-xing/gpt-oss-how-to-run-and-fine-tune.md)）的维度不能被 128 整除，因此部分内容无法量化到更低位宽。

该模型的 4 位版本需要约 24GB RAM。8 位版本需要 36GB。

### 🦥 Unsloth Studio 指南

在本教程中，我们将使用 [Unsloth Studio](/docs/zh/xin/studio.md)，这是我们用于运行和训练 LLM 的新网页界面。使用 Unsloth Studio，你可以在以下平台本地运行模型： **Mac、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）
* [自动推理](/docs/zh/xin/studio.md#model-arena) 参数调优（temp、top-p 等）
* [训练 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
```

{% endstep %}

{% step %}

#### 设置 Unsloth Studio（仅需一次）

设置过程会自动安装 Node.js（通过 nvm）、构建前端、安装所有 Python 依赖，并构建带 CUDA 支持的 llama.cpp。

{% hint style="info" %}
**WSL 用户：** 系统会提示你输入 `sudo` 密码以安装构建依赖（`cmake`, `git`, `libcurl4-openssl-dev`).
{% endhint %}
{% endstep %}

{% step %}

#### 启动 Unsloth

**MacOS、Linux、WSL：**

```bash
source unsloth_studio/bin/activate
unsloth studio -H 0.0.0.0 -p 8888
```

**Windows PowerShell：**

```bash
& .\unsloth_studio\Scripts\unsloth.exe studio -H 0.0.0.0 -p 8888
```

<div data-with-frame="true"><figure><img src="/files/7fd4b2ed7fb55df6d31b4dd1ce1181d57613709b" alt="" width="375"><figcaption></figcaption></figure></div>

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

{% step %}

#### 搜索并下载 Nemotron-3-Nano-30B-A3B

首次启动时，你需要创建密码以保护你的账户，并可在稍后重新登录。随后你会看到一个简短的引导向导，用于选择模型、数据集和基本设置。你可以随时跳过。

然后前往 [Studio Chat](/docs/zh/xin/studio/chat.md) 选项卡，在搜索栏中搜索 Nemotron-3-Nano-4B，并下载你想要的模型和量化版本。

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

{% step %}

#### 运行 Nemotron-3-Nano-30B-A3B

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

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

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

### Llama.cpp 教程：

在 llama.cpp 中运行的说明（注意我们将使用 4 位以适配大多数设备）：

{% 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 支持默认开启。

{% code overflow="wrap" %}

```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 -DLLAMA_CURL=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
```

{% endcode %}
{% endstep %}

{% step %}
你可以直接从 Hugging Face 拉取。随着你的 RAM/VRAM 允许，可以将上下文增加到 100 万。

以下内容适用于 **通用指令** 用例：

```bash
./llama.cpp/llama-cli \
    -hf unsloth/Nemotron-3-Nano-30B-A3B-GGUF:UD-Q4_K_XL \\
    --ctx-size 32768 \\
    --temp 1.0 --top-p 1.0
```

以下内容适用于 **工具调用** 用例：

```bash
./llama.cpp/llama-cli \
    -hf unsloth/Nemotron-3-Nano-30B-A3B-GGUF:UD-Q4_K_XL \\
    --ctx-size 32768 \\
    --temp 0.6 --top-p 0.95
```

{% endstep %}

{% step %}
通过以下方式下载模型（在安装 `pip install huggingface_hub hf_transfer` 之后）。你可以选择 `UD-Q4_K_XL` 或其他量化版本。

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/Nemotron-3-Nano-30B-A3B-GGUF",
    local_dir = "unsloth/Nemotron-3-Nano-30B-A3B-GGUF",
    allow_patterns = ["*UD-Q4_K_XL*"],
)
```

{% endstep %}

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

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Nemotron-3-Nano-30B-A3B-GGUF/Nemotron-3-Nano-30B-A3B-UD-Q4_K_XL.gguf \\
    --ctx-size 16384 \
    --seed 3407 \
    --prio 2 \
    --temp 0.6 \\
    --top-p 0.95
```

{% endcode %}

另外，请按需调整 **上下文窗口** 。确保你的硬件能够处理大于 256K 的上下文窗口。将其设置为 1M 可能会触发 CUDA OOM 并导致崩溃，因此默认值为 262,144。

{% hint style="info" %}
Nemotron 3 使用 `<think>` ，token ID 为 12；并使用 `</think>` ，token ID 为 13，用于推理。使用 `--special` 查看 llama.cpp 的 token。你可能还需要 `--verbose-prompt` 以查看 `<think>` ，因为它是预先添加的。
{% endhint %}
{% endstep %}
{% endstepper %}

### 🦥 Nemotron 3 和 RL 微调

Unsloth 现在支持所有 Nemotron 模型的微调，包括 Nemotron 3 Super 和 Nano。&#x20;

4B 模型可以放在免费的 Colab GPU 上运行，但 30B 模型放不下。我们仍然为你准备了一个 80GB A100 Colab 笔记本来进行微调。Nemotron 3 Nano 的 16 位 LoRA 微调将使用大约 **60GB VRAM**:

* [Nemotron-3-Nano-30B-A3B SFT LoRA 笔记本](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Nemotron-3-Nano-30B-A3B_A100.ipynb)

{% embed url="<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Nemotron-3-Nano-30B-A3B_A100.ipynb>" %}

关于 MoE 的微调——微调路由层可能不是个好主意，所以我们默认将其禁用。如果你想保留其推理能力（可选），可以使用直接答案和思维链示例的混合。数据集中至少使用 <mark style="background-color:green;">75% 推理</mark> 和 <mark style="background-color:green;">25% 非推理</mark> ，以让模型保留其推理能力。

#### :sparkles:强化学习 + NeMo Gym

我们与开源的 NVIDIA [NeMo Gym](https://github.com/NVIDIA-NeMo/Gym/pull/492) 团队合作，以促进 RL 环境的普及。我们的协作使得可以在许多感兴趣的领域进行单轮 rollout RL 训练，包括数学、编程、工具使用等，使用来自 NeMo Gym 的训练环境和数据集：

{% columns %}
{% column %}
[NeMo Gym 数独强化学习笔记本](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/nemo_gym_sudoku.ipynb)

{% embed url="<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/NeMo-Gym-Sudoku.ipynb>" %}
{% endcolumn %}

{% column %}
[NeMo Gym 多环境强化学习笔记本](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/NeMo-Gym-Multi-Environment.ipynb)

{% embed url="<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/NeMo-Gym-Multi-Environment.ipynb>" %}
{% endcolumn %}
{% endcolumns %}

{% hint style="success" %}
**另外，也请查看我们最新的协作指南，该指南发布在 NVIDIA 官方开发者博客上：**

#### [如何使用 Unsloth 在 NVIDIA GPU 上微调 LLM](https://blogs.nvidia.com/blog/rtx-ai-garage-fine-tuning-unsloth-dgx-spark/)

{% endhint %}

{% embed url="<https://blogs.nvidia.com/blog/rtx-ai-garage-fine-tuning-unsloth-dgx-spark/>" %}

### 🦙Llama-server 服务与部署

要将 Nemotron 3 部署到生产环境，我们使用 `llama-server` 在一个新终端中，例如通过 tmux，按以下方式部署模型：

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-server \
    --model unsloth/Nemotron-3-Nano-30B-A3B-GGUF/Nemotron-3-Nano-30B-A3B-UD-Q4_K_XL.gguf \\
    --alias "unsloth/Nemotron-3-Nano-30B-A3B" \\
    --prio 3 \
    --min-p 0.01 \
    --temp 0.6 \\
    --top-p 0.95 \
    --ctx-size 16384 \
    --port 8001
```

{% endcode %}

当你运行上面的命令时，你会得到：

<figure><img src="/files/5c29fcc3934d727ff13bf53e411192fcba2197bb" alt="" width="563"><figcaption></figcaption></figure>

然后在一个新终端中，在执行 `pip install openai`之后，执行：

{% code overflow="wrap" %}

```python
from openai import OpenAI
import json
openai_client = OpenAI(
    base_url = "http://127.0.0.1:8001/v1",
    api_key = "sk-no-key-required",
)
completion = openai_client.chat.completions.create(
    model = "unsloth/Nemotron-3-Nano-30B-A3B",
    messages = [{"role": "user", "content": "2+2 等于多少？"},],
)
print(completion.choices[0].message.content)
```

{% endcode %}

这将打印

{% code overflow="wrap" %}

```
用户问了一个简单问题：“What is 2+2?” 答案是 4。请提供答案。

2 + 2 = 4.
```

{% endcode %}

### 基准测试

Nemotron-3-Nano-4B 是在其体量范围内表现最好的模型，包括吞吐量。

<figure><img src="/files/0a440bb84e57fd70c33b16c45fcc39dc7d1119ec" alt="" width="375"><figcaption></figcaption></figure>

Nemotron-3-Nano-30B-A3B 是在所有基准测试中表现最好的模型，包括吞吐量。

<figure><img src="/files/f51c693c7b76cdf6c66f517920737646717a477e" alt=""><figcaption></figcaption></figure>


---

# 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/nemotron-3.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.
