ComfyUI_Step1X-Edit自定义节点将 Step1X-Edit 图像编辑模型集成到 ComfyUI 中。是一种最先进的图像编辑模型,可处理参考图像和用户的编辑指令以成新图像

​一、软件介绍

文末提供程序和源码下载

       ComfyUI_Step1X-Edit自定义节点将 Step1X-Edit 图像编辑模型集成到 ComfyUI 中。Step1X-Edit 是一种最先进的图像编辑模型,可处理参考图像和用户的编辑指令以生成新图像。支持 TeaCache 加速,以最小的质量损失实现 2 倍的推理速度

二、Features 特征

  •  Support for FP8 inference
    支持 FP8 推理
  •  Optimizing inference speed
    优化推理速度

三、Examples 例子

以下是您可以使用 ComfyUI_Step1X-Edit 实现的一些示例:

示例 1: “在这个女孩的脖子上添加带有红宝石的吊坠。

例 2: “让她哭吧。

四、Installation 安装

  1. 将此仓库克隆到你的 ComfyUI custom_nodes 的目录中:(文末提供直接源码下载)

    cd ComfyUI/custom_nodes
    git clone https://github.com/raykindle/ComfyUI_Step1X-Edit.git
    
  2. 安装所需的依赖项:

    Step 1: Install ComfyUI_Step1X-Edit dependencies
    第 1 步:安装 ComfyUI_Step1X-Edit 依赖项

    cd ComfyUI_Step1X-Edit
    pip install -r requirements.txt
    第 2 步:安装 flash-attn (文末链接下载),这里我们提供了一个脚本来帮助找到适合您系统的预构建 wheel。
    python utils/get_flash_attn.py

    The script will generate a wheel name like flash_attn-2.7.2.post1+cu12torch2.5cxx11abiFALSE-cp310-cp310-linux_x86_64.whl, which could be found in:
    该脚本将生成一个 wheel 名称,例如 flash_attn-2.7.2.post1+cu12torch2.5cxx11abiFALSE-cp310-cp310-linux_x86_64.whl ,可以在以下位置找到:

Linux 版本:Dao-AILab 的 flash-attn 版本(文末链接下载)

Windows 版本:kingbri1 的 flash-attn 版本(文末链接下载)

然后,您可以下载相应的预构建 wheel 并按照 中的 flash-attn 说明进行安装。

注意:即使 CUDA 和 Torch 版本不完全匹配,您仍然可以成功安装 flash-attention。但是,为了获得最佳性能和兼容性,建议使用与您的系统完全匹配的版本。

五、下载 Step1X-Edit-FP8 模型

<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>ComfyUI/
└── models/
    ├── diffusion_models/
    │   └── step1x-edit-i1258-FP8.safetensors
    ├── vae/
    │   └── vae.safetensors
    └── text_encoders/
        └── Qwen2.5-VL-7B-Instruct/
</code></span></span></span></span>
  • Step1X-Edit diffusion model: Download step1x-edit-i1258-FP8.safetensors from HuggingFace and place it in ComfyUI's models/diffusion_models directory
    Step1X - 编辑扩散模型:从 HuggingFace 下载 step1x-edit-i1258-FP8.safetensors 并放置在 ComfyUI 的 models/diffusion_models 目录中
  • Step1X-Edit VAE: Download vae.safetensors from HuggingFace and place it in ComfyUI's models/vae directory
    Step1X-编辑VAE:从HuggingFace下载 vae.safetensors 并放入ComfyUI的目录下 models/vae
  • Qwen2.5-VL model: Download Qwen2.5-VL-7B-Instruct and place it in ComfyUI's models/text_encoders/Qwen2.5-VL-7B-Instruct directory
    Qwen2.5-VL 模型:下载 Qwen2.5-VL-7B-Instruct 并将其放在 ComfyUI 的 models/text_encoders/Qwen2.5-VL-7B-Instruct 目录中

