Skip to content

Qwen-Image-2.1 本地部署、MCP 智能体接入与运行复用指南

Updated:
Edit page

本文档记录了在 Windows 环境(NVIDIA GeForce RTX 2070 SUPER 8GB 显存 + 32GB 物理内存)下,成功部署阿里通义千问最新旗舰级图像生成模型 Qwen-Image-2.1,接入 ComfyUI 官方 MCP 智能体协议,并配置全套官方工作流、方案 B 无审查去限制架构 以及 方案 C 提示词扩写(LM Studio 极速协同与直通选配) 的完整工程落地手册与实测数据。


📌 目录导航


一、 硬件与环境基准


二、 架构解析与低显存运行核心机理

1. 为什么该模型无法在常规自回归工具中直接生图?

2. ComfyUI 能够流畅运行生图的技术关键


三、 官方模型文件清单与国内免代理下载规范

所有官方权重统一存放在 E:\ComfyUI_Files\models\ 对应子目录中:

模块类别权重文件名文件大小存放子目录
扩散主干 (DiT)qwen_image_2.1_int8_convrot.safetensors6.76 GBE:\ComfyUI_Files\models\diffusion_models\
文本/视觉编码器qwen3vl_8b_w4a8.safetensors5.88 GBE:\ComfyUI_Files\models\text_encoders\
图像解码器 (VAE)qwen_image_2.1_vae_bf16.safetensors0.63 GBE:\ComfyUI_Files\models\vae\

国内魔搭(ModelScope)免代理直连下载脚本

import os
from modelscope.hub.file_download import model_file_download

# 清除代理环境变量,直连国内极速节点
for k in ['HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy']:
    os.environ.pop(k, None)

cache_dir = r"E:\ComfyUI_Files\temp\modelscope_cache"
os.environ['MODELSCOPE_CACHE'] = cache_dir
models_dir = r"E:\ComfyUI_Files\models"

model_id = "Comfy-Org/Qwen-Image-2.1"
files = [
    "vae/qwen_image_2.1_vae_bf16.safetensors",
    "text_encoders/qwen3vl_8b_w4a8.safetensors",
    "diffusion_models/qwen_image_2.1_int8_convrot.safetensors"
]

for f in files:
    print(f"正在下载: {f}")
    model_file_download(model_id=model_id, file_path=f, cache_dir=cache_dir, local_dir=models_dir)
print("全部官方权重下载完成!")

四、 启动模式与性能优化

1. 无头后台模式(Headless Mode)

相比直接打开 Electron 桌面客户端(额外占用 300~500MB 显存用于 UI 渲染),无头模式直接启动 Python 后端服务,让 8GB 显卡将所有资源完全倾注在生成推理中。

一键启动脚本路径: E:\ComfyUI_Files\start_headless.bat

@echo off
title ComfyUI Headless Service (Qwen-Image-2.1)
set PYTHONUTF8=1
cd /d "D:\Comfy-Desktop\ComfyUI-Installs\ComfyUI\ComfyUI"
"E:\ComfyUI_Files\.venv\Scripts\python.exe" main.py --listen 127.0.0.1 --port 8000 --preview-method auto --output-directory "E:\ComfyUI_Files\output"
pause

2. 实时去噪预览(Latent Real-time Preview)

3. Turing 架构显卡加速避坑(关于 SageAttention)


五、 智能体 MCP 服务端配置 (Comfy-MCP)

通过 Model Context Protocol (MCP),智能体可以直接接管 ComfyUI,实现无界面自动化排队、改参、生图并抓取结果。

1. 配置文件路径

C:\Users\<User>\.gemini\config\mcp_config.json

2. 服务配置项

"comfyui": {
  "command": "D:\\python3.13.0\\python.exe",
  "args": [
    "-m",
    "comfy_mcp.server"
  ],
  "env": {
    "COMFYUI_URL": "http://127.0.0.1:8000"
  }
}

注:务必配置 COMFYUI_URL 为 http://127.0.0.1:8000,使之与 ComfyUI Desktop/Headless 默认端口精准对齐。


六、 官方三大核心工作流与调用标准

工作流 JSON 文件已保存于 E:\ComfyUI_Files\workflows\:

1. 文生图工作流 (Text-to-Image)

2. 图像编辑与多图参考工作流 (Image Edit & Multi-Ref)

3. 透明背景生成与抠图工作流 (Background Removal / RGBA)


七、 官方基准实测案例与画质效果对比

