> 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

Unsloth 现在支持 NVIDIA 的 Blackwell 架构 GPU，包括 RTX 50 系列 GPU（5060–5090）、RTX PRO 6000，以及 B200、B40、GB100、GB102 等 GPU！你可以在这里阅读官方 [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. 更新 `triton`

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

   ```bash
   pip install -U "triton>=3.3.1"
   ```

   `triton>=3.3.1` 是 `Blackwell` 支持所必需的。
6. `Transformers` 安装任意版本的 transformers，但最好获取最新版本。

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

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

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