六、Usage 用法

  1. Start ComfyUI and create a new workflow.
    启动 ComfyUI 并创建一个新的工作流程。
  2. Add the "Step1X-Edit Model Loader" node (or the faster "Step1X-Edit TeaCache Model Loader" for 2x speedup) to your workflow.
    将“Step1X-Edit Model Loader”节点(或更快的“Step1X-Edit TeaCache Model Loader”节点,速度提高 2 倍)添加到您的工作流程中。
  3. Configure the model parameters:
    配置模型参数:
    • Select step1x-edit-i1258-FP8.safetensors as the diffusion model
      选择 step1x-edit-i1258-FP8.safetensors 作为扩散模型
    • Select vae.safetensors as the VAE
      选择 vae.safetensors 作为 VAE
    • Set Qwen2.5-VL-7B-Instruct as the text encoder
      设置为 Qwen2.5-VL-7B-Instruct 文本编码器
    • Set additional parameters (dtypequantizedoffload) as needed
      根据需要设置其他参数 ( dtype , quantized offload , )
    • If using TeaCache, set an appropriate threshold value
      如果使用 TeaCache,请设置适当的阈值
  4. Connect a "Step1X-Edit Generate" node (or "Step1X-Edit TeaCache Generate" if using TeaCache) to the model node.
    将“Step1X-Edit Generate”节点(如果使用 TeaCache,则为“Step1X-Edit TeaCache Generate”)连接到模型节点。
  5. Provide an input image and an editing prompt.
    提供输入图像和编辑提示。
  6. Run the workflow to generate edited images.
    运行工作流以生成编辑后的图像。

Parameters 参数

Step1X-Edit Model Loader Step1X-编辑模型加载器

  • diffusion_model: The Step1X-Edit diffusion model file (select from the diffusion_models dropdown)
    diffusion_model :Step1X-Edit 扩散模型文件(从diffusion_models下拉列表中选择)
  • vae: The Step1X-Edit VAE file (select from the vae dropdown)
    vae :Step1X-Edit VAE 文件(从 vae 下拉列表中选择)
  • text_encoder: The path to the Qwen2.5-VL model directory name (e.g., "Qwen2.5-VL-7B-Instruct")
    text_encoder :Qwen2.5-VL 模型目录名称的路径(例如,“Qwen2.5-VL-7B-Instruct”)
  • dtype: Model precision (bfloat16, float16, or float32)
    dtype :模型精度(bfloat16、float16 或 float32)
  • quantized: Whether to use FP8 quantized weights (true recommended)
    quantized :是否使用 FP8 量化权重(推荐 true)
  • offload: Whether to offload models to CPU when not in use
    offload :是否在不使用时将模型卸载到 CPU

Step1X-Edit TeaCache Model Loader (Additional Parameters)
Step1X-编辑 TeaCache Model Loader (附加参数)

  • teacache_threshold: Controls the trade-off between speed and quality
    teacache_threshold :控制速度和质量之间的权衡
    • 0.25: ~1.5x speedup
      0.25 : ~1.5 倍加速
    • 0.4: ~1.8x speedup
      0.4 : ~1.8 倍加速
    • 0.6: 2x speedup (recommended)
      0.6 :2 倍加速(推荐)
    • 0.8: ~2.25x speedup with minimal quality loss
      0.8 :~2.25 倍加速,质量损失最小
  • verbose: Whether to print TeaCache debug information
    verbose :是否打印 TeaCache 调试信息

Step1X-Edit Generate / Step1X-Edit TeaCache Generate
Step1X-编辑生成 / Step1X-编辑 TeaCache 生成

  • model: The Step1X-Edit model bundle
    model :Step1X-Edit 模型捆绑包
  • image: The input image to edit
    image :要编辑的输入图像
  • prompt: Text instructions describing the desired edit
    prompt :描述所需编辑的文本说明
  • negative_prompt: Text describing what to avoid
    negative_prompt :描述要避免的内容的文本
  • steps: Number of denoising steps (more steps = better quality but slower)
    steps :降噪步骤数(步骤越多 = 质量越好,但速度越慢)
  • cfg_scale: Guidance scale (how closely to follow the prompt)
    cfg_scale : 指导量表(遵循提示的程度)
  • image_size: Size of the output image (512 recommended)
    image_size :输出图像的大小(推荐 512)
  • seed: Random seed for reproducibility
    seed :用于可重复性的随机种子

