Nodes/ComfyUI/VAE Encode (for Inpainting)
ComfyUI Node Runs on cloud

VAE Encode (for Inpainting)

The correct way to start an inpaint in ComfyUI

By Comfy-Org·Created 4 years ago·Updated about 2 hours ago· 129,809
VAE Encode (for Inpainting)
  • pixels
  • vae
  • mask
  • LATENT
grow_mask_by6

Every guide to inpainting in ComfyUI tells you to use this node, and most of them never explain why it's special - so let's be blunt: a plain VAE Encode will not let you inpaint. It produces a latent with no mask attached, and without a mask the sampler regenerates the whole image. VAE Encode (for Inpainting) is the node that does the encode and attaches the mask, plus a bit of seam-prevention magic. It's the difference between "fix this region" and "redo the whole picture."

Four inputs:

  • pixels - the IMAGE to encode.
  • vae - your VAE.
  • mask - the MASK marking what to regenerate (white = regenerate).
  • grow_mask_by - default 6. Pixels to grow the mask before encoding.

Output: a LATENT that carries a noise_mask, ready for a KSampler at partial denoise.

What it does under the hood

Three things, in order. First, it aligns the image to the VAE's spatial compression (8× on most models), cropping a few stray pixels so encode and mask line up exactly - a source image that isn't a clean multiple of 8 gets quietly centered-and-cropped. Second, it encodes the image. Third, and most importantly, it attaches the noise mask - and it grows it by grow_mask_by pixels before attaching. That growth is the seam trick: the masked region bleeds a few pixels beyond your drawn area, so the denoised content blends into the untouched surround instead of forming a hard visible boundary in latent space. The default 6 is the community's hard-won sweet spot; 0 gives you crisp seams, 15+ starts eating into surrounding detail.

The one field that matters

Set grow_mask_by once and mostly leave it. For small fixes (faces, hands, a stray object) 4–8 is right. For big regeneration areas you can go higher. If you see a grey halo around your fix, the mask grew too far or your denoise is too high; if you see a hard edge, it didn't grow enough.

The workflow shape

VAE Encode (for Inpainting) → KSampler (denoise between 0.3 and 0.8 - the dial controls how much the masked region changes, from subtle rework to full regeneration) → VAE Decode → Image Composite Masked to paste the regenerated region back over the original pixels. That last step matters because the encode/decode round trip nudges unmasked pixels slightly; compositing keeps the rest pixel-identical.

Common traps

  • Denoise left at 1.0. The mask says where, denoise says how much. At 1.0 the masked region is a full regeneration that ignores the original - the classic "it ignored my image" report. Lower it.
  • Mask resolution. The mask must match the image size. A mask from a smaller load will land the inpainting region in the wrong place.
  • It doesn't take a latent. Some people try to feed this node a latent they already have - it takes pixels (an IMAGE). If you need to attach a mask to an existing latent, that's Set Latent Noise Mask's job.
  • Old-model note: the original SD 1.5 era had dedicated inpainting checkpoints that wanted a different (masked-latent) encode. On modern stacks this node is the one, and the noise-mask mechanism is what makes it work on any checkpoint.

It's a tiny node that does three unglamorous jobs, and getting all three right is what separates inpainting that looks natural from inpainting that looks like a patch.

Categorymodel/latent

Inputs (4)

NameTypeDefaultDescription
pixelsIMAGE
vaeVAE
maskMASK
grow_mask_byINT60–64

Outputs (1)

NameTypeDescription
LATENTLATENT