> 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/ji-chu-zhi-shi/diffusion-image.md).

# 如何使用 Unsloth 在本地运行图像扩散模型

无需编写代码，即可在本地生成和编辑 AI 图像。Unsloth 支持 [FLUX.3 Image Klein](https://unsloth.ai/docs/zh/mo-xing/flux-3.md), [MiniMax-H3-Image](https://unsloth.ai/docs/zh/mo-xing/minimax-h3-image.md), [Qwen-Image-2.1](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1.md) 和 [Qwen-Image-2.1-Turbo](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1/qwen-image-2.1-turbo.md)，以及 Z-Image、FLUX.1 和 SDXL。你可以从提示词或图像开始，然后使用相应模型支持的生成、编辑、参考图像和 LoRA 工作流。

### 图像示例

以下是各指南中的实际生成结果，按图像模型分组。打开模型指南，查看提示词、设置和硬件说明；这些只是示例，并非受控的质量比较。

#### FLUX.3 Image Klein

[运行和微调 FLUX.3 Image Klein →](https://unsloth.ai/docs/zh/mo-xing/flux-3.md)

<div><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FAUr9I8myeHeT9jCPPdV3%2Fflux-3-image-klein-out-bison.webp?alt=media" alt="A bison in a misty geothermal landscape at dawn"><figcaption><p>GGUF UD-Q4_K_XL</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fv7aDDYG13wwm4n2gTUCX%2Fflux-3-image-klein-out-cafe.webp?alt=media" alt="A chalkboard sign that reads Unsloth Coffee outside a cafe"><figcaption><p>FP8 仓库，bf16</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpqnjARNGI1y6IQ7dB6k5%2Fflux-3-image-klein-out-robot.webp?alt=media" alt="A small knitted robot next to a houseplant on a windowsill"><figcaption><p>FP8 仓库，INT8</p></figcaption></figure></div>

#### MiniMax-H3-Image

[运行和微调 MiniMax-H3-Image →](https://unsloth.ai/docs/zh/mo-xing/minimax-h3-image.md)

<div><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FdhaLehHOWudDk9TmHJfW%2Fminimax-h3-image-out-valley.webp?alt=media" alt="Misty autumn valley with a wooden footbridge"><figcaption><p>FP8 仓库（INT8）</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FE5iZZZi5oMaVw4Jo3ViS%2Fminimax-h3-image-out-island.webp?alt=media" alt="Isometric floating island city"><figcaption><p>FP8 仓库（INT8）</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FQ8V3wLPL9YacqR4YD5LK%2Fminimax-h3-image-out-ramen.webp?alt=media" alt="Overhead photo of ramen"><figcaption><p>GGUF UD-Q4_K_XL</p></figcaption></figure></div>

#### Qwen-Image-2.1

[运行和微调 Qwen-Image-2.1 →](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1.md)

<div><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F4aoR0eG610P5o96qSn3O%2Fqwen-image-2.1-out-cafe.webp?alt=media" alt="Barista pouring latte art"><figcaption><p>“阳光明媚的极简咖啡馆里，咖啡师正在拉花，晨光，编辑风格摄影”</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FxjemXJe6MtuxE57IK3bK%2Fqwen-image-2.1-out-astronaut.webp?alt=media" alt="Astronaut on a frozen lake"><figcaption><p>“孤独的宇航员穿越冰封湖面，巨大的环形行星悬挂在天空中，蓝色暮光，电影感”</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpVRGxtjLmheo2ahNAmnd%2Fqwen-image-2.1-out-market.webp?alt=media" alt="Watercolor flower market by a canal"><figcaption><p>“阿姆斯特丹运河边的花市水彩画，柔和的春日色彩”</p></figcaption></figure></div>

#### Qwen-Image-2.1-Turbo

[运行 Qwen-Image-2.1-Turbo →](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1/qwen-image-2.1-turbo.md)

<div><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fa5teZGDbqQn7KJGSDa3P%2Fqwen-image-2.1-turbo-out-ramen.webp?alt=media" alt="Neon ramen shop"><figcaption><p>“雨夜东京小巷中霓虹闪烁的拉面店，湿漉漉的路面倒映着灯光，电影感摄影”（Q4_K_M，13 秒）</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FeUgMrARGjaBd9HfVYBNW%2Fqwen-image-2.1-turbo-out-bee.webp?alt=media" alt="Honeybee on a sunflower"><figcaption><p>“向日葵上的蜜蜂微距照片，花粉颗粒清晰可见，细节极其丰富”（Q4_K_M，13 秒）</p></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FOoLevkElFI5ptCbyzKsM%2Fqwen-image-2.1-turbo-out-island.webp?alt=media" alt="Isometric lighthouse island"><figcaption><p>“等距 3D 插画：一座带灯塔的袖珍岛屿，柔和的色彩，轻柔的阴影”（FP8 仓库，7 秒）</p></figcaption></figure></div>

想了解视频生成？ [MiniMax-H3](https://unsloth.ai/docs/zh/mo-xing/minimax-h3.md) 是一个独立的视频和音频模型，并非 MiniMax-H3-Image。请访问“视频”页面并查看专用指南。LTX 也是视频模型。

要创建图像 LoRA，请训练以下受支持的基础模型： [FLUX.3 Klein Base](https://unsloth.ai/docs/zh/mo-xing/flux-3.md#train-a-lora), [Qwen-Image-2.1](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1.md#train-a-lora) 或 [MiniMax-H3-Image](https://unsloth.ai/docs/zh/mo-xing/minimax-h3-image.md#train-a-lora)。Qwen-Image-2.1 LoRA 可在 Turbo 上运行；Turbo 本身不能作为训练基础模型。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FGg2Q8Jd4doV8TVHuEbdL%2Fflux-3-image-klein-flow.webp?alt=media" alt="Animation: pick FLUX.3 Image Klein (Fast FP8), type a prompt, click Generate and get a lighthouse on a cliff"><figcaption><p>FLUX.3 Image Klein：选择模型，输入提示词并生成。加速演示。</p></figcaption></figure>

### ⚡ 快速入门

{% stepper %}
{% step %}

### **安装或更新**

桌面应用是最简单的入门方式。

<a href="https://unsloth.ai/download" class="button primary" data-icon="down-to-bracket">下载 Unsloth Desktop</a>

按照安装程序的指引操作，然后从应用程序中打开该应用。如果已经安装，请先确认已更新至最新版本，再继续操作。

**命令行**

更喜欢使用终端？请运行适用于你操作系统的命令。使用相同命令也可以更新现有安装。

**macOS、Linux、WSL：**

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

**Windows PowerShell：**

```powershell
irm https://unsloth.ai/install.ps1 | iex
```

#### 启动 Unsloth

安装完成后，启动 Unsloth：

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

打开 `http://localhost:8888` 如果它没有自动打开。
{% endstep %}

{% step %}

### 打开图像

从侧边栏中选择 **图像** 。 **创建** 工作流默认会打开。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F8VA0qli15m452CIo2DeL%2Fflux-3-image-klein-images-page.png?alt=media" alt="The Unsloth Images page with the Create workflow open and no model loaded"><figcaption><p>加载模型前，依次点击“图像”→“创建”。</p></figcaption></figure>

现在，我们可以进入下一步了。
{% endstep %}

{% step %}

### 选择模型

打开“选择图像模型”，搜索 FLUX.3 Image Klein、MiniMax-H3-Image、Qwen-Image-2.1 或 Qwen-Image-2.1-Turbo。Klein 是较小的通用型选择；Turbo 使用 8 步。请查看模型指南，了解硬件和内存要求。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F7ld8GwJlyKwIf9n0WXy2%2Fflux-3-image-klein-picker-search.png?alt=media" alt="Model picker search results for flux-3-image-klein with the Fast FP8, GGUF and Base entries"><figcaption><p>搜索 FLUX.3：生成和编辑请选择 Klein，训练 LoRA 请选择 Klein Base。</p></figcaption></figure>

“ **推荐** ”选项卡是不错的起点。\
\
对于 GGUF 模型，适合您设备的尺寸也会标记为 **推荐**。运行可能较慢或无法装入内存的尺寸会标记为 **紧张** 或 **内存不足**.
{% endstep %}

{% step %}

### 输入提示词

描述您想生成的图像。

例如：

> 黄金时分，海岸悬崖上的灯塔

保留已加载模型的默认设置：Klein 使用 16 步和引导值 1；Qwen-Image-2.1 使用 25 步和引导值 1；Turbo 使用 8 步和引导值 1；MiniMax-H3-Image 使用 6 步且不使用 CFG。这些设置不能互换。Klein 和 MiniMax-H3-Image 还提供可单独下载的提示词增强器。
{% endstep %}

{% step %}

### 生成您的第一张图像

选择 **生成**。首次生成时，模型需要下载并加载，因此可能会花费更长时间。

生成结果会显示在图库中，您可以查看其设置或下载图像。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FYBY7Z8KuulG11IHwzyEa%2Fflux-3-image-klein-result.png?alt=media" alt="Finished image of a lighthouse on a rocky coast at sunset, with the enhanced prompt on the left"><figcaption><p>使用灯塔提示词和提示词增强器生成的 FLUX.3 Image Klein 结果。</p></figcaption></figure>
{% endstep %}
{% endstepper %}

### ⭐ 功能

可用的工作流取决于您加载的模型。不受支持的工作流会自动隐藏。

#### 创建和编辑图像

* **创建：** 根据文本提示词生成图像。
* **转换：** 以现有图像为起点生成新图像。
* **局部重绘：** 选择图像的一部分并重新生成。
* **扩展：** 在原始画布范围之外生成内容。
* **放大：** 提高图像分辨率。
* **参考：** 使用一张或多张参考图像来引导生成。
* **编辑：** 描述你想对图像进行的更改。

以下模型支持基于指令的编辑： [FLUX.3 Image Klein](https://unsloth.ai/docs/zh/mo-xing/flux-3.md#image-editing), [MiniMax-H3-Image](https://unsloth.ai/docs/zh/mo-xing/minimax-h3-image.md#image-editing), [Qwen-Image-2.1](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1.md#image-editing) 和 [Turbo](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1/qwen-image-2.1-turbo.md#image-editing)，此外还有 Qwen-Image-Edit 和 FLUX.1 Kontext。请参阅模型指南，了解参考图像数量限制和输出尺寸。

#### LoRA 和 ControlNet

加载兼容的 LoRA，为生成结果添加角色、主体或视觉风格。调整 LoRA 权重，以控制其对结果的影响程度。

受支持的模型还可以使用 ControlNet 来引导图像结构。调整其强度，以控制结果与引导图像的契合程度。

#### 图库

生成的图像会保存到本地图库。打开结果即可查看其提示词和设置；选择 **配方** 可还原其生成设置，或下载图像。

### 支持的模型和工作流

| 模型                   | 工作流和详细指南                                                                                                                                       |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| FLUX.3 Image Klein   | [FLUX.3 指南](https://unsloth.ai/docs/zh/mo-xing/flux-3.md)：创建和编辑；16 步，guidance 为 1。使用 Klein Base 训练 LoRA。                                       |
| MiniMax-H3-Image     | [MiniMax-H3-Image 指南](https://unsloth.ai/docs/zh/mo-xing/minimax-h3-image.md)：创建和编辑，最多支持 16 张参考图；6 步，无 CFG，画布为 2048 × 2048。请查看其大型模型的内存需求。      |
| Qwen-Image-2.1       | [Qwen-Image-2.1 指南](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1.md)：创建和编辑，原生支持 2K，最多支持 10 张参考图；25 步，guidance 为 1。使用此基础模型训练 Qwen 图像 LoRA。 |
| Qwen-Image-2.1-Turbo | [Turbo 指南](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1/qwen-image-2.1-turbo.md)：8 步即可创建和编辑，guidance 为 1。内存需求与基础模型相同，并非更小的模型。             |
| 其他图像系列               | Z-Image、FLUX.1、FLUX.2 klein 和 SDXL 仍可使用。变换、局部重绘、扩展、放大和 ControlNet 功能因模型而异。                                                                     |

Fast FP8 表示选择器中的一个条目，并不保证每个组件都以 FP8 运行。Auto 可能会选择其他受支持的精度；Qwen 和 MiniMax-H3-Image 通常会以 INT8-ConvRot 加载。在支持的情况下，也可使用 GGUF，包括在 Mac 和 CPU 上运行。请查看各指南中经过测试的配置，不要将文件大小或内存估算视为有保证的最低要求。

#### 当前图像工作流

这些截图来自各模型的专属指南；不同模型的设置不可互换。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FJDkNG5C6ikli5XD6lIpx%2Fminimax-h3-image-result.png?alt=media" alt="Ginger cat asleep on books in a rainy bookshop window"><figcaption><p>MiniMax-H3-Image 生成与图库。内存需求请参阅其指南。</p></figcaption></figure>

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FE4WmS2aVmN1x1uB7Vsi4%2Fqwen-image-2.1-edit.png?alt=media" alt="Edit at 2048 with result"><figcaption><p>Qwen-Image-2.1 在 2048 分辨率下进行基于指令的编辑。</p></figcaption></figure>

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FStfTvPOPpHeJYXq5d81R%2Fqwen-image-2.1-turbo-result.png?alt=media" alt="Finished boathouse image and gallery"><figcaption><p>Qwen-Image-2.1-Turbo 生成与图库，采用其八步调度方案。</p></figcaption></figure>

#### 视频是独立的工作流

[MiniMax-H3 视频指南](https://unsloth.ai/docs/zh/mo-xing/minimax-h3.md) 介绍带声音的视频生成和视频 LoRA 训练。请打开“视频”页面，不要在图像模型选择器中选择 MiniMax-H3。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FqCq3GkDxVruGcu5LGHPi%2Fminimax-h3-video-page.png?alt=media" alt="The Unsloth Video page with the Create tab open and no model loaded"><figcaption><p>MiniMax-H3 使用独立的“视频”页面，而非“图像”工作流。</p></figcaption></figure>

### 生成设置

默认设置是很好的起点。不过，你也可以调整设置以获得最佳结果。以下是你可能需要更改的主要参数：

| 设置          | 作用                                   |
| ----------- | ------------------------------------ |
| **提示词**     | 描述你想创建的图像。在 **编辑**模式下，它会变成需要遵循的指令。   |
| **宽高比和分辨率** | 设置图像的形状和尺寸。图像越大，内存占用越多，生成时间也越长。      |
| **步数**      | 控制模型生成图像所用的迭代步数。步数越多，结果不一定越好。        |
| **引导强度**    | 控制提示词对生成结果的引导力度。某些模型在以下设置下效果最佳： `0`. |
| **随机种子**    | 帮助复现生成结果。留空则使用随机种子。                  |

<details>

<summary>高级生成设置</summary>

这些选项会影响模型在设备上的运行方式。调整它们可以减少内存占用、提升性能或排查生成问题。

| 设置          | 作用                                               |
| ----------- | ------------------------------------------------ |
| **速度**      | 控制编译和性能优化。编译模式可能会延长首次生成的耗时。                      |
| **精度**      | 更改运行模型时使用的数值格式。较低的精度可以减少内存占用。可用选项取决于模型和硬件。       |
| **注意力机制**   | 选择生成过程中使用的注意力实现。                                 |
| **内存**      | 平衡生成速度与 GPU 内存占用。如果模型的内存需求接近设备上限，请尝试使用 **低显存** 。 |
| **步骤缓存**    | 在扩散步骤之间复用部分计算结果，以提升生成速度。                         |
| **卸载到 CPU** | 将模型的部分内容移至系统内存。这可以减少 GPU 内存占用，但可能会降低生成速度。        |

</details>

### ⚠️ 故障排除

<details>

<summary>图像未显示</summary>

更新到最新版本，然后重启应用。请参阅 [更新 Unsloth](https://unsloth.ai/docs/get-started/install/updating) 了解操作说明。

</details>

<details>

<summary>模型无法下载或加载</summary>

某些图像模型体积较大，下载需要一些时间。请确认有足够的可用存储空间，并且网络连接稳定。

某些模型还要求你先在 Hugging Face 上接受其许可协议，并添加 Hugging Face 令牌，然后才能下载。

</details>

<details>

<summary>模型内存不足</summary>

尝试使用更小的 GGUF 量化版本或模型的 4 位版本。对于 GGUF 模型，请先选择标记为 **推荐**.

你还可以：

* 降低图像分辨率。
* 将批次大小保持为 `1`.
* 关闭其他正在使用 GPU 的应用程序。
* 选择更小的模型。

标记为 **紧张** 的模型可能会占用系统内存，运行速度也会较慢。标记为 **OOM** 的模型很可能无法装入内存。

</details>

<details>

<summary>缺少工作流</summary>

可用工作流取决于已加载的模型。不受支持的工作流不会显示。

如需基于指令进行编辑，请加载 FLUX.3 Image Klein、MiniMax-H3-Image、Qwen-Image-2.1 或 Turbo，然后选择“编辑”。其他工作流仍取决于模型。

</details>

### ❓ 常见问题

<details>

<summary>图像生成是在本地运行吗？</summary>

是的。模型下载完成后，图像生成会在你的设备上运行。

</details>

<details>

<summary>“转换”和“编辑”有什么区别？</summary>

**转换** 会根据描述完整结果的提示词，重新绘制现有图像。

**编辑** 遵循诸如更改背景或添加对象之类的指令。这需要兼容的编辑模型。

</details>

<details>

<summary>我可以训练自己的图像 LoRA 吗？</summary>

可以。使用自己的图像微调受支持的模型，然后在以下位置加载训练完成的 LoRA： **创建**.

请参阅 [FLUX.3 Klein Base 训练](https://unsloth.ai/docs/zh/mo-xing/flux-3.md#train-a-lora), [Qwen-Image-2.1 训练](https://unsloth.ai/docs/zh/mo-xing/qwen-image-2.1.md#train-a-lora) 或 [MiniMax-H3-Image 训练](https://unsloth.ai/docs/zh/mo-xing/minimax-h3-image.md#train-a-lora) 了解硬件、数据集和部署相关信息。支持的 NVIDIA 和 AMD 配置因系列而异。

</details>


---

# 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/ji-chu-zhi-shi/diffusion-image.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.