测试项目测试 1:东方美女网红咖啡馆生活照测试 2:火影忍者(漩涡鸣人)真人电影化编辑
测试类型文生图 (T2I)图生图多模态参考编辑 (Image Edit)
参考输入无naruto_ref.png 官方动漫头像
关键提示词A fashionable young Asian woman enjoying her afternoon at an aesthetically pleasing sunny cafe, wearing a cozy oversized oatmeal knit sweater, holding a ceramic latte cup, candid natural smile, warm sunlight casting gentle shadows, realistic skin texture with subtle pores, natural makeup…Transform the anime character in <image1> into a photorealistic cinematic live-action movie portrait, realistic blonde textured hair, hyper-detailed skin texture with subtle pores, realistic expressive blue eyes, wearing a detailed orange and black tactical shinobi jacket…
采样参数1024×1024, Steps=20, CFG=4.0, Euler+Simple1024×1024, Steps=20, CFG=2.5, Euler+Simple
单图总耗时~3 分 30 秒 (Text 18s + KSampler 185s + VAE 7s)~3 分 40 秒 (Vision Encode 22s + KSampler 190s + VAE 8s)
显存占用峰值4.85 GB / 8.0 GB (剩余 3.15 GB)5.12 GB / 8.0 GB (剩余 2.88 GB)
画质评价肤质极度写实、毛衣肌理与光影层次自然,完全无塑料感完美提取动漫角色发型、金发碧眼与木叶护额元素,写实转换自然
生成成果保存E:\ComfyUI_Files\output\QwenImage21_BeautyCafe_00001_.pngE:\ComfyUI_Files\output\QwenImage21_NarutoLiveAction_00001_.png

八、 显存释放与日常运维规范

1. 显存状态实测


九、 方案 B:无审查(去限制/突破审核)独立部署指南

1. 方案背景与两类解禁技术的本质区别

在开源社区中,文生图的“去限制/无审查”主要分为两类,方案 B 将两者的最强能力融合为一体:

方案分类代表项目与文件底层技术原理在体系中的角色与核心价值
第一类:Uncensored GGUFabenzerps/Qwen-Image-2.1-Uncensored-GGUF
qwen-image-2.1-Q4_K_M.gguf (4.29 GB)
K-quants 混合精度量化,移除云端外挂安全检查器(Safety Checker)图像去噪主干 (DiT):将显存开销从 6.8G 砍到 4.4G,8GB 显存设备不再告急,同时本地无外部黑名单拦截。
第二类:Heretic 文本编码器pottokao/Qwen-Image-2.1-...
qwen3vl_8b_w4a8_heretic.safetensors (5.88 GB)
方向消融(Direction Ablation):数学正交投影抹除大语言模型中的“拒答神经通路”提示词理解大脑 (Text Encoder):解决模型“嫌词敏感直接装傻”的痛点,100% 忠实理解人体解剖、极端恐怖艺术、医学写实与边缘题材。
方案 B 融合完全体第一类 DiT GGUF + 第二类 Heretic W4A8模块化流水线解耦 + 分阶段动态卸载终极方案:用 Heretic 换掉大脑的道德枷锁,用 GGUF 给画家的身体减肥,在 8GB 显卡上达成“彻底无审查 + 低显存高画质”。

2. 资产清单与独立隔离

所有方案 B 资产完全独立存放,官方 INT8 模型、文本编码器与工作流完全保留未动:

组件分类磁盘物理路径文件大小来源 / 格式说明
DiT 扩散主干E:\ComfyUI_Files\models\diffusion_models\qwen-image-2.1-Q4_K_M.gguf4.29 GBabenzerps / GGUF (Q4_K_M)独立新增,低显存渲染核心
文本编码器E:\ComfyUI_Files\models\text_encoders\qwen3vl_8b_w4a8_heretic.safetensors5.88 GBpottokao / Safetensors (W4A8)独立新增,去拒答大脑
独立工作流 JSONE:\ComfyUI_Files\workflows\qwen_image_2_1_uncensored_gguf.json6.5 KB方案 B 专属平铺连线独立的 7 节点标准连线,不影响官方工作流
扩展节点插件D:\Comfy-Desktop\ComfyUI-Installs\ComfyUI\ComfyUI\custom_nodes\ComfyUI-GGUF-leejet/ComfyUI-GGUF必须为 leejet 分支(已合入 qwen_image21 架构支持)

3. 去审查实测验收案例:卡拉瓦乔人体解剖肌理古典油画


十、 方案 C(扩展):提示词扩写全家桶(9B Heretic、Pocket-0.8B 与 Pocket-2B)与 LM Studio 极速协同

针对简短的一句话构思,Qwen 官方推出了提示词扩写模型(Qwen-Image-2.1-PE-T2I)。为了兼顾**“去审查解禁”与“秒级极速扩写”**,本地共部署并保留了三款代表性扩写模型,构建了分层协同矩阵。

1. 三大提示词扩写模型资产归档与定位

