> 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/mo-xing/tutorials/qwen-image-2512.md).

# 如何在 ComfyUI 中本地运行 Qwen-Image-2512

在你的本地设备上使用 ComfyUI 运行 Qwen-Image-2512 的分步教程。

**Qwen-Image-2512** 是 Qwen 的文本生成图像基础模型在 12 月的更新版。该模型是表现最好的开源扩散模型，本指南将教你如何通过以下方式在本地运行它 [Unsloth](https://github.com/unslothai/unsloth) GGUF 和 ComfyUI。

Qwen-Image-2512 特性：人物外观更真实；风景/纹理细节更丰富；文本渲染更准确。 **上传：** [GGUF](https://huggingface.co/unsloth/Qwen-Image-2512-GGUF) • [FP8](https://huggingface.co/unsloth/Qwen-Image-2512-FP8) • [4 位 BnB](https://huggingface.co/unsloth/Qwen-Image-2512-unsloth-bnb-4bit)

这些量化版本使用 [Unsloth Dynamic](/docs/zh/ji-chu-zhi-shi/dynamic-3.0-ggufs.md) 一种方法，会将重要层提升到更高精度以恢复更多准确性。感谢 Qwen 允许 Unsloth 在第 0 天提供支持。

## 📖 ComfyUI 教程

运行时，你不需要 GPU，只要有带 RAM 的 CPU 就可以。为了获得最佳效果，请确保你的总可用内存（RAM + VRAM / 统一内存）大于 GGUF 大小；例如 4 位（Q4\_K\_M） `unsloth/Qwen-Image-Edit-2512-GGUF` 是 13.1 GB，所以你应该有 13.2 GB 以上的总内存。

[ComfyUI](https://github.com/Comfy-Org/ComfyUI) 是一个开源扩散模型 GUI、API 和后端，使用基于节点（图/流程图）的界面。本指南将重点介绍带有 CUDA 的机器，但在 Apple 或 CPU 上构建的说明也类似。

### #1. 安装与设置

要安装 ComfyUI，你可以在 Windows 或 Mac 设备上下载桌面应用 [这里](https://www.comfy.org/download)。否则，要为运行 GGUF 模型设置 ComfyUI，请运行以下命令：

```bash
mkdir comfy_ggufs
cd comfy_ggufs
python -m venv .venv
source .venv/bin/activate

git clone https://github.com/Comfy-Org/ComfyUI.git
cd ComfyUI
pip install -r requirements.txt

cd custom_nodes
git clone https://github.com/city96/ComfyUI-GGUF
cd ComfyUI-GGUF
pip install -r requirements.txt
cd ../..
```

### #2. 下载模型

扩散模型通常需要 3 个模型：将图像像素空间编码到潜空间的变分自编码器（VAE）、将文本转换为输入嵌入的文本编码器，以及真正的扩散变换器。你可以在我们的 [合集这里找到](https://huggingface.co/collections/unsloth/unsloth-diffusion-ggufs).

扩散模型和文本编码器都可以采用 GGUF 格式，而 VAE 通常使用 safetensors。根据 [Qwen 的仓库](https://huggingface.co/Qwen/Qwen-Image-2512/blob/main/text_encoder/config.json)，我们将使用 Qwen2.5-VL，而不是 [Qwen3-VL](/docs/zh/mo-xing/tutorials/qwen3-how-to-run-and-fine-tune/qwen3-vl-how-to-run-and-fine-tune.md)。让我们下载将要使用的模型（注意：你也可以在 ComfyUI 中使用我们的 [FP8 上传版本](https://huggingface.co/unsloth/Qwen-Image-2512-FP8) ）：

```bash
cd models

## 扩散模型
curl -L -C - -o unet/qwen-image-2512-Q4_K_M.gguf \\
  https://huggingface.co/unsloth/Qwen-Image-2512-GGUF/resolve/main/qwen-image-2512-Q4_K_M.gguf
curl -L -C - -o unet/qwen-image-edit-2511-Q4_K_M.gguf \\
  https://huggingface.co/unsloth/Qwen-Image-Edit-2511-GGUF/resolve/main/qwen-image-edit-2511-Q4_K_M.gguf
 
## 文本编码器 + 视觉塔 + VAE   
curl -L -C - -o text_encoders/Qwen2.5-VL-7B-Instruct-UD-Q4_K_XL.gguf \\
  https://huggingface.co/unsloth/Qwen2.5-VL-7B-Instruct-GGUF/resolve/main/Qwen2.5-VL-7B-Instruct-UD-Q4_K_XL.gguf
curl -L -C - -o text_encoders/Qwen2.5-VL-7B-Instruct-mmproj-BF16.gguf \\
  https://huggingface.co/unsloth/Qwen2.5-VL-7B-Instruct-GGUF/resolve/main/mmproj-BF16.gguf
curl -L -C - -o vae/qwen_image_vae.safetensors \\
  https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/vae/qwen_image_vae.safetensors
```

请查看以下 GGUF 上传版本： [Qwen-Image-2512](https://huggingface.co/unsloth/Qwen-Image-2512-GGUF), [Qwen-Image-Edit-2511](https://huggingface.co/unsloth/Qwen-Image-Edit-2511-GGUF)，以及 [Qwen-Image-Layered](https://huggingface.co/unsloth/Qwen-Image-Layered-GGUF)

{% hint style="warning" %}
如果使用上面以外的检查点，vae 和扩散模型的格式可能与 diffusers 检查点不同。只使用与 ComfyUI 兼容的检查点。
{% endhint %}

这些文件必须位于正确的文件夹中，ComfyUI 才能识别它们。此外，存储在 mmproj 文件中的视觉塔必须使用与文本编码器相同的前缀。

也下载稍后要用到的参考图像：

```bash
curl -L -C - -o ../input/sloth1.jpg \\
    "https://unsloth.ai/cgi/image/_1d5a5685-2d88-44ca-b50f-ba432cd646ef_9CGCY8lvw4D9JkOdueqsk.jpeg?width=1920&quality=80&format=jpeg"

curl -L -C - -o ../input/sloth2.jpg \\
    "https://unsloth.ai/cgi/image/UnSloth_GPU_Front_-_Confetti_ArcSk-MR4MMN215UutOFZ.png?width=1920&quality=80&format=jpeg"
```

### #3. 工作流与超参数

更多信息也可以查看我们详细的 [Run GGUFs in ComfyUI](/docs/zh/bo-ke/comfyui.md#workflow-and-hyperparameters-1) 指南。

进入 ComfyUI 主目录并运行：

```bash
python main.py
```

{% hint style="info" %}
`python main.py --cpu` 可使用 CPU 运行，但会很慢。
{% endhint %}

这将启动一个网页服务器，让你可以访问 `https://127.0.0.1:8188` 。如果你在云端运行，需要确保已设置端口转发，才能在本地机器上访问。

工作流会作为 JSON 文件保存，嵌入在输出图像中（PNG 元数据），或者作为单独的 `.json` 文件。你可以：

* 将图像拖放到 ComfyUI 中以加载其工作流
* 通过菜单导出/导入工作流
* 将工作流共享为 JSON 文件

下面是两个可下载并使用的 Qwen-Image-2512 和 Qwen-Image-Edit-2511 json 文件示例：

{% file src="/files/ad09cd1029a0d8c31e363d7884a3f6cbefc5cf9b" %}

对于我们的工作流，我们默认使用 **1024×1024** 作为一个实用的中间值。虽然该模型支持原生分辨率（1328×1328），但以原生分辨率生成通常会使运行时间增加 **\~50%**。由于 GGUF 会增加开销，而且 40 步 已经算是较长的运行时间，1024×1024 能让生成时间保持在合理范围内。如有需要，你可以把分辨率提高到 1328。

{% hint style="warning" %}
为了获得更真实的结果，跳过诸如“photorealistic”或“digital rendering”或“3d render”之类的关键词，改用“photograph”等词。
{% endhint %}

{% hint style="info" %}
对于负面提示，最好采用 NLP 风格的方法：用 **自然语言** 描述你 *不* 想要图像中出现的内容。堆砌过多关键词反而会损害结果，而不是让它更具体。
{% endhint %}

{% file src="/files/5746a7311e0dd2def1c708a7984930b38e0d5f7d" %}

{% columns %}
{% column %}
与其从头设置工作流，不如直接在这里下载工作流。

点击 Comfy 标志 -> File -> Open -> 然后选择 `unsloth_qwen_image_2512.json` 你刚下载的文件，将其加载到浏览器页面中。它应该如下所示：
{% endcolumn %}

{% column %}

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FqoxBnRlnYrmzLfZshE1Z%2FScreenshot%20from%202025-12-29%2014-37-00.png?alt=media&amp;token=1b1517b7-d44f-4e95-a5ed-759a4e0f74ec" alt="" width="254"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FIg48mzpraPTu1O16X1ay%2FScreenshot%20from%202025-12-30%2015-27-35.png?alt=media&amp;token=c761e48a-18cd-4291-9f29-3c09f621729d" alt="" width="563"><figcaption></figcaption></figure>

这个工作流基于 ComfyUI 官方发布的工作流，只是使用了 GGUF 加载器扩展，并进行了简化，以演示文本生成图像功能。&#x20;

### #4. 推理

ComfyUI 具有高度可定制性。你可以混合模型并创建极其复杂的管线。对于基础的文本生成图像设置，我们需要加载模型、指定提示词和图像细节，并决定采样策略。&#x20;

#### **上传模型 + 设置提示词**

我们已经下载了模型，所以只需要选择正确的模型即可。对于 Unet Loader 请选择 `qwen-image-2512-Q4_K_M.gguf`，对于 CLIPLoader 请选择 `Qwen2.5-VL-7B-Instruct-UD-Q4_K_XL.gguf`，对于 Load VAE 请选择 `qwen_image_vae.safetensors`.&#x20;

{% hint style="info" %}
为了获得更真实的结果，跳过诸如“photorealistic”或“digital rendering”或“3d render”之类的关键词，改用“photograph”等词。
{% endhint %}

你可以设置任何你喜欢的提示词，也可以指定负面提示词。负面提示词通过告诉模型应该避开什么来提供帮助。

{% hint style="info" %}
对于负面提示，最好采用 NLP 风格的方法：用 **自然语言** 描述你 *不* 想要图像中出现的内容。堆砌过多关键词反而会损害结果，而不是让它更具体。
{% endhint %}

#### **图像尺寸 + 采样器参数**

Qwen 图像模型系列支持不同的图像尺寸。你可以通过设置宽度和高度的值来生成矩形形状。对于采样器参数，你可以尝试除 euler 之外的其他采样器，以及更多或更少的采样步数。工作流的步数设置为 40，但对于快速测试，20 步可能就足够了。将 `生成后控制` 设置从随机化改为固定，如果你想查看不同设置如何改变输出。

#### **运行**

点击运行，大约 1 分钟后就会生成一张图像（20 步大约 30 秒）。生成的图像可以保存。有趣的是，整个 comfy 工作流的元数据都保存在图像中。你可以分享它，任何人都能通过在 UI 中加载它来查看它是如何创建的。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F3fvZ7Y7dyOwwWfQXP4U9%2Funsloth_woman.png?alt=media&amp;token=bf131b12-be85-45c9-83bb-6a087decb8bb" alt="" width="188"><figcaption></figcaption></figure>

{% hint style="info" %}
如果你遇到模糊/效果差的图像，把 shift 提高到 12-13！这能解决大多数糟糕输出问题。
{% endhint %}

#### **多参考图像生成**

Qwen-Image-Edit-2511 的一个关键特性是多参考图像生成，你可以提供多张图像来帮助控制生成。这次请加载 `unsloth_qwen_image_edit_2511.json`。我们将使用大多数相同的模型，但把 `qwen-image-2512-Q4_K_M.gguf` 改为 `qwen-image-edit-2511-Q4_K_M.gguf` 替换为 unet。另一个不同之处是这次会额外添加用于选择参考图像的节点，这些图像我们之前已经下载好了。你会注意到提示词同时提到 `图像 1` 和 `图像 2` 它们是图像的提示锚点。加载完成后点击运行，你会看到一个输出，将我们两个独特的树懒角色保留其外貌特征地一起生成出来。

<div><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FmHqctMHBGGtyTMh7VcxN%2Funsloth_diffusion1.png?alt=media&amp;token=c66059ae-4015-4fea-9181-75566bc7f03d" alt="" width="188"><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%2FvRbCNdlnmXOyM84YaF0b%2Fsloth%20gpu%20square.png?alt=media&amp;token=7b5c14ae-b5d7-4554-86e5-f8e2480bbb39" alt="" width="188"><figcaption></figcaption></figure> <figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FwAYdYspdgZGbxFePXf06%2Fsloth%20on%20gpu.jpg?alt=media&amp;token=1031686f-1f0d-423a-80ae-77127aaaa0bd" alt="" width="188"><figcaption></figcaption></figure></div>

## 🤗 D**iffusers 教程**

我们还上传了一个 [动态 4 位 BitsandBytes](https://huggingface.co/unsloth/Qwen-Image-2512-unsloth-bnb-4bit) 量化版本，可在 Hugging Face 的 `diffusers` 库中运行。与之前一样，它使用 Unsloth Dynamic，会将重要层上转到更高精度。

运行 `Qwen-Image-2512-unsloth-bnb-4bit` 以及下面的代码：

```python
from diffusers import DiffusionPipeline
import torch

pipe = DiffusionPipeline.from_pretrained(
    "unsloth/Qwen-Image-2512-unsloth-bnb-4bit",
    torch_dtype=torch.bfloat16,
).to('cuda')

# 如果内存不足，请取消注释
# pipe.enable_model_cpu_offload() 

output = pipe(
    prompt="一只可爱的树懒在打鼓",
    negative_prompt="模糊，未对焦",
    num_inference_steps=20,
    true_cfg_scale=4.0,
)

# 保存输出
image = output.images[0]
image.save('sample.png')
```

## 🎨 **stable-diffusion.cpp 教程**

如果你想在 stable-diffusion.cpp 中运行模型，可以参考我们的 [此处的分步指南](/docs/zh/mo-xing/tutorials/qwen-image-2512/stable-diffusion.cpp.md).


---

# 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/mo-xing/tutorials/qwen-image-2512.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.
