# Qwen3.5 微调指南

你现在可以微调 [Qwen3.5](https://unsloth.ai/docs/zh/mo-xing/qwen3.5) 模型家族（0.8B、2B、4B、9B、27B、35B‑A3B、122B‑A10B）使用 [**使用 Unsloth 进行**](https://github.com/unslothai/unsloth)。支持包括 [视觉](#vision-fine-tuning)、文本和 [RL](#reinforcement-learning-rl) 微调。 **Qwen3.5‑35B‑A3B** - bf16 LoRA 可在 **74GB 显存上运行。**

* Unsloth 使 Qwen3.5 训练 **快 1.5 倍** 并且使用 **比 FA2 配置少 50% 的显存** 。
* Qwen3.5 bf16 LoRA 显存使用： **0.8B**：3GB • **2B**：5GB • **4B**：10GB • **9B**：22GB • **27B**：56GB
* 通过我们的 **0.8B**, **2B** 以及 **4B** 通过我们的 bf16 LoRA **免费** **Google Colab 笔记本**:

| [Qwen3.5-**0.8B**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(0_8B\)_Vision.ipynb) | [Qwen3.5-**2B**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(2B\)_Vision.ipynb) | [Qwen3.5-**4B**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(4B\)_Vision.ipynb) | [Qwen3.5-4B **GRPO**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(4B\)_Vision_GRPO.ipynb) |
| --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |

* 如果你想 **保留推理** 能力，你可以将推理风格示例与直接答案混合使用（至少保留 75% 的推理）。否则你可以完全输出。
* **全量微调（FFT）** 也同样可用。请注意，这将使用 4 倍更多的显存。
* Qwen3.5 适合多语言微调，因为它支持 201 种语言。
* 微调完成后，你可以导出为 [GGUF](#saving-export-your-fine-tuned-model) （适用于 llama.cpp/Ollama 等）或 [vLLM](#saving-export-your-fine-tuned-model)
* [强化学习](https://unsloth.ai/docs/zh/kai-shi-shi-yong/reinforcement-learning-rl-guide) （RL）用于 Qwen3.5 [VLM RL](https://unsloth.ai/docs/zh/kai-shi-shi-yong/reinforcement-learning-rl-guide/vision-reinforcement-learning-vlm-rl) 也可通过 Unsloth 推理使用。
* 我们有 **A100** Colab 笔记本用于 [Qwen3.5‑27B](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen_3_5_27B_A100\(80GB\).ipynb) 以及 [Qwen3.5‑35B‑A3B](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_MoE.ipynb).

如果你使用的是旧版本（或在本地微调），请先更新：

{% columns %}
{% column %}
Unsloth Studio：

{% code expandable="true" %}

```bash
unsloth studio update
```

{% endcode %}
{% endcolumn %}

{% column %}
基于代码的 Unsloth：

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

{% endcolumn %}
{% endcolumns %}

{% hint style="warning" %}
**请使用 `transformers v5` 用于 Qwen3.5。旧版本将无法使用。Unsloth 现在默认会自动使用 transformers v5（Colab 环境除外）。**

如果训练看起来 **比平时更慢**，那是因为 Qwen3.5 使用了自定义的 Mamba Triton 内核。编译这些内核可能比正常情况更久，尤其是在 T4 GPU 上。

不建议在 Qwen3.5 模型上进行 QLoRA（4-bit）训练，无论是 MoE 还是稠密模型，都因为量化差异高于正常水平。
{% endhint %}

### MoE 微调（35B、122B）

对于像以下这样的 MoE 模型 **Qwen3.5‑35B‑A3B / 122B‑A10B / 397B‑A17B**:

* 你可以使用我们的 [Qwen3.5‑35B‑A3B（A100）](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_MoE.ipynb) 微调笔记本
* 支持我们最近约快 12 倍的 [MoE 训练更新](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/faster-moe) 显存减少 >35%，上下文长度约提升 6 倍
* **最好使用 bf16 配置（例如 LoRA 或全参数微调）** （由于 BitsandBytes 的限制，不建议使用 MoE QLoRA 4-bit）。
* Unsloth 的 MoE 内核默认启用，并且可以使用不同后端；你可以通过以下方式切换： `UNSLOTH_MOE_BACKEND`.
* 为稳定起见，默认禁用路由层微调。
* Qwen3.5‑122B‑A10B - bf16 LoRA 可在 256GB 显存上运行。如果你使用多 GPU，请添加     `device_map = "balanced"` 或者参考我们的 [多 GPU 指南](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/multi-gpu-training-with-unsloth).

### 快速开始

#### 🦥 Unsloth Studio 指南

Qwen3.5 可以在以下环境中运行和微调 [Unsloth Studio](https://unsloth.ai/docs/zh/xin/studio)中运行和微调，这是我们为本地 AI 推出的新开源网页界面。使用 Unsloth Studio，你可以在以下系统上本地运行模型： **MacOS、Windows**、Linux 以及：

{% columns %}
{% column %}

* [训练 LLM](https://unsloth.ai/docs/zh/xin/studio#no-code-training) 速度提升 2 倍，VRAM 减少 70%
* 搜索、下载、 [运行 GGUF](https://unsloth.ai/docs/zh/xin/studio#run-models-locally) 和 safetensor 模型
* [**自我修复** 工具调用](https://unsloth.ai/docs/zh/xin/studio#execute-code--heal-tool-calling) + **网页搜索**
* [**代码执行**](https://unsloth.ai/docs/zh/xin/studio#run-models-locally) （Python、Bash）
* [自动推理](https://unsloth.ai/docs/zh/xin/studio#model-arena) 参数调优（temp、top-p 等）
* 通过 llama.cpp 实现快速 CPU + GPU 推理
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F6HTkhiz3DUtrtcqASpTy%2Fobserve%20skinny.png?alt=media&#x26;token=1981fe89-eccf-4c3d-ba92-d76f3123b05f" 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
```

{% hint style="success" %}
**安装会很快，约需 1-2 分钟。**
{% endhint %}
{% endstep %}

{% step %}

#### 启动 Unsloth

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

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

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

{% step %}

#### 训练 Qwen3.5

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

在搜索栏中搜索 Qwen3.5，并选择你想要的模型和数据集。接着，按需调整你的超参数和上下文长度。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FKljuGLmIAlo7s8J4LLOc%2FScreenshot%202026-04-02%20at%202.08.54%E2%80%AFAM.png?alt=media&#x26;token=8cb779f7-fbd3-49e5-95e7-cc615558d854" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### 监控训练进度

点击开始训练后，你将能够监控并观察模型的训练进度。训练损失应当稳定下降。\
完成后，模型会自动保存。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fhm21EMxnAiLJBgP3Tvtq%2FScreenshot%202026-04-02%20at%202.13.21%E2%80%AFAM.png?alt=media&#x26;token=babaecda-2b28-47d8-818b-4a74f4595325" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### 导出你的微调模型

完成后，Unsloth Studio 允许你将模型导出为 GGUF、safetensor 等格式。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FZvedfVVAmectHAEHHlGg%2FScreenshot%202026-04-02%20at%202.14.40%E2%80%AFAM.png?alt=media&#x26;token=4ddefe19-657b-4861-86da-cbfd983f75ba" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

#### Unsloth Core（基于代码）指南：

下面是一个最小 SFT 配方（适用于“仅文本”微调）。另请参阅我们的 [视觉微调](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/vision-fine-tuning) 部分。

{% hint style="info" %}
Qwen3.5 是“带视觉编码器的因果语言模型”（它是一个统一的 VLM），因此请确保你已安装常规的视觉依赖项（`torchvision`, `pillow`）如有需要，并保持 Transformers 为最新版本。请使用最新的 Transformers 版本来支持 Qwen3.5。

**如果你想进行** [**GRPO**](https://unsloth.ai/docs/zh/kai-shi-shi-yong/reinforcement-learning-rl-guide)**，只要禁用 fast vLLM 推理并改用 Unsloth 推理，它就能在 Unsloth 中运行。请参考我们的** [**视觉 RL**](https://unsloth.ai/docs/zh/kai-shi-shi-yong/reinforcement-learning-rl-guide/vision-reinforcement-learning-vlm-rl) **笔记本示例。**
{% endhint %}

{% code expandable="true" %}

```python
from unsloth import FastLanguageModel
import torch
from datasets import load_dataset
from trl import SFTTrainer, SFTConfig

max_seq_length = 2048  # 先从小开始；能工作后再扩大

# 示例数据集（替换为你的）。需要一个 "text" 列。
url = "https://huggingface.co/datasets/laion/OIG/resolve/main/unified_chip2.jsonl"
dataset = load_dataset("json", data_files={"train": url}, split="train")

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "Qwen/Qwen3.5-27B",
    max_seq_length = max_seq_length,
    load_in_4bit = False,     # 不建议使用 MoE QLoRA，稠密 27B 没问题
    load_in_16bit = True,     # bf16/16 位 LoRA
    full_finetuning = False,
)

model = FastLanguageModel.get_peft_model(
    model,
    r = 16,
    target_modules = [
        "q_proj", "k_proj", "v_proj", "o_proj",
        "gate_proj", "up_proj", "down_proj",
    ],
    lora_alpha = 16,
    lora_dropout = 0,
    bias = "none",
    # "unsloth" 检查点机制适用于超长上下文 + 更低 VRAM
    use_gradient_checkpointing = "unsloth",
    random_state = 3407,
    max_seq_length = max_seq_length,
)

trainer = SFTTrainer(
    model = model,
    train_dataset = dataset,
    tokenizer = tokenizer,
    args = SFTConfig(
        max_seq_length = max_seq_length,
        per_device_train_batch_size = 1,
        gradient_accumulation_steps = 4,
        warmup_steps = 10,
        max_steps = 100,
        logging_steps = 1,
        output_dir = "outputs_qwen35",
        optim = "adamw_8bit",
        seed = 3407,
        dataset_num_proc = 1,
    ),
)

trainer.train()
```

{% endcode %}

{% hint style="info" %}
如果你遇到 OOM：

* 将 `per_device_train_batch_size` 调低到 **1** 和/或降低 `max_seq_length`.&#x20;
* 保留 `use_`[`gradient_checkpointing`](https://unsloth.ai/docs/zh/bo-ke/500k-context-length-fine-tuning#unsloth-gradient-checkpointing-enhancements)`="unsloth"` 开启（它旨在减少 VRAM 使用并延长上下文长度）。
  {% endhint %}

**MoE 加载示例（bf16 LoRA）：**

```python
import os
import torch
from unsloth import FastModel

model, tokenizer = FastModel.from_pretrained(
    model_name = "unsloth/Qwen3.5-35B-A3B",
    max_seq_length = 2048,
    load_in_4bit = False,     # 不建议使用 MoE QLoRA，稠密 27B 没问题
    load_in_16bit = True,     # bf16/16 位 LoRA
    full_finetuning = False,
)
```

加载完成后，你将附加 LoRA 适配器，并像上面的 SFT 示例那样进行训练。

### 视觉微调

Unsloth 支持 [视觉微调](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/vision-fine-tuning) 用于多模态 Qwen3.5 模型。请使用下面的 Qwen3.5 笔记本，并将相应的模型名称改为你想要的 Qwen3.5 模型。

| [Qwen3.5-**0.8B**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(0_8B\)_Vision.ipynb) | [Qwen3.5-**2B**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(2B\)_Vision.ipynb) | [Qwen3.5-**4B**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(4B\)_Vision.ipynb) | Qwen3.5-**9B** |
| --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | -------------- |

* [Qwen3-VL GRPO/GSPO RL 笔记本](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_VL_\(8B\)-Vision-GRPO.ipynb) （将模型名称改为 Qwen3.5-4B 等）

**禁用视觉 / 仅文本微调：**

为了微调视觉模型，我们现在允许你选择要微调模型的哪些部分。你可以选择只微调视觉层，或语言层，或注意力 / MLP 层！我们默认全部开启！

{% code expandable="true" %}

```python
model = FastVisionModel.get_peft_model(
    model,
    finetune_vision_layers     = True, # 如果不微调视觉层则为 False
    finetune_language_layers   = True, # 如果不微调语言层则为 False
    finetune_attention_modules = True, # 如果不微调注意力层则为 False
    finetune_mlp_modules       = True, # 如果不微调 MLP 层则为 False

    r = 16,                           # 越大，准确率越高，但可能过拟合
    lora_alpha = 16,                  # 建议 alpha 至少等于 r
    lora_dropout = 0,
    bias = "none",
    random_state = 3407,
    use_rslora = False,               # 我们支持秩稳定化 LoRA
    loftq_config = None,               # 以及 LoftQ
    target_modules = "all-linear",    # 现在可选！如有需要可指定列表
    modules_to_save=[
        "lm_head",
        "embed_tokens",
    ],
)
```

{% endcode %}

为了使用多图像来微调或训练 Qwen3.5， 请查看我们的 [**多图像视觉指南**](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/vision-fine-tuning#multi-image-training)**.**

### 强化学习（RL）

你现在可以使用 [我们的免费笔记本](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_\(4B\)_Vision_GRPO.ipynb):

{% embed url="<https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_5_(4B)_Vision_GRPO.ipynb>" %}

即使 vLLM 不支持，你仍然可以通过设置以下参数来使用 Unsloth 运行 Qwen3.5 RL： `fast_inference=False` 在加载模型时：

```python
from unsloth import FastLanguageModel

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="unsloth/Qwen3.5-4B",
    fast_inference=False,
)
```

### 保存 / 导出微调模型

你可以查看我们针对以下内容的特定推理 / 部署指南： [Unsloth Studio](https://unsloth.ai/docs/zh/xin/studio/export), [llama.cpp](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/inference-and-deployment/saving-to-gguf), [vLLM](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/inference-and-deployment/vllm-guide), [llama-server](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/inference-and-deployment/llama-server-and-openai-endpoint), [Ollama](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/inference-and-deployment/saving-to-ollama).

#### 保存为 GGUF

Unsloth 支持直接保存为 GGUF：

```python
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "q4_k_m")
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "q8_0")
model.save_pretrained_gguf("directory", tokenizer, quantization_method = "f16")
```

或者将 GGUF 推送到 Hugging Face：

```python
model.push_to_hub_gguf("hf_username/directory", tokenizer, quantization_method = "q4_k_m")
model.push_to_hub_gguf("hf_username/directory", tokenizer, quantization_method = "q8_0")
```

如果导出的模型在另一个运行时中的表现更差，Unsloth 会指出最常见的原因： **推理时使用了错误的聊天模板 / EOS 令牌** （你必须使用与你训练时相同的聊天模板）。

#### 保存到 vLLM

{% hint style="warning" %}
vLLM 版本 `0.16.0` 不支持 Qwen3.5。请等待 `0.170` 或者尝试 Nightly 版本。
{% endhint %}

要保存为 16-bit 以供 vLLM 使用，请使用：

{% code overflow="wrap" %}

```python
model.save_pretrained_merged("finetuned_model", tokenizer, save_method = "merged_16bit")
## 或上传到 HuggingFace：
model.push_to_hub_merged("hf/model", tokenizer, save_method = "merged_16bit", token = "")
```

{% endcode %}

如果只想保存 LoRA 适配器，可使用以下任一方式：

```python
model.save_pretrained("finetuned_lora")
tokenizer.save_pretrained("finetuned_lora")
```

或者使用我们内置的函数：

{% code overflow="wrap" %}

```python
model.save_pretrained_merged("finetuned_model", tokenizer, save_method = "lora")
## 或上传到 HuggingFace
model.push_to_hub_merged("hf/model", tokenizer, save_method = "lora", token = "")
```

{% endcode %}

更多详情请阅读我们的推理指南：

{% columns %}
{% column width="50%" %}
{% content-ref url="../../ji-chu-zhi-shi/inference-and-deployment" %}
[inference-and-deployment](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/inference-and-deployment)
{% endcontent-ref %}

{% content-ref url="../../ji-chu-zhi-shi/inference-and-deployment/saving-to-gguf" %}
[saving-to-gguf](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/inference-and-deployment/saving-to-gguf)
{% endcontent-ref %}
{% endcolumn %}

{% column width="50%" %}
{% content-ref url="../../xin/studio/export" %}
[export](https://unsloth.ai/docs/zh/xin/studio/export)
{% endcontent-ref %}

{% content-ref url="../../ji-chu-zhi-shi/inference-and-deployment/vllm-guide" %}
[vllm-guide](https://unsloth.ai/docs/zh/ji-chu-zhi-shi/inference-and-deployment/vllm-guide)
{% endcontent-ref %}
{% endcolumn %}
{% endcolumns %}