模型代号与文件参数量 / 体积存储路径与加载方式运行实测耗时核心定位与使用建议
qwen-image-2.1-pe-t2i-heretic9B (5.49 GB)
GGUF Q4_K_M
E:\LM Studio Models\Qwen\Qwen-Image-2.1-PE-T2I-Heretic-GGUF\
(NTFS 硬链接至 E:\ComfyUI_Files\models\text_encoders\)
LM Studio CLI 调度
28.4 秒 (显存 ~3.5G)全能无审查大模型:词汇量庞大、修辞极尽详实,具备方向消融去审查特性。适合高定精细题材。
qwen-image-2.1-pe-t2i-pocket-0.8b
(ML-Intern-lab 蒸馏版)
0.8B (812 MB)
GGUF Q8_0
E:\LM Studio Models\ML-Intern-lab\Qwen-Image-2.1-PE-T2I-Pocket-0.8B\
LM Studio 原生常驻加载
⚡ 3.2 ~ 5.6 秒
(显存仅 774 MB)
【日常主力首选⭐】:官方 Q8_0 GGUF,体积小如羽毛,5秒内直出纯净结构化 JSON,显存开销几乎为零,日常生图无等待感。
Qwen-Image-2.1-PE-T2I-Pocket-2B
(ML-Intern-lab 蒸馏版)
2B (3.59 GB)
Safetensors (BF16)
E:\ComfyUI_Files\models\pocket_models\Qwen-Image-2.1-PE-T2I-Pocket-2B\
PyTorch 原生调用 / 观望后续 GGUF
51.4 秒 (原生未量化)
(GGUF 潜力 ~3 秒)
【文学与透视之王⭐ 保留待转 GGUF】:作者评测中忠实度最高(60.2% 胜过 9B 老师),电影级导演构图视角极佳。当前保留原始权重,等待社区/本地压制 GGUF。

2. 同一测试用例下三方扩写效果实测横向比对

(1) Pocket-0.8B 实测表现(耗时 5.62 秒 | 推荐画幅 1:1)

“The image is a vertically oriented digital oil painting-style artwork presented as a square-format composition on a dark charcoal-to-black textured canvas background. The upper and left portions of the frame are dominated by an intense dramatic chiaroscuro sky, rendered in heavy black-and-gold tones with luminous gold highlights, deep shadowed valleys, and a rough matte appearance that suggests aged paper or finely grained canvas. A bright central sunburst breaks through the dark clouds on the far upper-left area, casting long golden beams downward toward the lower-middle region… Centrally positioned slightly left of vertical midpoint is the main figure: a majestic armored celestial warrior standing in profile facing toward the right side of the frame… The figure wears elaborate golden armor in a classical Renaissance armor style: rectangular shoulder pauldrons, broad elbow plating with raised vertical ribs…”

(2) Pocket-2B 实测表现(耗时 51.45 秒 | 推荐画幅 2:3)

“A vertically oriented classical fine art oil painting portrays a majestic medieval armored knight standing prominently against a deep, storm-filled night sky. The composition is dominated by a colossal celestial guardian occupying the center and left side of the canvas, extending from the lower foreground into the upper background… His body is clad in dark bronze and black plate armor, heavily embossed with circular rivets, angular shoulder pauldrons, breastplates, gauntlets, greaves, helmet scales, and layered chainmail. The armor has a realistic metallic texture, catching warm highlights along raised edges and deep shadows in recessed plates. His face is partially visible through the helmet’s visor-like aperture, with a stern, weathered expression, thick dark hair, and a beard; his eyes appear luminous due to dramatic backlighting. The knight’s right arm is raised in a protective, commanding gesture, while his left arm holds a long curved sword pointing downward at a sharp point; the blade reflects bright starlight along its edge… The lighting is strongly directional and dramatic, coming from the upper right as a golden sunrise or moonbeam, casting long shadows, glinting off the armor, the sword blade, and the cloud edges…”

(3) 原版 9B Heretic 实测表现(耗时 28.4 秒 | 推荐画幅 1:1)

“A richly detailed classical fantasy-style oil painting depicts a muscular adult male warrior occupying most of the frame… His face is angular and strongly modeled by warm directional light: prominent cheekbones, deep-set eyes, a furrowed brow… He wears ornate antique-gold armor made of layered leather or metal plates, engraved medallions, straps, buckles, rivets, and sculpted decorative trim across the chest, shoulders, waist, and forearms. A pale cream-white draped cloth wraps over his right shoulder…“


3. 专属直通选配节点:LMStudioPromptEnhancer 智能自适应升级

节点位于 E:\ComfyUI_Files\custom_nodes\ComfyUI-LMStudio-Enhancer\nodes.py,现已升级智能双协议自适应引擎:


