> 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/bo-ke/fine-tuning-llms-with-blackwell-rtx-50-series-and-unsloth.md).

# 使用 Blackwell、RTX 50 系列和 Unsloth 对 LLM 进行微调

通过我们的分步指南，了解如何在 NVIDIA Blackwell RTX 50 系列和 B200 GPU 上对 LLM 进行微调。

Unsloth 现在支持 NVIDIA 的 Blackwell 架构 GPU，包括 RTX 50 系列 GPU（5060–5090）、RTX PRO 6000，以及 B200、B40、GB100、GB102 等更多型号！你可以在这里阅读官方 [NVIDIA 博客文章](https://developer.nvidia.com/blog/train-an-llm-on-an-nvidia-blackwell-desktop-with-unsloth-and-scale-it/).

Unsloth 现在与 2018 年及以后的所有 NVIDIA GPU 兼容，包括 [DGX Spark](/docs/zh/bo-ke/fine-tuning-llms-with-nvidia-dgx-spark-and-unsloth.md).

> **我们的新** [**Docker 镜像**](#docker) **支持 Blackwell。运行 Docker 镜像并开始训练！** [**指南**](/docs/zh/bo-ke/fine-tuning-llms-with-blackwell-rtx-50-series-and-unsloth.md)

### Pip 安装

只需安装 Unsloth：

```bash
pip install unsloth
```

如果你看到问题，另一种选择是创建一个独立的隔离环境：

```bash
python -m venv unsloth
source unsloth/bin/activate
pip install unsloth
```

注意它可能是 `pip3` 或 `pip3.13` 以及 `python3` 或 `python3.13`

你可能会遇到一些 Xformers 问题，在这种情况下你应该从源码构建：

{% code overflow="wrap" %}

```bash
# 先卸载之前库安装的 xformers
pip uninstall xformers -y

# 克隆并构建
pip install ninja
export TORCH_CUDA_ARCH_LIST="12.0"
git clone --depth=1 https://github.com/facebookresearch/xformers --recursive
cd xformers && python setup.py install && cd ..
```

{% endcode %}

### Docker

[**`unsloth/unsloth`**](https://hub.docker.com/r/unsloth/unsloth) 是 Unsloth 唯一的 Docker 镜像。对于 Blackwell 和 50 系列 GPU，请使用同一个镜像——无需单独镜像。

有关安装说明，请遵循我们的 [Unsloth Docker 指南](/docs/zh/bo-ke/how-to-fine-tune-llms-with-unsloth-and-docker.md).

### uv

```bash
uv pip install unsloth
```

#### uv（高级）

安装顺序很重要，因为我们希望用特定版本覆盖捆绑依赖项（即 `xformers` 和 `triton`).

1. 我更喜欢使用 `uv` 而不是 `pip` 因为它更快，且在解决依赖方面更好，尤其是对于依赖于 `torch` 但在这种情况下需要特定的 `CUDA` 版本。

   安装 `uv`

   ```bash
   curl -LsSf https://astral.sh/uv/install.sh | sh && source $HOME/.local/bin/env
   ```

   创建项目目录和虚拟环境：

   ```bash
   mkdir 'unsloth-blackwell' && cd 'unsloth-blackwell'
   uv venv .venv --python=3.12 --seed
   source .venv/bin/activate
   ```
2. 安装 `vllm`

   ```bash
   uv pip install -U vllm --torch-backend=cu128
   ```

   注意我们必须指定 `cu128`，否则 `vllm` 将安装 `torch==2.7.0` 但使用 `cu126`.
3. 安装 `unsloth` 依赖项

   ```bash
   uv pip install unsloth unsloth_zoo bitsandbytes
   ```

   如果你注意到由于 Xformers 导致的奇怪解析问题，你也可以在不使用 Xformers 的情况下从源码安装 Unsloth：

   ```bash
   uv pip install -qqq \
   "unsloth_zoo[base] @ git+https://github.com/unslothai/unsloth-zoo" \
   "unsloth[base] @ git+https://github.com/unslothai/unsloth"
   ```
4. 下载并构建 `xformers` （可选）

   Xformers 是可选的，但它确实更快且更省内存。如果你不想使用 Xformers，我们会使用 PyTorch 原生的 SDPA。从源码构建 Xformers 可能会很慢，所以要小心！

   ```bash
   # 先卸载之前库安装的 xformers
   pip uninstall xformers -y

   # 克隆并构建
   pip install ninja
   export TORCH_CUDA_ARCH_LIST="12.0"
   git clone --depth=1 https://github.com/facebookresearch/xformers --recursive
   cd xformers && python setup.py install && cd ..
   ```

   注意我们必须显式设置 `TORCH_CUDA_ARCH_LIST=12.0`.
5. `transformers` 安装任意版本的 transformers，但最好使用最新版本。

   ```bash
   uv pip install -U transformers
   ```

### Conda 或 mamba（高级）

1. 安装 `conda/mamba`

   ```bash
   curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
   ```

   运行安装脚本

   ```bash
   bash Miniforge3-$(uname)-$(uname -m).sh
   ```

   创建一个 conda 或 mamba 环境

   ```bash
   conda create --name unsloth-blackwell python==3.12 -y
   ```

   激活新创建的环境

   ```bash
   conda activate unsloth-blackwell
   ```
2. 安装 `vllm`

   确保你位于已激活的 conda/mamba 环境中。你应该会在终端提示符前看到你的环境名称作为前缀，像这样你的 `(unsloth-blackwell)user@machine:`

   ```bash
   pip install -U vllm --extra-index-url https://download.pytorch.org/whl/cu128
   ```

   注意我们必须指定 `cu128`，否则 `vllm` 将安装 `torch==2.7.0` 但使用 `cu126`.
3. 安装 `unsloth` 依赖项

   确保你位于已激活的 conda/mamba 环境中。你应该会在终端提示符前看到你的环境名称作为前缀，像这样你的 `(unsloth-blackwell)user@machine:`

   ```bash
   pip install unsloth unsloth_zoo bitsandbytes
   ```
4. 下载并构建 `xformers` （可选）

   Xformers 是可选的，但它确实更快且更省内存。如果你不想使用 Xformers，我们会使用 PyTorch 原生的 SDPA。从源码构建 Xformers 可能会很慢，所以要小心！

   你应该会在终端提示符前看到你的环境名称作为前缀，像这样你的 `(unsloth-blackwell)user@machine:`

   ```bash
   # 先卸载之前库安装的 xformers
   pip uninstall xformers -y

   # 克隆并构建
   pip install ninja
   export TORCH_CUDA_ARCH_LIST="12.0"
   git clone --depth=1 https://github.com/facebookresearch/xformers --recursive
   cd xformers && python setup.py install && cd ..
   ```

   注意我们必须显式设置 `TORCH_CUDA_ARCH_LIST=12.0`.
5. `Transformers` 安装任意版本的 transformers，但最好使用最新版本。

   ```bash
   uv pip install -U transformers
   ```

如果你使用 mamba 作为你的包管理器，只需将上面所有命令中的 conda 替换为 mamba。

不要单独升级 `triton` 。每个 `torch` 版本都固定了其构建时使用的精确 `triton` 版本（其已支持 Blackwell），所以 `pip install -U triton` 会导致诸如 `torch ... requires triton==X, but you have triton Y which is incompatible`之类的错误。如果你已经这样做了，请安装错误中指定的版本，例如 `pip install "triton==3.7.1"`.

### WSL 特定说明

如果你正在使用 WSL（Windows Subsystem for Linux）并在 xformers 编译期间遇到问题（提醒一下，Xformers 是可选的，但训练时更快），请按照以下额外步骤：

1. **提高 WSL 内存限制** 创建或编辑 WSL 配置文件：

   ```bash
   # 在你的 Windows 用户目录中创建或编辑 .wslconfig
   #（通常是 C:\Users\YourUsername\.wslconfig）

   # 将这些行添加到文件中
   [wsl2]
   memory=16GB  # 建议 xformers 编译至少使用 16GB
   processors=4  # 根据你的 CPU 核心数调整
   swap=2GB
   localhostForwarding=true
   ```

   进行这些更改后，重启 WSL：

   ```powershell
   wsl --shutdown
   ```
2. **安装 xformers** 使用以下命令以针对 WSL 优化编译来安装 xformers：

   ```bash
   # 为 Blackwell GPU 设置 CUDA 架构
   export TORCH_CUDA_ARCH_LIST="12.0"

   # 使用优化的构建标志从源码安装 xformers
   pip install -v --no-build-isolation -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers
   ```

   “ `--no-build-isolation` 标志有助于避免 WSL 环境中的潜在构建问题。


---

# 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/bo-ke/fine-tuning-llms-with-blackwell-rtx-50-series-and-unsloth.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.
