> 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/ji-chu-zhi-shi/nvfp4.md).

# Unsloth Dynamic NVFP4 运行指南

了解 Unsloth Dynamic NVFP4 如何在 NVIDIA Blackwell GPU 上实现快速、准确的 4 位推理。

Unsloth Dynamic NVFP4 是一种量化模型格式，运行于 NVIDIA Blackwell GPU，旨在实现更快、更准确的 4 位推理。它结合了 NVIDIA 原生 NVFP4 精度与 [Unsloth Dynamic 2.0](/docs/zh/ji-chu-zhi-shi/dynamic-3.0-ggufs.md) 量化，以在减少 VRAM 占用并提升速度的同时保持模型准确性。本指南解释 FP4 量化，对比 NVFP4 与其他格式，并展示如何运行像 [Qwen3.8](/docs/zh/mo-xing/qwen3.8.md), [Gemma 4](/docs/zh/mo-xing/gemma-4.md) 和 [Qwen3.6](/docs/zh/mo-xing/qwen3.6.md) 的模型，可在 RTX 5050-5090、B200、RTX PRO 6000 以及更多 GPU 上使用 vLLM 或 SGLang 在本地运行。

Dynamic NVFP4 的工作方式是选择重要层保持 FP8（W8A8）或 BF16，而其余层使用 W4A4（而不是 W4A16），而不是强制所有层都进入 FP4。这使得最高可达 **推理速度提升 2.5 倍** 因为 W4A4 充分利用了 Blackwell GPU 的 FP4 张量核心。对于所有量化版本，我们还提供 FP8 KV cache 校准，从而实现 **上下文长度延长 2 倍**.

{% hint style="success" %}
**8 月 14 日：** [**Qwen3.8-27B**](/docs/zh/mo-xing/qwen3.8.md) **现已上线，并附带我们的 NVFP4 量化版本。**