4. 日常取舍与配置方案

  1. 日常出图默认配置:
    • 在 LM Studio 中加载 qwen-image-2.1-pe-t2i-pocket-0.8b(仅占 774MB,永不退显存);
    • 工作流 qwen_image_2_1_with_lmstudio_pe.json 默认已配置指向该模型,享受 3~5 秒极速扩写。
  2. 深度艺术与概念设计:
    • 需要极致电影质感时,可运行测试脚本 test_pocket_2b.py 单独生成高质量长描述后贴入 ComfyUI;
    • 后续社区一旦推出 2B 的 GGUF,即可无缝导入 LM Studio 实现 3 秒推理。
  3. 极简直通出图:
    • 将 enable_rewrite 切换为 False,跳过大模型直接出图。

十一、 全套工作流总览与选型矩阵

所有工作流 JSON 均存放于 E:\ComfyUI_Files\workflows\:

工作流文件核心主干与编码器扩写支持审查状态显存峰值适用业务场景
qwen_image_2_1_t2i.json官方 INT8 DiT + W4A8 VL无官方默认审查~4.85 GB基础通用文生图、高品质人像/风光
image_qwen_image_2_1_image_edit.json官方 INT8 DiT + W4A8 VL无官方默认审查~5.12 GB图生图、多图参考融合(<image1> 语法)
image_qwen_image_2_1_background_removal.json官方 INT8 DiT + 16x RGBA VAE无官方默认审查~4.60 GB透明背景免抠生成、电商白底/透明底素材
qwen_image_2_1_uncensored_gguf.jsonGGUF Q4_K_M + Heretic W4A8无彻底无审查~4.48 GB写实人体解剖、边缘艺术、突破拒答限制
qwen_image_2_1_with_lmstudio_pe.jsonGGUF Q4_K_M + Heretic W4A8 + LM Studio3~5s Pocket-0.8B 极速扩写(可直通)彻底无审查~4.70 GB全功能旗舰完全体:输入一句话自动扩写大师级画作

十二、 一键启动与日常极简运维

1. 双服务一键自动化拉起

已为你创建集成批处理文件 E:\ComfyUI_Files\start_all_services.bat:

2. 命令行手动操作指引 (LM Studio CLI)

3. 一键显存释放

在长时间生图或切换超大模型前,可直接在终端或脚本中调用清理接口:

curl -X POST http://127.0.0.1:8000/free

显存将立刻从 ~4.8GB 回落至 1.7GB 初始纯净状态。


十三、 常见问题与排障手册 (FAQ)

Q1: 如果不想开 LM Studio,生图会报错中断吗?

不会。专属节点 LMStudioPromptEnhancer 具备高可用直通逻辑:

  1. 若主动将 enable_rewrite 设为 False,节点直接将用户原始 Prompt 直通下游;
  2. 若 enable_rewrite 为 True 但 LM Studio 服务未启动或超时,节点会自动捕获异常并在控制台输出友好 Warning,随即自动回退将原始 Prompt 传给下游。整个生图流程 100% 顺畅执行。

Q2: 为什么不能直接在 ComfyUI 里用原生 GGUF 节点加载 PE-T2I?

ComfyUI-GGUF 的底层机制是为了 DiT(整个模型一次性前向传播 20 步)和 CLIP 短文本一次性编码设计的,并没有为自回归文本生成的 KV-Cache 和 C++/CUDA Kernel 融合做优化。在 8GB 显存设备上,逐字生成需要不断在 CPU 内存与 GPU 之间搬运 5.5GB 权重并反量化,速度慢达 25~34 秒/Token;而 LM Studio 采用预编译的 ggml-cuda 动态链接库,不仅执行效率高,还能利用 --ttl 90 机制让模型在扩写完成后自动退出显存,把 8GB 空间完整让给 DiT。

Q3: 提示 Unknown model architecture: qwen_image21?

这是因为旧版 city96/ComfyUI-GGUF 缺乏针对 Qwen-Image-2.1 的架构反量化定义。当前环境已升级至 leejet/ComfyUI-GGUF 专属分支,已原生支持 qwen_image21 架构。

Q4: 如何在 LM Studio 中更换其他扩写模型?

如果希望尝试其他通用大模型(如 qwen2.5-7b-instruct 或 deepseek-r1-distill-qwen-7b)来做提示词扩写,只需在 LM Studio 中下载对应模型,然后在 ComfyUI 的 LMStudioPromptEnhancer 节点的 model_name 参数栏填入对应模型标识符即可;若 model_name 留空,节点将默认调用 LM Studio 当前已加载的模型。


十四、 版本演进与变更日志 (Changelog)


Edit page
下载文章

Next Post
Cloudflare 零成本全栈生态实战与 AI Agent 自动化运维指南