TeaCache Acceleration TeaCache 加速

This implementation includes TeaCache acceleration technology, which provides:
此实现包括 TeaCache 加速技术,该技术提供:

  • 2x faster inference with no quality loss
    推理速度提高 2 倍,且无质量损失
  • Training-free acceleration with no additional model fine-tuning
    无需训练的加速,无需额外的模型微调
  • Adaptive caching based on timestep embeddings
    基于时间步嵌入的自适应缓存
  • Adjustable speed-quality trade-off via threshold parameter
    通过阈值参数调整速度-质量权衡

TeaCache works by intelligently skipping redundant calculations during the denoising process. It analyzes the relative changes between steps and reuses previously computed results when possible, significantly reducing computational requirements without compromising output quality.
TeaCache 的工作原理是在降噪过程中智能地跳过冗余计算。它分析步骤之间的相对变化,并在可能的情况下重用以前计算的结果,从而在不影响输出质量的情况下显著降低计算要求。

Based on TeaCache research, which was developed for accelerating video diffusion models and adapted here for image generation.
基于 TeaCache 研究,该研究是为加速视频扩散模型而开发的,并在此处进行了调整以用于图像生成。

七、软件下载

夸克网盘分享

本文信息来源于GitHub作者地址:GitHub - raykindle/ComfyUI_Step1X-Edit: 🔥🔥🔥 Support TeaCache acceleration for 2x faster inference with minimal quality loss

