# 使用 Unsloth 进行多 GPU 微调

Unsloth 当前通过 Accelerate 和 DeepSpeed 等库支持多 GPU 配置。这意味着您已经可以利用诸如 **FSDP** 和 **DDP** 与 Unsloth 一起使用。

#### **请参阅我们新的分布式数据并行** [**（DDP）多 GPU 指南在此处**](https://unsloth.ai/docs/zh/ji-chu/multi-gpu-training-with-unsloth/ddp)**.**

我们知道这个过程可能很复杂并且需要手动设置。我们正在努力使多 GPU 支持更简单、更易用，并且我们会很快宣布 Unsloth 的官方多 GPU 支持。

目前，您可以使用我们的 [Magistral-2509 Kaggle 笔记本](https://unsloth.ai/docs/zh/mo-xing/tutorials/magistral-how-to-run-and-fine-tune#fine-tuning-magistral-with-unsloth) 作为示例，该示例利用多 GPU Unsloth 来适配 24B 参数模型，或者使用我们的 [DDP 指南](https://unsloth.ai/docs/zh/ji-chu/multi-gpu-training-with-unsloth/ddp).

**同时**，要为 DDP 启用多 GPU，请执行以下操作：

1. 将您的训练脚本创建为 `train.py` （或类似文件）。例如，您可以使用我们的一份 [训练脚本](https://github.com/unslothai/notebooks/tree/main/python_scripts) 从我们各种笔记本创建的！
2. 运行 `accelerate launch train.py` 或 `torchrun --nproc_per_node N_GPUS train.py` 其中 `N_GPUS` 是您拥有的 GPU 数量。

#### **流水线 / 模型切分加载**

如果您没有足够的显存让单个 GPU 加载比如 Llama 70B，不用担心——我们会在每个 GPU 上为您切分模型！要启用此功能，请使用 `device_map = "balanced"` 标志：

```python
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
    "unsloth/Llama-3.3-70B-Instruct",
    load_in_4bit = True,
    device_map = "balanced",
)
```

**敬请关注我们的官方公告！**\
欲了解更多细节，请查看我们正在进行的 [拉取请求](https://github.com/unslothai/unsloth/issues/2435) 讨论多 GPU 支持。


---

# 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/ji-chu/multi-gpu-training-with-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.
