实用指南:ComfyUI 全流程指南:安装、配置、插件与模型选型

作者:吴业亮
博客:wuyeliang.blog.csdn.net

一、ComfyUI 简介及后端原理

1. 什么是 ComfyUI

ComfyUI 是一款功能强大的 Stable Diffusion 可视化节点编辑器,允许用户通过拖拽节点的方式构建图像生成流程,提供了比传统 UI 更灵活、更精细的控制能力。它适用于需要自定义生成流程的开发者和高级用户,支持各种扩散模型、插件扩展和工作流自动化。

2. 后端原理

ComfyUI 后端基于 Python 构建,核心原理如下:

  • 节点式架构:将图像生成的各个环节(如模型加载、文本编码、图像解码等)封装为独立节点,通过节点间的连接构建完整工作流
  • PyTorch 集成:底层依赖 PyTorch 框架进行模型推理,支持 CPU/GPU 计算,通过 CUDA 加速实现高效的图像生成
  • 异步处理:采用异步任务处理机制,支持批量生成和后台任务运行
  • 模块化设计:通过插件系统支持功能扩展,允许开发者自定义节点和工作流逻辑
  • 模型管理:支持多种扩散模型(如 Stable Diffusion、SDXL 等)及配套组件(VAE、LoRA 等)的加载与管理

二、ComfyUI 安装步骤

1. 克隆仓库

  • GitHub 直接克隆

    cd /data
    git clone https://github.com/comfyanonymous/ComfyUI.git
  • 国内镜像克隆(加速访问)

    git clone https://mirror.ghproxy.com/https://github.com/comfyanonymous/ComfyUI.git
  • 进入项目目录

    cd ComfyUI/

2. 创建运行环境

  • 建立 Conda 虚拟环境

    conda create -n comfyui python=3.11
    conda activate comfyui
  • 安装依赖库

    pip install -r requirements.txt
  • 针对 CUDA 11.8 的特殊配置
    编辑 requirements.txt,移除以下行:

    torch
    torchvision
    torchaudio

    然后执行专用安装命令:

    pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

3. 启动与配置

  • 自定义端口启动(示例使用 80 端口)

    python main.py --port 80 --listen 0.0.0.0
  • 解决 CUDA 相关错误
    若出现 RuntimeError: CUDA error: operation not supported,使用以下命令启动:

    python main.py --port 80 --listen 0.0.0.0 --disable-cuda-malloc
  • 配置系统服务(开机自启)

    1. 创建服务文件
      vi /etc/systemd/system/ComfyUI.service
    2. 写入以下内容
      [Unit]
      Description=ComfyUI Service
      After=network.target
      [Service]
      Type=simple
      User=root
      StandardOutput=file:/var/log/ComfyUI.log
      StandardError=file:/var/log/ComfyUI.log
      WorkingDirectory=/data/ComfyUI/
      ExecStart=/bin/bash -c 'source /root/miniconda3/bin/activate && conda activate comfyui && python main.py --port 8080 --listen 0.0.0.0 --disable-cuda-malloc'
      Restart=on-failure
      [Install]
      WantedBy=multi-user.target
    3. 启用并启动服务
      systemctl daemon-reload
      systemctl enable ComfyUI.service
      systemctl restart ComfyUI.service

三、推荐插件

插件功能安装命令
设备管理器git clone https://mirror.ghproxy.com/https://github.com/11cafe/comfyui-workspace-manager.git
界面汉化git clone https://mirror.ghproxy.com/https://github.com/AIGODLIKE/AIGODLIKE-ComfyUI-Translation.git
自动补全git clone https://mirror.ghproxy.com/https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git
提示词翻译git clone https://mirror.ghproxy.com/https://github.com/AlekPet/ComfyUI_Custom_Nodes_AlekPet.git
节点管理器git clone https://github.com/ltdrdata/ComfyUI-Manager
环境信息提示器git clone https://mirror.ghproxy.com/https://github.com/crystian/ComfyUI-Crystools.git
额外依赖:pip install split_image facexlib ultralytics wget deepdiff pynvml transparent_background supervision aiohttp_cors webcolors

四、常用差异化节点

ComfyUI-AnimateAnyone-Evolved/      # 动画生成节点
ComfyUI-BrushNet/                  # 画笔控制节点
ComfyUI_CatVTON_Wrapper/           # 虚拟试衣节点
ComfyUI-CogVideoXWrapper/          # 视频生成节点
ComfyUI-Gemini/                    # Gemini 模型集成
ComfyUI-GGUF/                      # GGUF 格式模型支持
ComfyUI-InstantID/                 # 人脸特征控制
ComfyUI-layerdiffuse/              # 分层扩散节点
ComfyUI-Marigold/                  # 深度估计节点
ComfyUI-MimicMotionWrapper/        # 动作模仿节点
ComfyUI-MingNodes/                 # 通用功能扩展节点
ComfyUI_OmniGen_Wrapper/           # OmniGen 模型封装
ComfyUI-PhotoMaker-ZHO/            # 照片生成节点
comfyui_segment_anything/          # 图像分割节点
ComfyUI-SUPIR/                     # 超分辨率节点
ComfyUI_toyxyz_test_nodes/         # 测试节点集
ComfyUI-YoloWorld-EfficientSAM/    # 目标检测节点
eden_comfy_pipelines/              # 预设工作流
facerestore_cf/                    # 人脸修复节点
NodeGPT/                           # GPT 集成节点

五、推荐 VAE 模型

模型名称适用场景下载链接
vae-ft-mse-840000-ema-pruned通用 Stable Diffusion 版本下载
kl-f8-anime2动漫风格图像下载
sdxl_vae.safetensorsSDXL 模型专用下载
orangemix.vae.ptAnything V3/V4 模型下载
clearvae_v2.2.safetensors提高图像清晰度下载

提示:不同 VAE 模型会影响图像生成质量和风格,建议根据具体需求测试选择最合适的模型。

posted @ 2026-01-26 10:58  clnchanpin  阅读(24)  评论(0)    收藏  举报