解释分析细致讲解一下这段代码int ncds_file_editconfig_internal (struct ncds_ds *ds, NC_DATASTORE target, char config) { struct ncds_ds_file * file_ds = (struct ncds_ds_file )ds; xmlDocPtr config_doc, datastore_doc; xmlNodePtr target_ds, tmp_target_ds, aux_node, root; int retval = EXIT_SUCCESS, ret; char aux = NULL; const char configp; LOCK(file_ds,ret); if (ret) { return EXIT_FAILURE; } DBG("enter %s/%d\n", func,LINE); if(file_fill_dsnodes(file_ds)) { UNLOCK(file_ds); ERROR("%s: file_ds->running_all/startup_all/candidate_all is NULL\n", func); return EXIT_FAILURE; } DBG("%s step1\n", func); file_rollback_store(file_ds); switch(target) { case NC_DATASTORE_RUNNING: target_ds = file_ds->running; break; case NC_DATASTORE_STARTUP: target_ds = file_ds->startup; break; case NC_DATASTORE_CANDIDATE: target_ds = file_ds->candidate; break; default: UNLOCK(file_ds); ERROR("%s: invalid target.", func); return EXIT_FAILURE; break; } if (strncmp(config, "<?xml", 5) == 0) { if ((configp = strchr(config, '>')) == NULL) { UNLOCK(file_ds); ERROR("%s: invalid config.", func); return EXIT_FAILURE; } ++configp; while (*configp == ' ' || *configp == '\n' || configp == '\t') { ++configp; } } else { configp = config; } if (asprintf(&aux, "<config>%s</config>", configp) == -1) { UNLOCK(file_ds); ERROR("asprintf() failed (%s:%d).", FILE, LINE); return EXIT_FAILURE; } if ((config_doc = xmlReadMemory (aux, strlen(aux), NULL, NULL, NC_XMLREAD_OPTIONS)) == NULL) { UNLOCK(file_ds); free(aux); ERROR("%s: Reading xml data failed!", func); return EXIT_FAILURE; } free(aux); root = xmlDocGetRootElement(config_doc); for (aux_node = root->children; aux_node != NULL; aux_node = root->children) { xmlUnlinkNode(aux_node); xmlAddNextSibling(config_doc->last, aux_node); } aux_node = root->next; xmlUnlinkNode(root); xmlFreeNode(root); datastore_doc = xmlNewDoc (BAD_CAST "1.0"); xmlDocSetRootElement(datastore_doc, xmlCopyNode(target_ds->children, 1)); if (target_ds->children) { for (root = target_ds->children->next; root != NULL; root = aux_node) { aux_node = root->next; xmlAddNextSibling(datastore_doc->last, xmlCopyNode(root, 1)); } } retval = edit_config_internal(datastore_doc, config_doc, (struct ncds_ds)file_ds, NC_EDIT_DEFOP_NOTSET); if (EXIT_SUCCESS == retval) { #if 1 while ((aux_node = target_ds->children) != NULL) { xmlUnlinkNode(aux_node); xmlFreeNode(aux_node); } xmlAddChildList(target_ds, xmlCopyNodeList(datastore_doc->children)); if (file_sync(file_ds)) { retval = EXIT_FAILURE; } #endif } else { retval = EXIT_FAILURE; } UNLOCK(file_ds); xmlFreeDoc (datastore_doc); xmlFreeDoc (config_doc); return retval; }
06-09
这段代码是一个函数,函数名为 ncds_file_editconfig_internal,它的作用是编辑一个 data store 文件。函数的参数有三个,分别是一个指向 ncds_ds 结构体的指针 ds,一个 NC_DATASTORE 类型的 target,以及一个 char 类型的 config。该函数返回一个整数值。 函数开始时,它将传入的 ds 强制转换为 struct ncds_ds_file 类型的指针 file_ds,并定义了一些变量,如 xmlDocPtr 类型的指针 config_doc datastore_doc,以及 xmlNodePtr 类型的指针 target_ds、tmp_target_ds、aux_node root,以及 int 类型的变量 retval ret,以及 char 类型的变量 aux configp。 接下来,函数会对 file_ds 作加锁操作,并检查加锁是否成功。如果加锁失败,则返回 EXIT_FAILURE。 然后,函数会输出一条日志,表明函数已经进入到了这个代码块中。接着,函数会调用 file_fill_dsnodes 函数,如果该函数返回值不为 0,说明 file_ds 的成员变量 running_all、startup_all candidate_all 为空,此时函数会解锁 file_ds,并输出错误日志,终返回 EXIT_FAILURE。 然后,函数会调用 file_rollback_store 函数,该函数的作用是将 file_ds 的 candidate 数据库回滚到 running 或 startup 数据库中。接着,函数会根据传入的 target 值来确定 target_ds 的值,如果 target 不是 NC_DATASTORE_RUNNING、NC_DATASTORE_STARTUP 或 NC_DATASTORE_CANDIDATE 中的一个,则函数会解锁 file_ds,并输出错误日志,终返回 EXIT_FAILURE。 接下来,函数会判断 config 是否以 "<?xml" 开头,如果是,则将 configp 指向 config 中第一个 ">" 的下一个字符,并将 configp 中的空格、制表符换行符过滤掉;否则,将 configp 指向 config。接着,函数会调用 asprintf 函数来构造一个新的字符串 aux,将 configp 包装成一个 XML 标签,然后将其读入到 config_doc 中,如果读入失败,则函数会释放锁并返回 EXIT_FAILURE。 接下来,函数会提取 config_doc 中的根点 root,并将它的子点从 root 中分离出来,然后将这些子点添加到 config_doc 的后一个点后面。接着,函数会新建一个名为 "1.0" 的 XML 文档 datastore_doc,并将 target_ds 的子点添加到 datastore_doc 中。然后,函数会遍历 target_ds 的子点,将它们添加到 datastore_doc 的后一个点后面。 接下来,函数会调用 edit_config_internal 函数来编辑 datastore_doc config_doc,其中 edit_config_internal 函数是另一个函数,我们无法得知它的实现细,但是它的作用是将 config_doc 中的配置应用到 datastore_doc 中。如果 edit_config_internal 函数返回值为 EXIT_SUCCESS,则将 datastore_doc 中的子点添加到 target_ds 中,并调用 file_sync 函数来将修改同步到文件系统中。如果 file_sync 函数返回值不为 0,则函数返回 EXIT_FAILURE。 后,函数会解锁 file_ds,并释放 config_doc datastore_doc 所占用的内存,并返回 retval。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值