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

# 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://unsloth.ai/docs/models/nemotron-3#fine-tuning-nemotron-3-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" : "1+1 等于多少？"},
    {"role" : "assistant", "content" : "2"},
    {"role" : "user", "content" : "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\n1+1 等于多少？<|im_end|>\n<|im_start|>assistant\n<think></think>2<|im_end|>\n<|im_start|>user\n2+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-de/studio.md)，这是我们用于本地 AI 的全新开源 Web UI。借助 Unsloth Studio，你可以在本地运行模型于 **MacOS、Windows**、Linux，以及：

{% columns %}
{% column %}

* 搜索、下载， [运行 GGUF](/docs/zh/xin-de/studio.md#run-models-locally) 以及 safetensor 模型
* [**自修复** 工具调用](/docs/zh/xin-de/studio.md#execute-code--heal-tool-calling) + **网页搜索**
* [**代码执行**](/docs/zh/xin-de/studio.md#run-models-locally) （Python、Bash）
* [自动推理](/docs/zh/xin-de/studio.md#model-arena) 参数调优（temp、top-p 等）
* 通过 llama.cpp 实现快速 CPU + GPU 推理
* [训练 LLM](/docs/zh/xin-de/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

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

然后前往 [Unsloth Chat](/docs/zh/xin-de/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-de/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
导入 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 的上下文窗口。将其设置为 100 万可能会触发 CUDA 内存不足并崩溃，这就是默认值为 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-de/studio.md)，这是我们用于运行和训练 LLM 的全新 Web UI。借助 Unsloth Studio，你可以在本地运行模型于 **Mac、Windows**和 Linux，并且可以：

{% columns %}
{% column %}

* 搜索、下载， [运行 GGUF](/docs/zh/xin-de/studio.md#run-models-locally) 以及 safetensor 模型
* **并排** 比较 **模型**
* [**自修复** 工具调用](/docs/zh/xin-de/studio.md#execute-code--heal-tool-calling) + **网页搜索**
* [**代码执行**](/docs/zh/xin-de/studio.md#run-models-locally) （Python、Bash）
* [自动推理](/docs/zh/xin-de/studio.md#model-arena) 参数调优（temp、top-p 等）
* [训练 LLM](/docs/zh/xin-de/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

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

然后前往 [Unsloth Chat](/docs/zh/xin-de/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-de/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-bit 以适配大多数设备）：

{% 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
导入 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 的上下文窗口。将其设置为 100 万可能会触发 CUDA 内存不足并崩溃，这就是默认值为 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 官方 Developer 博客上：**

#### [如何使用 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" %}

```
用户提出了一个简单问题：“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
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/nemotron-3.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.
