mcpField
F
flux-txt2img

flux-txt2img

github.com/artokun创意与媒体87639 次安装2 天前更新
代码仓库

关于 flux-txt2img

一份使用 Flux 在 ComfyUI 中构建文生图工作流的技能指南,涵盖 Flux.1 Dev SRPO、Flux 2 Klein 9B 和 Flux 2 Turbo LoRA,并说明模型连接、提示词条件设置与采样参数。

主要功能

  1. 01三种 Flux 工作流配置
  2. 02模型与编码器设置
  3. 03引导与提示词条件设置
  4. 04各模型变体的采样参数
  5. 05分辨率与 VRAM 指引
  6. 06应用 LoRA

适用场景

  1. 01搭建 Flux.1 Dev SRPO 工作流
  2. 02用蒸馏版 Klein 进行四步图像生成
  3. 03应用 Turbo LoRA 加快采样
  4. 04调整提示词的引导值和分辨率

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/artokun/comfyui-mcp --skill flux-txt2img

安装后在 Claude Code 中输入/flux-txt2img确认已加载。

详细介绍

Flux 文生图工作流

概述

Flux 是 Black Forest Labs 推出的引导蒸馏扩散模型系列。它使用独立的 FluxGuidance 节点,而不是 KSampler CFG(其值必须始终为 1.0)。本地提供三种变体:

  1. Flux.1 Dev SRPO。 经过 SRPO 对齐微调的 Flux.1 Dev。使用 DualCLIPLoader(T5XXL + CLIP-L)。仅支持 BF16。
  2. Flux 2 Klein 9B。 蒸馏版 Flux 2 变体。使用单个 CLIPLoader(Qwen3-8B)和 flux2-vae.safetensors。可快速生成,仅需 4 步。
  3. Flux 2 Turbo LoRA。 应用于 Flux.1 Dev,以实现 4 步生成。

模型

Flux.1 Dev SRPO
组件节点模型备注
UNETUNETLoaderflux.1-dev-SRPO-BFL-bf16.safetensors22.7GB,仅支持 BF16 — FP8 会产生异常结果
CLIPDualCLIPLoader (type=flux)clip_name1: t5xxl_fp8_e4m3fn.safetensors,clip_name2: clip_l.safetensorsT5XXL(4.7GB)+ CLIP-L(235MB)
VAEVAELoaderae.safetensors标准 Flux VAE(320MB)。Z-Image 使用相同的 VAE 架构,但权重不同 — 它的 VAE 是单独的文件(z-image-ae.safetensors),不是此文件
Flux 2 Klein 9B
组件节点模型备注
UNETUNETLoaderbigLove_klein1.safetensors17.3GB,Klein 9B 变体
CLIPCLIPLoader (type=flux2)qwen_3_8b_fp8mixed.safetensorstext_encoders/ 中的 Qwen3-8B(8.3GB)。使用 flux2,不要使用 flux — 两者都在枚举中,但 flux 会在采样器处失败
VAEVAELoaderflux2-vae.safetensorsFlux 2 专用 VAE(321MB)

Klein 9B 与 Flux.1 Dev 的区别:Klein 使用 Qwen3-8B 文本编码器(而非 T5XXL + CLIP-L)。它使用不同的 VAE(flux2-vae.safetensors)。蒸馏版 9B 只需 4 步;基础版 9B 在 CFG 5.0 下需要约 50 步。使用 FP8 时可在约 20GB VRAM 中运行。

Flux 2 Turbo LoRA(应用于 Flux.1 Dev)
组件节点模型备注
LoRALoraLoaderModelOnlyflux2-turbo-lora.safetensors2.6GB,强度 1.0
Alt LoRALoraLoaderModelOnlyFlux2TurboComfyv2.safetensors社区变体,大小相同

条件设定

CLIPTextEncodeFlux(Flux.1 Dev 推荐)

为每个文本编码器提供独立的提示词字段:

{
  "class_type": "CLIPTextEncodeFlux",
  "inputs": {
    "clip": ["<dual_clip>", 0],
    "clip_l": "short prompt for CLIP-L",
    "t5xxl": "detailed description for T5XXL",
    "guidance": 3.5
  }
}

clip_l 提取关键语义特征。t5xxl 扩展并完善描述。简单使用时,可在两个字段中填写相同的提示词。该节点内置引导,因此无需单独使用 FluxGuidance。

FluxGuidance(替代方案)

如果使用标准 CLIPTextEncode 而非 CLIPTextEncodeFlux,请单独应用引导:

{
  "class_type": "FluxGuidance",
  "inputs": {
    "conditioning": ["<clip_text_encode>", 0],
    "guidance": 3.5
  }
}
引导值
场景引导值备注
短提示词3.5–4.0更严格地遵循提示词
长/复杂提示词1.0–1.5更大的创作空间
写实效果2.5减少皮肤的光泽感,呈现更丰富的细节
标准3.5适用于大多数场景的默认值
负向条件设定

Flux 不支持传统的负面提示词(引导蒸馏,CFG=1.0)。请使用 ConditioningZeroOut:

