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

**Qwen-Image-2512** 是 对 Qwen 文本到图像基础模型的十二月更新。该模型是表现最好的开源扩散模型，本指南将教你如何通过 [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 位 BitsandBytes](https://huggingface.co/unsloth/Qwen-Image-2512-unsloth-bnb-4bit)

这些量化使用了 [Unsloth 动态](/docs/zh/ji-chu/unsloth-dynamic-2.0-ggufs.md) 方法，它将重要层提升到更高精度以恢复更多准确性。感谢 Qwen 允许 Unsloth 在第 0 天提供支持。

## 📖 ComfyUI 教程

运行时不需要 GPU，只需有内存的 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）将图像像素空间编码到潜在空间，一个文本编码器将文本翻译为输入嵌入，以及实际的扩散 transformer。你可以在我们的 [合集在此](https://huggingface.co/collections/unsloth/unsloth-diffusion-ggufs).

找到所有 Unsloth 扩散 GGUF。扩散模型和文本编码器都可以是 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 %}

这将启动一个允许你访问的 Web 服务器 `https://127.0.0.1:8188` 。如果你在云上运行此服务，需要确保设置端口转发以便在本地机器上访问。

工作流程作为嵌入在输出图像（PNG 元数据）中的 JSON 文件或作为单独的 `.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" %}
对于反向提示（negative prompts），最好使用 NLP 风格的方法：用 **自然语言** 描述你 *不* 希望出现在图像中的内容。塞入过多关键字可能会损害结果，而不是使其更具体。
{% endhint %}

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

{% columns %}
{% column %}
你可以不从头设置工作流程，而是从这里下载工作流程。

通过点击 Comfy 徽标 -> 文件 -> 打开 -> 然后选择你刚下载的 `unsloth_qwen_image_2512.json` 文件将其加载到浏览器页面。它应该看起来像下面这样：
{% endcolumn %}

{% column %}

<figure><img src="/files/b207b9ea3fa00d87bb21604efc62fc2f8f31a0b4" alt="" width="254"><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

<figure><img src="/files/a88e0b28a8b25a344ef25112d3ecf48d9ef2e0c5" 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" %}
对于反向提示（negative prompts），最好使用 NLP 风格的方法：用 **自然语言** 描述你 *不* 希望出现在图像中的内容。塞入过多关键字可能会损害结果，而不是使其更具体。
{% endhint %}

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

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

#### **运行**

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

<figure><img src="/files/eacc2ded23cccb7bdb5512b85ac6340cfa089897" 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="/files/78c736c35db61c093a75b1114742eae31ab19e36" alt="" width="188"><figcaption><p>右侧图像生成的最终结果：</p></figcaption></figure> <figure><img src="/files/9a4011b7c4167e81374c547ee7668218c1df6f3c" alt="" width="188"><figcaption></figcaption></figure> <figure><img src="/files/9e5f17430fa41eeb4cf14416ad5533966dfc5250" 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 动态方法，将重要层提升到更高精度。

运行 `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: 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/mo-xing/tutorials/qwen-image-2512.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.
