Local image and video generation with ComfyUI
How ComfyUI's node graphs map onto the diffusion pipeline (model loader, text encoder, sampler, VAE), where model files go, memory and speed on consumer GPUs and Macs, LoRAs and ControlNet, running workflows through its API, and keeping custom nodes safe.
By Sandip Maity, Applied AI Engineer
ComfyUI is the most widely used local tool for image and video generation. Its interface is a graph of nodes, which looks intimidating at first and turns out to be the diffusion pipeline drawn out step by step. If you have read image and video diffusion, every node will be familiar.
What we checked. Node names, folders and the API below follow ComfyUI's documentation as of November 2026. We did not benchmark generation for this lesson, so the speed and memory guidance is qualitative; measure on your own hardware.
#The pipeline as nodes
- 1Load checkpointdiffusion model, text encoder and VAE from model files
- 2Text encodepositive and negative prompts become conditioning
- 3Empty latentthe starting noise at your chosen resolution
- 4KSamplerthe denoising loop: steps, sampler, scheduler, guidance
- 5VAE decodelatent to pixels
- 6Save imagewrites the file, with the workflow embedded
- Load checkpoint reads the model. Newer model families often ship as separate files (diffusion model, one or more text encoders, VAE) with a loader node for each.
- Text encode turns your prompt into conditioning vectors. Many recent models use a large language-model text encoder, which takes a lot of memory itself.
- KSampler is where the time goes. More steps means more time, roughly linearly. Few-step distilled models reach good quality in 1 to 8 steps (few-step generation).
- VAE decode converts the latent to an image. At high resolutions or for video it can need a lot of memory; tiled decoding helps.
Saved PNGs carry the full workflow in their metadata: dragging an image back into ComfyUI restores the graph that made it.
#Installing and organising
Install the desktop app or the portable package, or clone the repository into a Python environment. Model files go into folders under models/:
| Folder | What goes there |
|---|---|
models/checkpoints |
All-in-one model files |
models/diffusion_models |
Diffusion model weights shipped separately |
models/text_encoders |
Text encoders |
models/vae |
VAEs |
models/loras |
LoRA adapters |
models/controlnet |
ControlNet models |
The web interface runs on http://127.0.0.1:8188 by default. Keep it bound to localhost unless you put authentication in front of it.
#Memory and speed
What decides whether a workflow fits:
- The diffusion model's size and precision. Large recent image and video models are many billions of parameters; 8-bit and 4-bit variants (FP8, GGUF and others) cut memory a lot at some quality cost.
- The text encoder. Can be several GB; ComfyUI can offload it to system memory after encoding.
- Resolution and, for video, frame count. Latent size grows with both, and attention cost grows faster.
On NVIDIA GPUs, 12 to 16 GB runs most image models with quantised weights; 24 to 32 GB gives room for larger models and video. Apple Silicon runs ComfyUI through PyTorch's Metal backend; it works, but diffusion is compute-bound and Macs are slower than recent NVIDIA cards here. AMD support depends on ROCm (Linux) or other backends.
#Steering generation
- LoRAs add a style, character or concept with a small adapter loaded between the model and the sampler (LoRA in depth).
- ControlNet and similar adapters condition on an edge map, depth map or pose, so you control composition.
- Image-to-image and inpainting start from an existing image's latent instead of pure noise, with a "denoise" strength between 0 and 1.
- Upscaling with a dedicated model or a second low-denoise sampling pass at higher resolution.
#Running workflows as a service
Use "Export (API)" to save a workflow in API format, then submit it:
import json, urllib.request
wf = json.load(open("workflow_api.json"))
wf["6"]["inputs"]["text"] = "a lighthouse at dusk, oil painting" # node ids come from your export
req = urllib.request.Request("http://127.0.0.1:8188/prompt",
data=json.dumps({"prompt": wf}).encode(),
headers={"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(req))) # returns a prompt id; fetch results from /history/<id>ComfyUI queues jobs and runs them one at a time on the GPU; a websocket reports progress. For several users, put a small queue service in front and think about serving multimodal models.
#Custom nodes and safety
Custom nodes extend ComfyUI with new models and tools, and they are Python code that runs with your permissions. Install them only from sources you trust, prefer well-known nodes with active maintainers, review what updates change, and consider running ComfyUI in a container or a separate user account. Treat downloaded workflows that require unknown nodes with the same care. Model files should be in safetensors format rather than pickle-based formats (supply chain).
Check the licence of every model you use, especially for commercial work; image and video model licences vary widely (licences).
#Exercises
- Build the six-node text-to-image graph by hand, generate an image, then drag the PNG back in and confirm the graph is restored.
- Time the same prompt at 4, 8, 20 and 30 steps. Where does extra time stop improving the image for you?
- Export a workflow in API format and run it from a script with three different prompts.
Quick quiz
+10 XP per correct answer, +25 XP for a perfect score
1. In a ComfyUI graph, what does the KSampler node do?
2. What does the VAE decode step do?
3. Why are custom nodes a security concern?
4. Image generation runs out of memory on a 12 GB GPU. Which change helps most without changing the model family?
5. How do you run a ComfyUI workflow from your own program?
Up next · 15 min · Pro, first part free
Serving multimodal models: patterns per modality
How serving differs for vision-language models, speech recognition, speech synthesis, image and video generation and embeddings: what dominates latency and memory for each, batching and queueing, image token budgets and caching, streaming audio, GPU sharing, and the metrics to watch.
Continue →Found this useful?
Send it to someone who is learning the same thing.