{
  "class_type": "ConditioningZeroOut",
  "inputs": { "conditioning": ["<positive_cond>", 0] }
}

或者将空的 CLIPTextEncode 用作负向输入。

采样器设置

Flux.1 Dev SRPO
参数标准值备注
steps20范围:20–28
cfg1.0始终为 1.0 — 引导通过 FluxGuidance 实现
sampler_nameipndm作者推荐用于 SRPO
schedulerbeta作者推荐用于 SRPO
guidance3.5通过 CLIPTextEncodeFlux 或 FluxGuidance 设置
denoise1.0

SRPO 作者推荐使用 ipndm/beta 组合。标准 Flux 设置(euler/simple)也可运行,但 ipndm/beta 与此微调模型搭配时效果更好。

Flux 2 Klein 9B(蒸馏版)
参数值备注
steps4蒸馏模型,4 步为最佳
cfg1.0始终为 1.0
sampler_nameeuler
schedulersimple
denoise1.0
Flux 2 Klein 9B(Base/未蒸馏)
参数值备注
steps50完整画质
cfg5.0Base 模型需要更高的 CFG
sampler_nameeuler
schedulersimple
Flux.1 Dev + Turbo LoRA
参数值备注
steps4Turbo 蒸馏版
cfg1.0
sampler_nameeuler
schedulersimple
lora_strength1.0

分辨率

纵横比分辨率百万像素
正方形1024x10241.0MP
纵向 3:4896x11521.0MP
横向 4:31152x8961.0MP
横向 16:91344x7681.0MP
纵向 9:16768x13441.0MP

Flux 原生处理约 1 百万像素的图像。尺寸应为 8 的倍数。

提示词风格

使用自然语言描述。无需质量标签(不同于 SDXL/Illustrious)。详细、描述性强的提示词效果最佳。

Good: "A young woman with auburn hair sits at a sunlit cafe in Paris, wearing a cream linen blazer, soft bokeh background, shot on Sony A7III 85mm f/1.4"
Bad: "masterpiece, best quality, 1girl, cafe, paris"

完整工作流:Flux.1 Dev SRPO

{
  "1": { "class_type": "UNETLoader", "inputs": { "unet_name": "flux.1-dev-SRPO-BFL-bf16.safetensors", "weight_dtype": "default" }},
  "2": { "class_type": "DualCLIPLoader", "inputs": { "clip_name1": "t5xxl_fp8_e4m3fn.safetensors", "clip_name2": "clip_l.safetensors", "type": "flux" }},
  "3": { "class_type": "VAELoader", "inputs": { "vae_name": "ae.safetensors" }},
  "4": { "class_type": "CLIPTextEncodeFlux", "inputs": {
    "clip": ["2", 0],
    "clip_l": "<short prompt>",
    "t5xxl": "<detailed prompt>",
    "guidance": 3.5
  }},
  "5": { "class_type": "ConditioningZeroOut", "inputs": { "conditioning": ["4", 0] }},
  "6": { "class_type": "EmptyLatentImage", "inputs": { "width": 896, "height": 1152, "batch_size": 1 }},
  "7": { "class_type": "KSampler", "inputs": {
    "model": ["1", 0],
    "positive": ["4", 0],
    "negative": ["5", 0],
    "latent_image": ["6", 0],
    "seed": 42, "steps": 20, "cfg": 1, "sampler_name": "ipndm", "scheduler": "beta", "denoise": 1
  }},
  "8": { "class_type": "VAEDecode", "inputs": { "samples": ["7", 0], "vae": ["3", 0] }},
  "9": { "class_type": "SaveImage", "inputs": { "images": ["8", 0], "filename_prefix": "flux_srpo" }}
}

完整工作流:Flux 2 Klein 9B(蒸馏版,4 步)

{
  "1": { "class_type": "UNETLoader", "inputs": { "unet_name": "bigLove_klein1.safetensors", "weight_dtype": "default" }},
  "2": { "class_type": "CLIPLoader", "inputs": { "clip_name": "qwen_3_8b_fp8mixed.safetensors", "type": "flux2" }},
  "3": { "class_type": "VAELoader", "inputs": { "vae_name": "flux2-vae.safetensors" }},
  "4": { "class_type": "CLIPTextEncode", "inputs": { "clip": ["2", 0], "text": "<prompt>" }},
  "5": { "class_type": "ConditioningZeroOut", "inputs": { "conditioning": ["4", 0] }},
  "6": { "class_type": "EmptyFlux2LatentImage", "inputs": { "width": 1024, "height": 1024, "batch_size": 1 }},
  "7": { "class_type": "KSampler", "inputs": {
    "model": ["1", 0],
    "positive": ["4", 0],
    "negative": ["5", 0],
    "latent_image": ["6", 0],
    "seed": 42, "steps": 4, "cfg": 1, "sampler_name": "euler", "scheduler": "simple", "denoise": 1
  }},
  "8": { "class_type": "VAEDecode", "inputs": { "samples": ["7", 0], "vae": ["3", 0] }},
  "9": { "class_type": "SaveImage", "inputs": { "images": ["8", 0], "filename_prefix": "flux_klein" }}
}

