> 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/qwen3-how-to-run-and-fine-tune/qwen3-2507.md).

# Qwen3-2507：本地运行指南

在你的设备上本地运行 Qwen3-30B-A3B-2507 和 235B-A22B 的 Thinking 与 Instruct 版本！

Qwen 发布了其 2507（2025年7月）更新，适用于 [Qwen3](/docs/zh/mo-xing/tutorials/qwen3-how-to-run-and-fine-tune.md) 4B、30B 和 235B 模型，并引入了“思考”和“非思考”两个变体。非思考型‘**Qwen3-30B-A3B-Instruct-2507**”和“**Qwen3-235B-A22B-Instruct-2507'** 具有 256K 上下文窗口、改进的指令遵循能力、多语言能力和对齐能力。

思考型模型‘**Qwen3-30B-A3B-Thinking-2507**”和“**Qwen3-235B-A22B-Thinking-2507**’在推理方面表现出色，其中 235B 在逻辑、数学、科学、编程和高级学术任务上取得了 SOTA 结果。

[Unsloth](https://github.com/unslothai/unsloth) 现在还支持微调和 [强化学习（RL）](/docs/zh/kuai-su-kai-shi/reinforcement-learning-rl-guide.md) Qwen3-2507 模型的——速度提升 2 倍，显存占用减少 70%，上下文长度延长 8 倍

<a href="#run-qwen3-30b-a3b-2507-tutorials" class="button secondary">运行 30B-A3B</a><a href="/docs/zh/mo-xing/tutorials/qwen3-how-to-run-and-fine-tune/qwen3-2507.md#run-qwen3-235b-a22b-2507-tutorials" class="button secondary">运行 235B-A22B</a><a href="#fine-tuning-qwen3-2507-with-unsloth" class="button secondary">微调 Qwen3-2507</a>

**Unsloth** [**Dynamic 2.0**](/docs/zh/ji-chu-zhi-shi/dynamic-3.0-ggufs.md) **GGUF：**

| 模型                       | 要运行的 GGUF：                                                                                                                                        |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Qwen3-**4B-2507**        | [指令](https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF) • [思考](https://huggingface.co/unsloth/Qwen3-4B-Thinking-2507-GGUF)               |
| Qwen3-**30B-A3B**-2507   | [指令](#llama.cpp-run-qwen3-30b-a3b-instruct-2507-tutorial) • [思考](https://huggingface.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF)                 |
| Qwen3-**235B-A22B**-2507 | [指令](https://huggingface.co/unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF) • [思考](https://huggingface.co/unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF) |

## ⚙️最佳实践

{% hint style="success" %}
思考型和指令型模型的设置不同。\
思考型模型使用 temperature = 0.6，而指令型模型使用 temperature = 0.7\
思考型模型使用 top\_p = 0.95，而指令型模型使用 top\_p = 0.8
{% endhint %}

为达到最佳性能，Qwen 建议使用以下设置：

| 指令型模型设置：                                                          | 思考型模型设置：                                                          |
| ----------------------------------------------------------------- | ----------------------------------------------------------------- |
| <mark style="background-color:blue;">`Temperature = 0.7`</mark>   | <mark style="background-color:blue;">`Temperature = 0.6`</mark>   |
| `Min_P = 0.00` （llama.cpp 的默认值是 0.1）                              | `Min_P = 0.00` （llama.cpp 的默认值是 0.1）                              |
| `Top_P = 0.80`                                                    | `Top_P = 0.95`                                                    |
| `TopK = 20`                                                       | `TopK = 20`                                                       |
| `presence_penalty = 0.0 到 2.0` （llama.cpp 默认会关闭它，但为了减少重复，你可以使用这个） | `presence_penalty = 0.0 到 2.0` （llama.cpp 默认会关闭它，但为了减少重复，你可以使用这个） |

**足够的输出长度**：对大多数查询，思考版使用输出长度 `32,768` 大多数查询所需的 token 数，这对大多数查询已经足够。

两种模式的聊天模板（thinking 额外有 `<think></think>`），instruct 如下：

```
<|im_start|>user
嘿！<|im_end|>
<|im_start|>assistant
1+1 等于多少？<|im_end|>
<|im_start|>user
2<|im_end|>
<|im_start|>assistant
```

## 📖 运行 Qwen3-30B-A3B-2507 教程

下面是该 [思考](#thinking-qwen3-30b-a3b-thinking-2507) 和 [指令](#instruct-qwen3-30b-a3b-instruct-2507) 模型版本的指南。

### 指令型：Qwen3-30B-A3B-Instruct-2507

鉴于这是一个非思考型模型，无需设置 `thinking=False` 并且模型不会生成 `<think> </think>` 块。

#### ⚙️最佳实践

为达到最佳性能，Qwen 建议使用以下设置：

* 我们建议使用 `temperature=0.7, top_p=0.8, top_k=20, and min_p=0.0` `presence_penalty` 在 0 到 2 之间，如果框架支持的话，以减少无休止的重复。
* **`temperature = 0.7`**
* `top_k = 20`
* `min_p = 0.00` （llama.cpp 的默认值是 0.1）
* **`top_p = 0.80`**
* `presence_penalty = 0.0 到 2.0` （llama.cpp 默认会关闭它，但为了减少重复，你可以使用这个）例如尝试 1.0。
* 支持高达 `262,144` 本地上下文，但你可以将其设为 `32,768` tokens，以减少 RAM 使用

#### 🦙 Ollama：运行 Qwen3-30B-A3B-Instruct-2507 教程

1. 安装 `ollama` 如果你还没有安装的话！你只能运行参数规模不超过 32B 的模型。

```bash
apt-get update
apt-get install pciutils -y
curl -fsSL https://ollama.com/install.sh | sh
```

2. 运行模型！注意，如果失败，你可以在另一个终端中调用 `ollama serve`！我们把所有修复和建议参数（温度等）都包含在 `params` 中，位于我们上传到 Hugging Face 的文件里！

```bash
ollama run hf.co/unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF:UD-Q4_K_XL
```

#### :sparkles: Llama.cpp：运行 Qwen3-30B-A3B-Instruct-2507 教程

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

```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-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

2. 你可以通过以下方式直接从 HuggingFace 拉取：

   ```bash
   ./llama.cpp/llama-cli \\
       -hf unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF:Q4_K_XL \
       --jinja -ngl 99 --ctx-size 32768 \\
       --temp 0.7 --min-p 0.0 --top-p 0.80 --top-k 20 --presence-penalty 1.0
   ```
3. 通过以下方式下载模型（在安装 `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/Qwen3-30B-A3B-Instruct-2507-GGUF",
    local_dir = "unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF",
    allow_patterns = ["*UD-Q4_K_XL*"],
)
```

### 思考型：Qwen3-30B-A3B-Thinking-2507

该模型原生仅支持思考模式和 256K 上下文窗口。默认聊天模板会自动添加 `<think>` ，因此你可能在输出中只看到一个结尾的 `</think>` 标签。

#### ⚙️最佳实践

为达到最佳性能，Qwen 建议使用以下设置：

* 我们建议使用 `temperature=0.6, top_p=0.95, top_k=20, and min_p=0.0` `presence_penalty` 在 0 到 2 之间，如果框架支持的话，以减少无休止的重复。
* **`temperature = 0.6`**
* `top_k = 20`
* `min_p = 0.00` （llama.cpp 的默认值是 0.1）
* **`top_p = 0.95`**
* `presence_penalty = 0.0 到 2.0` （llama.cpp 默认会关闭它，但为了减少重复，你可以使用这个）例如尝试 1.0。
* 支持高达 `262,144` 本地上下文，但你可以将其设为 `32,768` tokens，以减少 RAM 使用

#### 🦙 Ollama：运行 Qwen3-30B-A3B-Instruct-2507 教程

1. 安装 `ollama` 如果你还没有安装的话！你只能运行参数规模不超过 32B 的模型。要运行完整的 235B-A22B 模型， [请看这里](#run-qwen3-235b-a22b-instruct-2507).

```bash
apt-get update
apt-get install pciutils -y
curl -fsSL https://ollama.com/install.sh | sh
```

2. 运行模型！注意，如果失败，你可以在另一个终端中调用 `ollama serve`！我们把所有修复和建议参数（温度等）都包含在 `params` 中，位于我们上传到 Hugging Face 的文件里！

```bash
ollama run hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL
```

#### :sparkles: Llama.cpp：运行 Qwen3-30B-A3B-Instruct-2507 教程

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

```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-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

2. 你可以直接通过以下方式从 Hugging Face 拉取：

   ```bash
   ./llama.cpp/llama-cli \\
       -hf unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:Q4_K_XL \
       --jinja -ngl 99 --ctx-size 32768 \\
       --temp 0.6 --min-p 0.0 --top-p 0.95 --top-k 20 --presence-penalty 1.0
   ```
3. 通过以下方式下载模型（在安装 `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/Qwen3-30B-A3B-Thinking-2507-GGUF",
    local_dir = "unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF",
    allow_patterns = ["*UD-Q4_K_XL*"],
)
```

## 📖 运行 **Qwen3-235B-A22B-2507** 教程

下面是该 [思考](#run-qwen3-235b-a22b-thinking-via-llama.cpp) 和 [指令](#run-qwen3-235b-a22b-instruct-via-llama.cpp) 模型版本的指南。

### 思考型：Qwen3-**235B-A22B**-Thinking-2507

该模型原生仅支持思考模式和 256K 上下文窗口。默认聊天模板会自动添加 `<think>` ，因此你可能在输出中只看到一个结尾的 `</think>` 标签。

#### :gear: 最佳实践

为实现最佳性能，Qwen 推荐思考型模型使用以下设置：

* **`temperature = 0.6`**
* `top_k = 20`
* `min_p = 0.00` （llama.cpp 的默认值是 0.1）
* `top_p = 0.95`
* `presence_penalty = 0.0 到 2.0` （llama.cpp 默认会关闭它，但为了减少重复，你可以使用这个）例如尝试 1.0。
* **足够的输出长度**：对大多数查询，思考版使用输出长度 `32,768` 大多数查询所需的 token 数，这对大多数查询已经足够。

#### :sparkles:通过 llama.cpp 运行 Qwen3-235B-A22B-Thinking：

对于 Qwen3-235B-A22B，我们将特别使用 Llama.cpp 进行优化推理，并提供丰富的选项。

{% hint style="success" %}
如果你想要一个 **完整精度、未量化版本**，请使用我们的 `Q8_K_XL, Q8_0` 或 `BF16` 版本！
{% endhint %}

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

   ```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-gguf-split
   cp llama.cpp/build/bin/llama-* llama.cpp
   ```
2. 你可以直接使用 llama.cpp 下载模型，但我通常建议使用 `huggingface_hub` 要直接使用 llama.cpp，请执行：

   ```bash
   ./llama.cpp/llama-cli \\
       -hf unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF:Q2_K_XL \
       --ctx-size 16384 \
       --n-gpu-layers 99 \
       -ot ".ffn_.*_exps.=CPU" \\
       --temp 0.6 \\
       --min-p 0.0 \
       --top-p 0.95 \\
       --top-k 20 \
       --presence-penalty 1.0
   ```
3. 通过以下方式下载模型（在安装 `pip install huggingface_hub hf_transfer` ）。你可以选择 UD-Q2\_K\_XL，或其他量化版本。。

   ```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/Qwen3-235B-A22B-Thinking-2507-GGUF",
       local_dir = "unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF",
       allow_patterns = ["*UD-Q2_K_XL*"],
   )
   ```
4. 运行模型并尝试任意提示。
5. 编辑 `--threads -1` CPU 线程数， `--ctx-size` 262114 作为上下文长度， `--n-gpu-layers 99` 用于 GPU 卸载的层数。如果你的 GPU 显存不足，请尝试调整它。如果你只使用 CPU 推理，也请将其移除。

{% hint style="success" %}
使用 `-ot ".ffn_.*_exps.=CPU"` 将所有 MoE 层卸载到 CPU！这实际上让你可以把所有非 MoE 层放到 1 张 GPU 上，从而提升生成速度。如果你有更多 GPU 容量，还可以自定义正则表达式以容纳更多层。
{% endhint %}

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \\
    --model unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF/UD-Q2_K_XL/Qwen3-235B-A22B-Thinking-2507-UD-Q2_K_XL-00001-of-00002.gguf \
    --ctx-size 16384 \
    --n-gpu-layers 99 \
    -ot ".ffn_.*_exps.=CPU" \\
    --seed 3407 \
    --temp 0.6 \\
    --min-p 0.0 \
    --top-p 0.95 \\
    --top-k 20
    --presence-penalty 1.0
```

{% endcode %}

### 指令型：Qwen3-**235B-A22B**-Instruct-2507

鉴于这是一个非思考型模型，无需设置 `thinking=False` 并且模型不会生成 `<think> </think>` 块。

#### ⚙️最佳实践

为实现最佳性能，我们建议使用以下设置：

**1. 采样参数**：我们建议使用 `temperature=0.7、top_p=0.8、top_k=20 和 min_p=0。` `presence_penalty` 在 0 到 2 之间，如果框架支持的话，以减少无休止的重复。

2\. **足够的输出长度**：我们建议输出长度设为 `16,384` 个 token，适用于大多数查询，这对指令型模型已经足够。

3\. **标准化输出格式：** 在进行基准测试时，我们建议使用提示词来规范模型输出。

* **数学问题**：包含 `请逐步推理，并将最终答案放在 \boxed{} 中。` 在提示词中。
* **选择题**：向提示词中添加以下 JSON 结构以规范响应："请仅在 \`answer\` 字段中显示你的选择，只写选项字母，例如，\`\\"answer\\": \\"C\\"。

#### :sparkles:通过 llama.cpp 运行 Qwen3-235B-A22B-Instruct：

对于 Qwen3-235B-A22B，我们将特别使用 Llama.cpp 进行优化推理，并提供丰富的选项。

{% hint style="info" %}
如果你想要一个 **完整精度、未量化版本**，请使用我们的 `Q8_K_XL, Q8_0` 或 `BF16` 版本！
{% endhint %}

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

```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-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

2\. 你可以直接使用 llama.cpp 下载模型，但我通常建议使用 `huggingface_hub` 若要直接使用 llama.cpp，请执行：\\

```bash
./llama.cpp/llama-cli \\
    -hf unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF:Q2_K_XL \
    --ctx-size 16384 \
    --n-gpu-layers 99 \
    -ot ".ffn_.*_exps.=CPU" \\
    --temp 0.7 \\
    --min-p 0.0 \
    --top-p 0.8 \
    --top-k 20 \
    --repeat-penalty 1.0
```

3\. 通过以下方式下载模型（在安装 `pip install huggingface_hub hf_transfer` ）。你可以选择 UD-Q2\_K\_XL，或其他量化版本。。

```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/Qwen3-235B-A22B-Instruct-2507-GGUF",
    local_dir = "unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF",
    allow_patterns = ["*UD-Q2_K_XL*"],
)
```

4\. 运行模型并尝试任意提示词。5. 编辑 `--threads -1` CPU 线程数， `--ctx-size` 262114 作为上下文长度， `--n-gpu-layers 99` 用于 GPU 卸载的层数。如果你的 GPU 显存不足，请尝试调整它。如果你只使用 CPU 推理，也请将其移除。

{% hint style="success" %}
使用 `-ot ".ffn_.*_exps.=CPU"` 将所有 MoE 层卸载到 CPU！这实际上让你可以把所有非 MoE 层放到 1 张 GPU 上，从而提升生成速度。如果你有更多 GPU 容量，还可以自定义正则表达式以容纳更多层。
{% endhint %}

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \\
    --model unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF/UD-Q2_K_XL/Qwen3-235B-A22B-Instruct-2507-UD-Q2_K_XL-00001-of-00002.gguf \
    --ctx-size 16384 \
    --n-gpu-layers 99 \
    -ot ".ffn_.*_exps.=CPU" \\
    --temp 0.7 \\
    --min-p 0.0 \
    --top-p 0.8 \
    --top-k 20
```

{% endcode %}

### 🛠️ 提升生成速度 <a href="#improving-generation-speed" id="improving-generation-speed"></a>

如果你有更多 VRAM，可以尝试卸载更多 MoE 层，或者直接卸载整个层。

通常， `-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 "\.(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 层。

“ [最新的 llama.cpp 版本](https://github.com/ggml-org/llama.cpp/pull/14363) 还引入了高吞吐模式。使用 `llama-parallel`. 了解更多 [这里](https://github.com/ggml-org/llama.cpp/tree/master/examples/parallel). 你还可以 **将 KV 缓存量化为 4 位** 例如可减少 VRAM / RAM 之间的数据移动，这也能让生成过程更快。 [下一节](#how-to-fit-long-context-256k-to-1m) 将介绍 KV 缓存量化。

### 📐如何适配长上下文 <a href="#how-to-fit-long-context-256k-to-1m" id="how-to-fit-long-context-256k-to-1m"></a>

要容纳更长的上下文，你可以使用 **KV 缓存量化** 将 K 和 V 缓存量化为更低的位数。这也可以因为减少 RAM / VRAM 数据传输而提高生成速度。K 量化允许的选项（默认是 `f16`）包括以下内容。

`--cache-type-k f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1`

你应该使用 `_1` 这些变体以获得稍高的准确率，不过会稍慢一些。例如 `q4_1, q5_1` 所以请尝试 `--cache-type-k q4_1`

你也可以量化 V 缓存，但你需要 **通过以下方式编译支持 Flash Attention 的 llama.cpp** 支持，方法是使用 `-DGGML_CUDA_FA_ALL_QUANTS=ON`，并使用 `--flash-attn` 来启用它。安装 Flash Attention 之后，你就可以使用 `--cache-type-v q4_1`

## 🦥 使用 Unsloth 微调 Qwen3-2507

Unsloth 使 [Qwen3](/docs/zh/mo-xing/tutorials/qwen3-how-to-run-and-fine-tune.md#fine-tuning-qwen3-with-unsloth) 并使 Qwen3-2507 的微调速度提升 2 倍，显存占用减少 70%，并支持 8 倍更长的上下文长度。由于 Qwen3-2507 仅发布了 30B 变体，这意味着你需要一块大约 40GB 的 A100 GPU，才能使用 QLoRA（4 位）对模型进行微调。

对于 notebook，由于模型无法放入 Colab 免费的 16GB GPU，你需要使用 40GB A100。你可以使用我们的对话 notebook，但将数据集替换为你正在使用的任意数据集。这次你不需要在数据集中包含推理内容，因为该模型没有推理能力。

* [Qwen3（14B）推理 + 对话 notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(14B\)-Reasoning-Conversational.ipynb)

如果你使用的是旧版本的 Unsloth 和/或是在本地进行微调，请安装最新版的 Unsloth：

```bash
pip install --upgrade --force-reinstall --no-cache-dir unsloth unsloth_zoo
```

### Qwen3-2507 MOE 模型微调

微调支持包括 MOE 模型：30B-A3B 和 235B-A22B。Qwen3-30B-A3B 可在 30GB 显存上通过 Unsloth 运行。对于 MoE 的微调——大概不建议微调路由层，所以我们默认将其禁用。

**Qwen3-2507-4B notebook 适用于：** [思考](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(4B\)-Thinking.ipynb) 和 [指令](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(4B\)-Instruct.ipynb)

30B-A3B 可放入 30GB 显存，但你可能会缺少内存或磁盘空间，因为完整的 16 位模型必须先下载，然后在 QLoRA 微调时即时转换为 4 位。这是由于直接导入 4 位 BnB MOE 模型存在问题。这只影响 MOE 模型。

{% hint style="warning" %}
如果你正在微调 MOE 模型，请使用 `FastModel` 而不是 `FastLanguageModel`
{% endhint %}

```python
from unsloth import FastModel
import torch
model, tokenizer = FastModel.from_pretrained(
    model_name = "unsloth/Qwen3-30B-A3B-Instruct-2507",
    max_seq_length = 2048, # 长上下文可任选任何值！
    load_in_4bit = True,  # 4 位量化以减少显存
    load_in_8bit = False, # [NEW!] 稍微更准确，使用 2 倍内存
    full_finetuning = False, # [NEW!] 我们现在支持完整微调！
    # token = "hf_...", # 如果使用受限模型则使用这个
)
```

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-be34c101c627020c7a6cfb6cd249f2462587d235%2Fqwen33%20mascot.png?alt=media" 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 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/qwen3-how-to-run-and-fine-tune/qwen3-2507.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.
