🤖 AI/ML

ComfyUI

A node-based interface for Stable Diffusion

📖 Detailed Explanation

ComfyUI is a node-based GUI interface for Stable Diffusion that lets you visually design complex image generation workflows. Each function is organized as an independent node, and you connect them by drag and drop, allowing fine-grained control over the entire pipeline from prompt input to post-processing.

ComfyUI, released on GitHub in early 2023, started as an open-source project and grew rapidly. While the AUTOMATIC1111 WebUI focused on ease of use, ComfyUI focused on flexibility and extensibility for advanced users. It currently has over 50,000 GitHub stars and has built an active community.

The core principle of ComfyUI is dataflow programming, in which data flows along the connections between nodes and is transformed. Each step, such as checkpoint loading, prompt encoding, sampling, and VAE decoding, is separated into an independent node, so you can save intermediate results, run multiple models in parallel, or set up conditional branches.

In practice, ComfyUI is used for batch generation automation, ControlNet/LoRA combination experiments, building img2img pipelines, and bulk processing of video frames. Workflows can be saved and shared as JSON, which is advantageous for team collaboration, and running it in API server mode also enables integration with external systems.

💻 Code Example

import json
import urllib.request
import urllib.parse

# ComfyUI API 서버 주소
COMFY_API = "http://127.0.0.1:8188"

def queue_prompt(workflow: dict) -> dict:
    """ComfyUI에 워크플로우 실행 요청"""
    data = json.dumps({"prompt": workflow}).encode('utf-8')
    req = urllib.request.Request(
        f"{COMFY_API}/prompt",
        data=data,
        headers={'Content-Type': 'application/json'}
    )
    return json.loads(urllib.request.urlopen(req).read())

# 간단한 txt2img 워크플로우 예시
workflow = {
    "3": {  # KSampler 노드
        "class_type": "KSampler",
        "inputs": {
            "seed": 42,
            "steps": 20,
            "cfg": 7.5,
            "sampler_name": "euler",
            "scheduler": "normal",
            "denoise": 1.0,
            "model": ["4", 0],     # CheckpointLoader 연결
            "positive": ["6", 0],  # CLIP 인코딩 연결
            "negative": ["7", 0],
            "latent_image": ["5", 0]
        }
    },
    "4": {  # 체크포인트 로더
        "class_type": "CheckpointLoaderSimple",
        "inputs": {"ckpt_name": "v1-5-pruned.safetensors"}
    },
    "5": {  # 빈 latent 이미지
        "class_type": "EmptyLatentImage",
        "inputs": {"width": 512, "height": 512, "batch_size": 1}
    },
    "6": {  # 긍정 프롬프트 인코딩
        "class_type": "CLIPTextEncode",
        "inputs": {
            "text": "a beautiful sunset over mountains, highly detailed",
            "clip": ["4", 1]
        }
    }
}

result = queue_prompt(workflow)
print(f"Prompt ID: {result['prompt_id']}")

🗣️ Examples of Practical Conversations

At an AI art team meeting

"ComfyUI is much better than A1111 for batch work. Once you build a workflow, you can automatically generate hundreds of images just by changing the prompt, and combining several ControlNets is done just by connecting nodes."

On a tech blog

"The strength of ComfyUI is workflow reusability. If you export to JSON and share it with teammates, you can reproduce identical results. Version control is also possible, and it's easy to integrate into services in API mode."

In a Discord community

"Installing ComfyUI Manager makes managing custom nodes so much easier. Node packs install with one click, and it even resolves dependency conflicts automatically. I wouldn't recommend using ComfyUI without it."

⚠️ Cautions

1
VRAM management is essential

Complex workflows consume VRAM quickly. Place model unloading nodes appropriately, and on GPUs with 8GB or less, run with the --lowvram option.

2
Node version compatibility

Updating custom nodes may break existing workflows. For important projects, pin node versions and back up before updating.

3
Set paths correctly

Model, LoRA, and VAE file paths must be correct. If you set the paths in extra_model_paths.yaml and share the model folder with A1111, you can save storage space.

🔗 Related Terms

📚 Learn More