# 在 NVIDIA DGX Station 上使用 Unsloth 微调 LLM

现在，您可以在 NVIDIA DGX Station 上使用本地训练 LLM，使用 [Unsloth](https://github.com/unslothai/unsloth)。DGX Station 拥有超过 **\~200GB 显存** 以及超过 **700GB 的统一 GPU/CPU 内存** 并将 Grace CPU 与 Blackwell GPU 结合在一个紧密互连的系统中，专为大规模 AI 工作负载设计。通过 NVLink-C2C 连接，CPU 与 GPU 虽然仍然各自独立，但协同工作比传统的 CPU-GPU 配置高效得多。

在本指南中，我们将使用 Unsloth 笔记本训练 [Qwen3.5](#qwen3.5-35b-a3b-fine-tuning) 和 [gpt-oss-120b](#gpt-oss-120b-fine-tuning) 在 DGX Station 上。感谢 NVIDIA 提供部分早期访问的 DGX Station 硬件以测试 Unsloth！

### 快速开始

您将需要 `python3` 已安装，特别是需要开发头文件。在我们的系统上，我们有 `python 3.12` 因此我们将安装 3.12 的开发头文件。

```bash
sudo apt update
sudo apt install python3.12-dev
```

然后创建一个新的虚拟环境来安装 [Unsloth](https://github.com/unslothai/unsloth)。这样我们可以最小化依赖冲突并保留当前工作环境的状态。&#x20;

{% code overflow="wrap" %}

```bash
python3 -m venv .unsloth
source .unsloth/bin/activate
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130
```

{% endcode %}

{% hint style="warning" %}
首先从 `torch` 安装 `cuda 13` 索引，否则我们可能会得到 CPU 版本或体系结构与功能不匹配的版本！
{% endhint %}

<div><figure><img src="/files/e2ba630849737314af6bf416d4a64b3856952159" alt=""><figcaption></figcaption></figure> <figure><img src="/files/e028078c5e28b66de7cbe395c0ec9dadbd33c130" alt=""><figcaption></figcaption></figure></div>

现在我们可以安装 Unsloth：

```bash
pip install unsloth
```

<div><figure><img src="/files/0943d1a340d31cd1b5baa197d2ff01b1c4d363ce" alt=""><figcaption></figcaption></figure> <figure><img src="/files/b02597ae649bb1cf8e0d5b956343279653ef15fb" alt=""><figcaption></figcaption></figure></div>

现在让我们安装 `xformers` 并（可选地）从源码构建 `flash-attention` 这两个包都需要时间，因此在构建时请耐心等待。

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

```bash
pip install --no-deps --no-build-isolation xformers==0.0.33.post1
# 可选的 flash-attn
# 克隆并构建（针对 B300 的 sm_100） 
git clone https://github.com/Dao-AILab/flash-attention
cd flash-attention 
# B300 = sm_100，显式设置架构 
TORCH_CUDA_ARCH_LIST="10.0" MAX_JOBS=8 pip install . --no-build-isolation
cd ..
```

{% endcode %}

<div><figure><img src="/files/77ee1ed30ca8208b64dff6a14ea176bb19ae48a2" alt=""><figcaption></figcaption></figure> <figure><img src="/files/8333483b2fde9d81cb378f5b1169815b67e17b3f" alt=""><figcaption></figcaption></figure></div>

{% columns %}
{% column %}
对于 Qwen 3.5 MoE，我们需要下载两个内核包 `flash-linear-attention` 和 `causal-conv1d` 以提高速度。

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

```bash
pip install --no-build-isolation flash-linear-attention causal_conv1d==1.6.0
```

{% endcode %}
{% endcolumn %}

{% column %}

<figure><img src="/files/d37ecded3c5d983b7fcfc5de5b5e97e24ecc004e" alt="" width="375"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

如果您还没有笔记本客户端，请安装一个。对于本指南，我们将使用 Jupyter Notebook：

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

```bash
cd ..
pip install notebook
pip install ipywidgets
```

{% endcode %}

最后我们下载实际用于运行的 Unsloth 笔记本。共有 250 多个用于 LLM 训练的笔记本以及 Python 脚本。

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

```bash
git clone https://github.com/unslothai/notebooks.git
cd notebooks
```

{% endcode %}

### 训练教程

{% columns %}
{% column %}
现在我们可以启动 Jupyter Notebook 并在浏览器中导航到 UI。

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

```bash
jupyter notebook
```

{% endcode %}
{% endcolumn %}

{% column %}

<figure><img src="/files/9924e198bd25b56fc0ec126889cc358f6a56beda" alt="" width="375"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
复制并粘贴 `localhost` 站点带有 token 参数并将其粘贴到浏览器中。您应看到类似于：

该 `nb` 文件夹包含所有可运行的笔记本。
{% endcolumn %}

{% column %}

<figure><img src="/files/d95bad03a22170204f2c1593d57aca03abbae9f7" alt="" width="375"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

#### Qwen3.5-35B-A3B 训练

{% columns %}
{% column %}
打开文件 `nb/Qwen3_5_MoE.ipynb`。跳过安装部分，因为我们之前已经安装了所有需要的内容。导航到 Unsloth 部分并从那里开始执行单元。

{% endcolumn %}

{% column %}

<figure><img src="/files/8126aed327154338e8e6076a3eef9b6aaa24e1c9" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
该笔记本涵盖模型设置、数据集准备和训练器配置。每一步可能都需要一些时间，因为我们正在下载非常大的模型、初始化数十亿个权重，并进一步优化以提高运行速度。&#x20;
{% endcolumn %}

{% column %}

<figure><img src="/files/d8de66a5d0a341b02102f5045f7485c8c0deebae" alt="" width="375"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

使用默认设置训练非常快。在 DGX Station 上内存充足，因此您可以调整默认训练超参数以真正挑战内存和计算。一旦训练完成，您可以保存模型以备后用，将模型推送到 Hugging Face Hub 与他人共享，或导出为量化格式。

#### gpt-oss-120b 训练

{% columns %}
{% column %}
打开文件 `nb/gpt-oss-(120B)_A100-Fine-tuning.ipynb`。跳过安装部分，因为我们已经安装了先决条件，并导航到 Unsloth 部分。我们可以从那里开始运行笔记本。该笔记本将使用大约 72 GB 的 GPU 内存，运行大约 10 分钟。
{% endcolumn %}

{% column %}

<figure><img src="/files/73c75f9288e6c292b03332cab62ee34cc31375a8" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
每个单元格可能需要一些时间来运行，因为我们需要下载模型、初始化权重，并进一步优化以获得更快的体验。笔记本涵盖数据集预处理和训练器设置。一旦我们到达 `trainer.train()` 单元并执行，训练就会开始。
{% endcolumn %}

{% column %}

<figure><img src="/files/d44ad652685b54edddf3b68c58fc872648b4a276" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

现在完成后，我们可以保存模型以备后用，推送到 Hugging Face Hub 与全世界共享，或将其导出为 GGUF 格式。

<figure><img src="/files/8a7173fb9f3d290099d7fc1b1b8a512b800b8db6" alt=""><figcaption></figcaption></figure>

在以下链接阅读有关 NVIDIA DGX Station 的更多信息： <https://www.nvidia.com/en-us/products/workstations/dgx-station/>


---

# 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/bo-ke/dgx-station.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.
