Nodes/ComfyUI_KV_Edit/KV_Edit_Load
ComfyUI Node

KV_Edit_Load

The loader that lets Flux do surgery instead of repainting the whole photo

By smthemex·Created about a year ago·Updated 11 months ago· 60
KV_Edit_Load
  • model
  • model
unet
offloadtrue
use_inftrue

Every KV-Edit workflow starts here, so get this one right and the rest of the pack mostly runs itself. KV_Edit_Load takes a single-file Flux.1 dev checkpoint and turns it into a MODEL_KVEDIT - a model object that only the three other nodes in this pack can consume. You won't wire its output into a normal sampler or a VAE decode; you feed it to KV_Edit_PreData and KV_Edit_Sampler, or through KV_Edit_Load_LoRA on the way.

The "KV" in the name is the whole trick. KV-Edit is a training-free editing method from a 2025 paper (arXiv:2502.17363, "KV-Edit: Training-Free Image Editing for Precise Background Preservation"), ported to ComfyUI by smthemex - the same prolific paper-to-ComfyUI porter behind TwinFlow and a pile of other research ports. Instead of regenerating the whole frame and hoping the unmasked bits come back close, the sampler runs the image through the model once, caches the attention keys and values of the background, and reuses them during the edit. The background comes back essentially untouched, not just "similar." That's the thing mask-based editing still uniquely owns that instruction-editing models like Qwen-Edit and Flux Kontext quietly drop - the KB's inpainting essay calls it "bit-identical unmasked pixels," and it's exactly what KV-Edit is built around.

What you feed it

The unet dropdown lists everything in your ComfyUI/models/diffusion_models folder. Pick a single-file Flux.1 dev safetensors. The README spells out the two realistic options:

  • flux1-dev.safetensors (23.8 GB) - the full bf16 model from black-forest-labs/FLUX.1-dev.
  • flux1-kj-dev-fp8.safetensors (11 GB) - the community "kj" single-file fp8. Any filename containing fp8 flips on automatic quantization, which is why the README explicitly warns it does not support ComfyUI's own quantized (GGUF) checkpoints - it loads raw safetensors and does its own thing.

There's also an optional model input of type MODEL. If you leave unet on "none" and wire in a regular ComfyUI-loaded Flux model instead, the node tears down that ComfyUI model, copies its weights into its own Flux wrapper, and frees the original - a workaround for setups where the file path fails, not the recommended route.

The two toggles matter more than they look:

  • offload (default on): keeps the model on CPU and moves it to the GPU for the inference pass. On a 16 GB card you basically have to leave it on; with offload off you get speed if you've got the VRAM.
  • use_inf (default on): picks which edit engine the sampler uses. On is the fast RF-Solver single-pass path; off is the original two-stage inversion-and-reuse path. Defaults are sane - keep them until you know why you're changing them.

It returns one thing: model (MODEL_KVEDIT).

Install

ComfyUI Manager (search "ComfyUI_KV_Edit") works, or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/smthemex/ComfyUI_KV_Edit
cd ComfyUI_KV_Edit
pip install -r requirements.txt

Then restart ComfyUI. You also need the text encoders and VAE: clip_l.safetensors and t5xxl_fp8_e4m3fn.safetensors from comfyanonymous/flux_text_encoders, and ae.safetensors for the VAE. These go to KV_Edit_PreData, not here, but you'll need them before any workflow runs.

Where people get burned

Accelerate is a hidden hard dependency. requirements.txt doesn't list it, but the single-file loading path calls load_checkpoint_and_dispatch from it. Most ComfyUI installs already have it via other nodes; if you're on a minimal setup and get a NameError: name 'load_checkpoint_and_dispatch' is not defined, pip install accelerate fixes it.

It kicks everything else out of VRAM. After loading, the node calls unload_all_models() and soft_empty_cache(), so anything else you had loaded vanishes from memory. Load it last, once your workflow graph is built.

It's a big model on big hardware. Flux.1 dev is 12B parameters. Realistically you want 16 GB VRAM, and with the fp8 file plus offload you can scrape by on 12 GB - slowly. That's the price of the one editing method that leaves your background alone.

CategoryKV_Edit

Inputs (4)

NameTypeDefaultDescription
unetCOMBO1 options: none
offloadBOOLEANtrue
use_infBOOLEANtrue
modeloptMODEL

Outputs (1)

NameTypeDescription
modelMODEL_KVEDIT