A cream canvas holds a node graph: four coloured rectangles (text prompt, encoder, sampler, save) connected by red wires, each node with small dots marking inputs and outputs. A single rendered amber square to the right represents the final image. Bauhaus punctuation dots and a grounding triangle.
[ AI & Automation ]7 min read

Generating Art: The Chaos and Beauty of ComfyUI

Phase 4 · Autonomous Agents and UX

A node-based visual programming environment for image generation, the GPU driver patch that cost a weekend, and why exposing the graph is a feature, not a bug.

ComfyUIStable Diffusion XLPyTorchDocker

Text generation is abstract. You type, the model answers, the answer is words. Image generation is stubborn, because you can argue about whether the picture is the one you wanted. The argument is not subjective; it is architectural. A prompt plus a model plus some settings produces an image, and the image is almost what you wanted but not quite, and the part you want to change is locked behind a one-click interface that will not tell you why it made that choice.

ComfyUI is the answer to that frustration. It takes the entire image-generation pipeline out of the one-click box and lays it on a canvas as a graph of nodes you can see, edit, and reconnect. The first time you open it, the graph looks like airplane wiring. A week later, it looks like the honest description of what every other tool was hiding from you.

The Analogy

A modern synthesiser has a front panel with large, friendly knobs. You turn “filter cutoff” to get a brighter sound. That knob works because underneath it there is a specific analog circuit, a voltage-controlled filter, that takes the control voltage from the knob and bends the sound accordingly. The knob is a simplification of a patchable signal path.

A modular synthesiser exposes the signal path. Oscillators, envelopes, filters, mixers are separate modules, each with physical input and output sockets. You run patch cables between them. If you want the envelope to modulate the filter cutoff, you run a cable from “envelope out” to “filter CV in”. Nothing is hidden. Every knob on the simpler synth was this cable, drawn short and soldered shut.

ComfyUI is the modular synthesiser for image generation. The text prompt is one module. The latent sampler is another. The VAE decoder that turns latents into pixels is a third. You run the connections yourself, and in exchange you understand what the tool is actually doing.

The Tech Translated

A Stable Diffusion image-generation pipeline has, at minimum, these stages:

  1. Text encoder. Turns your prompt into an embedding vector.
  2. Latent sampler. Runs the reverse-diffusion loop in compressed “latent” space, guided by the embedding. Produces a small tensor that encodes the image’s content.
  3. VAE (variational autoencoder) decoder. Decompresses the latent tensor into pixel-space image data.
  4. Save / display. Writes the PNG to disk and shows it in the UI.

Every commercial AI art product runs this pipeline behind a button. ComfyUI shows it as four connected nodes. You can now insert things between the nodes: a second encoder to combine two prompts with weighting, a ControlNet to condition the sampler on a pose image, a tiled upscaler between VAE and save to break a 4K render into manageable tiles. Each of these is a new node, connected with a single drag.

The practical advantages, once the learning curve flattens:

  • Reproducibility. A workflow is saved as JSON. Drop the JSON on someone else’s ComfyUI and they get the exact same pipeline, down to seed and sampler config.
  • Branching. Render three variations from the same latent, one per sampler setting, in a single run.
  • Debuggability. When an output is wrong, you can inspect the intermediate latents and watch where the pipeline took a turn.

The cost is that the first hour is disorienting. Every tutorial starts the same way: “connect the checkpoint loader to the KSampler, route the positive prompt and the negative prompt, attach a latent image source, then VAE-decode”. After doing that twice, you stop reading tutorials.

The Action

Running ComfyUI in a container with GPU access

The install is straightforward; the configuration that makes it production-ish is the part worth documenting. ComfyUI is a Python app. It runs fine natively on the AI node. I run it in a Docker container anyway, for the same reason everything else in the lab is containerised: clean rollback, no leaked dependencies on the host.

# docker-compose.yml for ComfyUI on the AI node (bare-metal host).
services:
  comfyui:
    image: ghcr.io/ai-dock/comfyui:latest-cuda
    container_name: comfyui
    restart: unless-stopped
    runtime: nvidia   # Pass GPU through to the container.
    environment:
      NVIDIA_VISIBLE_DEVICES: all
      NVIDIA_DRIVER_CAPABILITIES: compute,utility

      # Use the ZFS pool for model checkpoints — these files are large.
      CF_TUNNEL_TOKEN: ""
      WEB_PASSWORD: "${WEB_PASSWORD}"

    volumes:
      # Models persist on the ZFS pool and survive container rebuilds.
      - /tank/comfyui/models:/opt/ComfyUI/models
      - /tank/comfyui/output:/opt/ComfyUI/output
      - /tank/comfyui/user:/opt/ComfyUI/user

    ports:
      - "198.51.100.20:8188:8188"

    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

Bring it up, open the web UI at http://198.51.100.20:8188, drop in a base Stable Diffusion XL checkpoint, and render the first image. The checkpoint is ~6 GB; the first download takes a minute on gigabit, then everything is local.

What broke

The weekend I installed ComfyUI, the latest PyTorch build was a version ahead of the CUDA runtime I had pinned in entry 14. ComfyUI started, loaded the model, and at the first inference step crashed with:

RuntimeError: CUDA error: no kernel image is available for execution on the device.

The error reads like a hardware failure; it is not. It means the compiled PyTorch kernels were built for a CUDA compute capability (sm_89 for Ada Lovelace cards) that my installed CUDA runtime did not include. The fix was to either downgrade PyTorch to the version matching my CUDA runtime, or upgrade the CUDA runtime to match PyTorch. I chose the upgrade path, because the newer CUDA runtime was backwards-compatible with the Ollama install from entry 14:

# Uninstall the older CUDA runtime.
sudo apt remove nvidia-cuda-toolkit

# Install the version matching current PyTorch (12.1 at the time).
# Via NVIDIA's apt repository — see their docs for the current keyring.
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt install cuda-toolkit-12-1

# Rebuild the container so PyTorch picks up the new runtime.
docker compose down
docker compose up -d --build

After the runtime upgrade, the render completed in seven seconds. I wrote a sticky-note rule on the monitor: pin PyTorch and CUDA versions together; treat them as a single dependency. A month later the note paid for itself when a naive apt upgrade would have nudged the runtime and broken ComfyUI again.

A smaller, less glamorous bug: the second container run could not write output files. Inside the container, ComfyUI runs as UID 1000; on the ZFS pool, the /tank/comfyui/output directory was owned by root. The container could read model checkpoints (world-readable) but not write outputs. One chown -R 1000:1000 /tank/comfyui/{output,user} on the host, and images started landing in the output directory. The fix is boring; forgetting it costs twenty minutes.

Why exposing the graph is the point

Commercial image-generation products hide the pipeline because simplicity sells. The pipeline exists regardless; you just do not get to touch it. For professional or creative work, that trade-off is wrong. A designer who wants a specific lighting variation cannot ask a one-click product to change the CFG scale of the first half of the diffusion steps while leaving the second half alone; ComfyUI lets you wire that in three minutes by adding a KSamplerAdvanced node with a step range.

The graph is not a tax. It is the interface the tool should have had from the start. Once you accept that, ComfyUI stops looking like airplane wiring and starts looking like the schematic of a thing you can finally shape.

Footnotes

  1. ComfyUI is GPL-licensed; home at github.com/comfyanonymous/ComfyUI. The Stable Diffusion research paper is Rombach et al. (2022), “High-Resolution Image Synthesis with Latent Diffusion Models”, arxiv.org/abs/2112.10752. ↩

Table of Contents