**所有** [**Gemma 4**](#gemma-4) **模型现已作为 Unsloth Dynamic NVFP4 量化版本提供：** E2B、E4B、12B Unified、26B-A4B MoE 和 31B Dense。

查看 [Unsloth Dynamic NVFP4 集合](https://huggingface.co/collections/unsloth/nvfp4) 以获取我们所有模型的上传版本。
{% endhint %}

### Float4 与其他精度对比

秘诀在于 **更快的 GPU 的关键是降低矩阵乘法的数值精度**。矩阵乘法单元所需的晶体管数量与 **尾数的平方**有关。尾数决定数字可以拥有多少个“小数”位——因此位数越多，就越能准确表示小数。例如，要表示 0.121332，需要更多尾数位；而尾数位较少时，会将其四舍五入为 0.1。

{% columns %}
{% column width="50%" %}
FP32 有 23 个尾数位，因此需要 23^2+ 8 个指数位 = 537 的空间。Bfloat16 有 7 个尾数位，因此需要 7^2 + 8 个指数位 = 57 的空间。这意味着 bfloat16 所需空间比 FP32 少约 9 倍！而当我们转向只有 3 个尾数位的 float8 时，则为 3^2 + 4 个指数位 = 13——这比 FP32 少 41 倍的空间！

最后，float4 有 1 个尾数位和 2 个指数位，因此只需 3 的空间——比 FP32 少了惊人的 179 倍——这实际上意味着一台 **GPU 在相同空间内大约可以进行 179 倍更多的 FP4 矩阵乘法，而不是 FP32 乘法 FLOPs**!
{% endcolumn %}

{% column width="50%" %}
![](https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FJQlcQbDGgw5qbkltc7jr%2Funknown.png?alt=media\&token=75d1ec98-3fa5-4b5a-b51a-5577ac5a96ca)
{% endcolumn %}
{% endcolumns %}

### NVFP4 与 MXFP4

<div><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FRDyKe2OmFRK0tDbrrnMb%2Fimage.png?alt=media&amp;token=affd39c0-11e9-458f-982f-181ebc327b82" alt=""><figcaption></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fj2COTZX8rNX5un1JeaNU%2Fimage.png?alt=media&amp;token=9b5749d8-9e0e-4f04-8022-90379e9d544c" alt=""><figcaption></figcaption></figure></div>

还有另一种 FP4 格式叫 MXFP4——由于以下两点，它不如 NVFP4 精确：

1. NVFP4 使用 16 的块大小，而 MXFP4 为 32——这使得异常值更容易被隔离，并且为更小的权重子集提供缩放因子，从而提高准确性
2. 每个块使用的是 E4M3（FP8）缩放，而不是 E8M0（2 的幂缩放）。使用 FP8 类型的块大小似乎要好得多，尤其是对 LLM 而言。

### 性能分析

我们的新 动态 NVFP4 Qwen3.6 量化版本运行速度约为**快 2.5 倍** 相比其他 NVFP4 量化版本，且 **更好的性能** 文件大小也相当。运行 Qwen3.6-27B NVFP4 **快 2.5 倍** 在 **24GB VRAM** 以及 Qwen3.6-35B-A3B **快 1.7 倍** 在 **32GB VRAM**。我们还新增了 **FP8 KV 缓存校准** 以实现 2 倍更长的上下文长度！NVFP4 需要 NVIDIA 的 Blackwell GPU，例如 RTX 50X、DGX Spark（见 [#dgx-spark-with-nvfp4-quants](#dgx-spark-with-nvfp4-quants "mention")）以及 B200、B300 GPU。对于较旧的 GPU，我们的 GGUF 版本也表现良好！

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F8zM7cg0Xgo2pAlop1iPW%2F01_qwen36_combined_throughput.png?alt=media&amp;token=23131a96-4c41-42d7-aa16-5bfb21bb44a3" alt="" width="563"><figcaption></figcaption></figure>

所有基准均使用 1x B200、128 并发。更高的并发可将 35B 提升至 17,561 tokens/s。我们还刚刚发布了新的 [Qwen3.8](/docs/zh/mo-xing/qwen3.8.md) NVFP4 量化版本：

* [Qwen3.8-27B NVFP4](https://huggingface.co/unsloth/Qwen3.8-27B-NVFP4) （新版）

我们还将发布两个 35B-A3B NVFP4 版本：

* [Qwen3.6-35B-A3B-NVFP4-Fast](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-NVFP4-Fast) 这是一个完整的 W4A4 量化版本——快 1.79 倍
* [Qwen3.6-35B-A3B-NVFP4](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-NVFP4) 它稍大一些，但更准确，且快 1.56 倍

在准确率基准测试中，我们对 FP8、BF16、NVIDIA 的 NVFP4 以及我们的 NVFP4 进行了 MMLU-Pro、AIME 2025、GPQA 测试——我们展示了我们的更快量化版本在所有测试中的表现都相近：

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FFhOUUUlRBj3dafGnmvhK%2F03_qwen36_combined_accuracy(7).png?alt=media&amp;token=9178447f-d5ae-4489-9bdc-73b2b7b1631b" alt=""><figcaption></figcaption></figure>

| Qwen3.8-27B（新版）                                                            |
| -------------------------------------------------------------------------- |
| [Qwen3.8-27B NVFP4](https://huggingface.co/unsloth/Qwen3.8-27B-NVFP4) （新版） |

<table><thead><tr><th width="372.5999755859375">Qwen3.6-35B-A3B</th><th>Qwen3.6-27B</th></tr></thead><tbody><tr><td><a href="https://huggingface.co/unsloth/Qwen3.6-35B-A3B-NVFP4">Qwen3.6-35B-A3B-NVFP4</a> （快 1.56 倍）</td><td><a href="https://huggingface.co/unsloth/Qwen3.6-27B-NVFP4">Qwen3.6-27B-NVFP4</a> （快 2.5 倍）</td></tr><tr><td><a href="https://huggingface.co/unsloth/Qwen3.6-35B-A3B-NVFP4-Fast">Qwen3.6-35B-A3B-NVFP4-Fast</a> （快 1.79 倍）</td><td></td></tr></tbody></table>

**MTP 张量也直接内置在量化版本中，以进一步提速。** 准确性提升来自对 Qwen3.6 聊天模板和数据集校准的改进。我们使用之前对聊天模板的更新来帮助提升代码与工具调用的一致性，同时减少循环以及其他已报告的问题。我们的校准使用了针对代码、工具调用和聊天优化的数据集，并结合了 UltraChat。

在解码速度（每人 tokens）方面，我们在 27B 上快 1.03 倍，而 35B 上分别快 1.17 倍和 1.22 倍。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FR3X2O3iOBhjMS1ekX7zO%2F03_qwen36_combined_decode.png?alt=media&amp;token=a8b34056-7178-4e0d-851b-9467fa0ba2f6" alt="" width="563"><figcaption></figcaption></figure>

### 概览

以下是你可以使用的模型所需硬件要求，包括 Gemma 4 和 Qwen3.6。另请查看你将获得的整体速度提升：

#### Gemma 4：

| Gemma 4 变体                                                         | 所需 VRAM | 比 BF16 更快 |
| ------------------------------------------------------------------ | ------: | --------: |
| [E2B](https://huggingface.co/unsloth/gemma-4-E2B-it-NVFP4)         |    7 GB |  快 1.12 倍 |
| [E4B](https://huggingface.co/unsloth/gemma-4-E4B-it-NVFP4)         |    9 GB |  快 1.22 倍 |
| [12B Unified](https://huggingface.co/unsloth/gemma-4-12b-it-NVFP4) |   11 GB |  快 1.26 倍 |
| [26B A4B](https://huggingface.co/unsloth/gemma-4-26B-A4B-it-NVFP4) |   26 GB |  快 1.41 倍 |
| [31B](https://huggingface.co/unsloth/gemma-4-31B-it-NVFP4)         |   32 GB |  快 1.45 倍 |

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FZw91MhTauyOZGP5HT7bl%2Fimage.png?alt=media&amp;token=ae0051a9-af39-4ef7-8ed2-9f8c1fff33fc" alt="" width="563"><figcaption></figcaption></figure>

#### Qwen3.6：

| Qwen3.6 变体                                                                | 所需 VRAM | 比其他 NVFP4 量化版本更快 |
| ------------------------------------------------------------------------- | ------: | ---------------: |
| [27B](https://huggingface.co/unsloth/Qwen3.6-27B-NVFP4)                   |   24 GB |          快 2.5 倍 |
| [35B A3B](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-NVFP4)           |   32 GB |         快 1.56 倍 |
| [35B A3B Fast](https://huggingface.co/unsloth/Qwen3.6-35B-A3B-NVFP4-Fast) |   32 GB |         快 1.79 倍 |

### NVFP4 基准测试

NVFP4 直接在 Blackwell Tensor Cores 上运行 4 位权重和矩阵乘法。我们的 Qwen3.6 NVFP4 量化版本使用 W4A4，因此它们实际上使用 FP4 张量核心，所以解码速度比 NVIDIA 的 W4A16 更快。我们还动态量化各层以保持准确性，并对所有量化版本进行了 MMLU-Pro、AIME 2025、GPQA 测试，同时与 FP8 和 BF16 进行了比较。

**Qwen3.6-27B NVFP4 准确率基准**

| 提供方     | MMLU-Pro |  GPQA | AIME 2025 |
| ------- | -------: | ----: | --------: |
| Unsloth |    86.25 | 86.34 |     93.12 |
| NVIDIA  |    85.96 | 86.87 |     93.12 |
| FP8     |    86.11 | 86.87 |     93.75 |
| BF16    |    85.96 | 88.13 |     93.33 |

**Qwen3.6-35B-A3B NVFP4 准确率基准**

| 提供方              | MMLU-Pro |  GPQA | AIME 2025 |
| ---------------- | -------: | ----: | --------: |
| Unsloth          |    85.85 | 86.74 |     92.29 |
| **Unsloth Fast** |    85.58 | 87.75 |     91.67 |
| NVIDIA           |    85.60 | 87.12 |     91.88 |
| FP8              |    85.75 | 86.74 |     93.12 |
| BF16             |    85.75 | 86.36 |     92.50 |

我们也检查了所有基准的输出长度，它们都可比，因此新的 NVFP4 量化版本不会因为“思考”更久而抵消量化的目的！（也就是说，如果快 2 倍，但思考也多 2 倍，那就毫无意义）

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FjG1C3y6GVWvnorRfmnIF%2Fqwen36_combined_output_length_reordered_estimated_no_footnote.png?alt=media&amp;token=2aa2d784-c082-476e-895a-4bea77385956" alt=""><figcaption></figcaption></figure>

## **运行 NVFP4 教程**

要运行 NVFP4 量化版本，请参见下方命令，以在 Qwen3.6-27B [vLLM](/docs/zh/ji-chu-zhi-shi/inference-and-deployment/vllm-guide.md) 和 [SGLang](/docs/zh/ji-chu-zhi-shi/inference-and-deployment/sglang-guide.md) （你可以将模型名称更改为 `Qwen3.6-35-A3B-NVFP4`).&#x20;

### **vLLM 教程**

你可以在 [vLLM](https://github.com/vllm-project/vllm)。不要选择任何 MoE 后端——让 vLLM 自行选择——例如 Marlin 会慢 2.5 倍！参见 [#marlin-vs-flashinfer-vs-cutlass-vs-cute-dsl](#marlin-vs-flashinfer-vs-cutlass-vs-cute-dsl "mention")如果你有 DGX Spark，请参见 [#dgx-spark-serving](#dgx-spark-serving "mention") 你必须使用 `--moe-backend flashinfer_b12x` 否则推理会慢得多。

要在独立的 venv 中安装 vLLM：

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

```bash
uv venv unsloth-nvfp4-env --python 3.13
source unsloth-nvfp4-env/bin/activate
uv pip install "vllm>=0.25.0" "flashinfer-python>=0.6.13" "nvidia-cutlass-dsl>=4.5.2" \\
    --torch-backend=auto
```

{% endcode %}

然后，要提供 35B Fast 版本：

```shell
vllm serve unsloth/Qwen3.6-35B-A3B-NVFP4-Fast
```

将 `unsloth/Qwen3.6-35B-A3B-NVFP4-Fast` 到 NVFP4 量化名称中！

要启用 MTP / speculative decoding（解码更快，但吞吐量会略低），请使用：

```bash
vllm serve unsloth/Qwen3.6-35B-A3B-NVFP4-Fast
    --speculative-config '{"method": "mtp", "num_speculative_tokens": 2}'
```

如果你遇到 Torchcodec 问题，请务必先执行以下操作，然后重新启动 vllm。

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

```bash
sudo apt-get update
sudo apt-get install -y ffmpeg
```

{% endcode %}

### **DGX Spark 教程**

为确保 DGX Spark 具有正确的内核（否则你会得到 **推理速度慢 2 倍**），请先检查：

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

```bash
python -c "
import torch; from vllm.utils.flashinfer import has_flashinfer_b12x_gemm as g, has_flashinfer_b12x_moe as m
cap = torch.cuda.get_device_capability(); print('cap', cap, '| b12x gemm', g(), '| b12x moe', m()); assert cap[0] == 12 and g() and m(), 'b12x 不可用：服务将降级为 marlin W4A16'"
```

{% endcode %}

这段代码不应该报错——如果报错了，请更新 vllm 或通过以下方式重新安装：

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

```bash
uv venv unsloth-nvfp4-env --python 3.13
source unsloth-nvfp4-env/bin/activate
uv pip install "vllm>=0.25.0" "flashinfer-python>=0.6.13" "nvidia-cutlass-dsl>=4.5.2" \\
    --torch-backend=auto
```

{% endcode %}

然后，要在 vLLM 中为 DGX Spark 提供服务：

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

```shellscript
export CUTE_DSL_ARCH=sm_121a
vllm serve unsloth/Qwen3.6-35B-A3B-NVFP4-Fast --moe-backend flashinfer_b12x
```

{% endcode %}

如果你遇到 Torchcodec 问题，请务必先执行以下操作，然后重新启动 vllm。

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

```bash
sudo apt-get update
sudo apt-get install -y ffmpeg
```

{% endcode %}

### **SGLang 教程：**

你可以在 [SGLang](https://github.com/sgl-project/sglang)。记得把模型名称替换成你想要的模型。

**Qwen3.6：**

```bash
python -m sglang.launch_server --model-path unsloth/Qwen3.6-27B-NVFP4 --speculative-algorithm NEXTN \\
     --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4
```

**Gemma 4：**

```bash
python -m sglang.launch_server --model-path unsloth/Gemma-4-31B-NVFP4 --speculative-algorithm NEXTN \\
     --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4
```

### Gemma 4 及其他

每个 Gemma 4 变体现在都有一个 Unsloth Dynamic NVFP4 检查点。

我们显示，在 1x B200 上以 128 并发服务时，Gemma-4 的吞吐提升最高可达 1.44 倍，相比 BF16。Qwen3.5-122B-A10B 快 1.38 倍，GLM-4.7-Flash 快 1.27 倍。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F40mWjyryioZIww8kxH61%2F02_throughput_nvfp4_vs_bf16.png?alt=media&amp;token=330f88e8-00d4-4573-8f79-24bd9886f2f9" alt=""><figcaption></figcaption></figure>

### Marlin、Flashinfer、cutlass 与 cute-DSL 对比

我们还发现 Marlin 内核对 W4A4 的支持不佳——启用它会导致 2.5 倍的性能下降——因此请使用 CUTLASS、Flashinfer-TRTLLM 或 Cute-DSL（在 vLLM 中自动启用）！另外，如果你有 DGX Spark，请参见 [#dgx-spark-serving](#dgx-spark-serving "mention") 你必须使用 `--moe-backend flashinfer_b12x` 否则你会得到快 2.5 倍的慢推理。

**所以不要设置任何后端——vLLM 会自动选择最佳后端。**

| 模型              | 方案    | 后端                 | 解码 tok/s | 吞吐 tok/s   |
| --------------- | ----- | ------------------ | -------- | ---------- |
| NVIDIA 27B      | W4A16 | marlin（自动）         | 115.6    | 2,403      |
| Unsloth 27B     | W4A4  | marlin             | 105.6    | 2,127      |
| Unsloth 27B     | W4A4  | cutlass            | 113.5    | 6,681      |
| Unsloth 27B     | W4A4  | flashinfer\_trtllm | 112.6    | 6,158      |
| Unsloth 27B     | W4A4  | **cute-DSL（自动）**   | 125.9    | **6,863**  |
| NVIDIA 35B-A3B  | W4A4  | marlin（自动）         | 240.8    | 8,721      |
| Unsloth 35B-A3B | W4A4  | marlin             | 215.8    | 8,619      |
| Unsloth 35B-A3B | W4A4  | cutlass            | 158.3    | 11,017     |
| Unsloth 35B-A3B | W4A4  | **cute-DSL（自动）**   | 295.2    | **15,636** |


---

# 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/ji-chu-zhi-shi/nvfp4.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.