Klein 使用单个 CLIPLoader(而非 DualCLIPLoader),设置 type: "flux2",并使用来自 text_encoders/ 的 Qwen3-8B 文本编码器。CLIP 加载器路径从 models/text_encoders/ 解析。

Flux-2 特有的注意事项如下。这些问题都会在 KSampler 而非加载器处报错,因此错误会指向错误的节点:

  • type 必须是 flux2,不能是 flux。CLIPLoader 枚举中包含这两个值,因此使用 flux 时会正常加载,随后在采样期间失败。
  • 使用 EmptyFlux2LatentImage,而非 EmptyLatentImage。Flux 2 使用不同数量的潜变量通道。
  • Klein 9B 应搭配 Qwen3-8B 编码器(来自 Comfy-Org/vae-text-encorder-for-flux-klein-9b 的 qwen_3_8b*)。名称相似的 qwen_3_4b 随 klein-4b 仓库提供,适用于 4B 模型。混用会引发 mat1 and mat2 shapes cannot be multiplied (512x7680 and 12288x4096) 错误,其中 7680 = 2560x3(4B 隐藏层大小),12288 = 4096x3(8B)。这看起来像令人困惑的 CLIP 错误,而不是文件选错错误。

完整工作流:Flux.1 Dev + Turbo LoRA(4 步)

{
  "1": { "class_type": "UNETLoader", "inputs": { "unet_name": "flux.1-dev-SRPO-BFL-bf16.safetensors", "weight_dtype": "default" }},
  "2": { "class_type": "LoraLoaderModelOnly", "inputs": { "model": ["1", 0], "lora_name": "flux2-turbo-lora.safetensors", "strength_model": 1.0 }},
  "3": { "class_type": "DualCLIPLoader", "inputs": { "clip_name1": "t5xxl_fp8_e4m3fn.safetensors", "clip_name2": "clip_l.safetensors", "type": "flux" }},
  "4": { "class_type": "VAELoader", "inputs": { "vae_name": "ae.safetensors" }},
  "5": { "class_type": "CLIPTextEncodeFlux", "inputs": {
    "clip": ["3", 0],
    "clip_l": "<short prompt>",
    "t5xxl": "<detailed prompt>",
    "guidance": 3.5
  }},
  "6": { "class_type": "ConditioningZeroOut", "inputs": { "conditioning": ["5", 0] }},
  "7": { "class_type": "EmptyLatentImage", "inputs": { "width": 1024, "height": 1024, "batch_size": 1 }},
  "8": { "class_type": "KSampler", "inputs": {
    "model": ["2", 0],
    "positive": ["5", 0],
    "negative": ["6", 0],
    "latent_image": ["7", 0],
    "seed": 42, "steps": 4, "cfg": 1, "sampler_name": "euler", "scheduler": "simple", "denoise": 1
  }},
  "9": { "class_type": "VAEDecode", "inputs": { "samples": ["8", 0], "vae": ["4", 0] }},
  "10": { "class_type": "SaveImage", "inputs": { "images": ["9", 0], "filename_prefix": "flux_turbo" }}
}

LoRA 支持

自定义 LoRA(jellyfish 等)

在 UNET 和 KSampler 之间使用 LoraLoaderModelOnly 应用 Flux LoRA:

{
  "class_type": "LoraLoaderModelOnly",
  "inputs": {
    "model": ["<unet_or_previous_lora>", 0],
    "lora_name": "<lora_file>.safetensors",
    "strength_model": 1.0
  }
}
Klein LoRA

Klein 9B LoRA 应放在 loras/Flux.2 Klein 9B/ 子文件夹中:

  • klein_slider_detail.safetensors,一个细节滑块 LoRA

VRAM 注意事项

模型VRAM备注
SRPO BF16 + DualCLIP~24GB恰好占满 RTX 4090。必须使用 BF16——SRPO 的 FP8 无法正常工作
Klein 9B FP8 + Qwen3-8B~20GB可轻松装入 4090
SRPO + Turbo LoRA~24GB与 SRPO 基础版相同
  • 从其他模型系列切换到 Flux 前,始终先执行 clear_vram
  • T5XXL 与 UNET 是主要的 VRAM 消耗者;采样期间两者都会保持加载
  • CLIP-L 体积较小(235MB),可以忽略不计

提示

  1. KSampler CFG 必须始终为 1.0。所有引导都通过 CLIPTextEncodeFlux 或 FluxGuidance 实现
  2. SRPO 需要 BF16。已知此微调模型使用 FP8 量化会产生异常结果
  3. 对于较短的提示词(1 到 2 句话),将引导提高到 3.5 到 4.0。对于较长的提示词(一个段落),将其降低到 1.0 到 1.5
  4. Flux 生成图像文字的效果出色。将要渲染的文字放在提示词的引号内
  5. Klein 9B 是 4 步生成中速度最快的选项。可用它快速迭代,然后切换到 SRPO 获取最终画质

来源

  • 官方: 未找到。
  • 实测: 采样器参数、连接方式和提示词说明来自 packs/ 中可运行的图,以及观察到的生成结果;并非供应商的提示词指南。

评论

支持 Markdown