XB-BOX - VAE修补编码(原版优化)
Inpainting encode with a cleanup knob — same masked latent, less OOM
- pixels
- vae
- mask
- LATENT
VAEEncodeForInpaint is the standard way to get an image + mask into a latent that a sampler can inpaint inside. XB_VAEEncodeForInpaint is a faithful copy of that node with exactly one addition: the XB_ToolBox cleanup dropdown. Dig into the source and you'll see it deep-copies the official node's input types, appends the cleanup enum, and forwards everything through nodes.VAEEncodeForInpaint().encode(**kwargs). Nothing about the mask handling, the grow, or the latent math is touched.
If that sounds like a lot of ceremony for a small change, it is - and that's the entire design philosophy of the pack's "原版优化" (original-vanilla optimized) line. Rather than reinvent inpainting encoding, the author reuses ComfyUI's battle-tested implementation and adds the one thing his AMD/ROCm-targeting toolset cares about: an explicit, staged VRAM cleanup that runs before the encode, so a fragmented cache doesn't OOM you at the worst moment.
When you'd swap it in
You're in a video or high-res workflow where the encoder is the thing that dies. Inpainting pipelines are usually part of bigger graphs - face fixing, object removal, character-mask work in Wan - and by the time you reach the encode, VRAM is already full of a loaded model and a couple of latents. Dropping this node in lets you unload models to RAM right before the encode without touching any other part of the graph. If your plain inpainting encode already works, there's no reason to switch.
Inputs that matter
- pixels (IMAGE) - the image to encode.
- vae (VAE) - your VAE.
- mask (MASK) - the region to inpaint; the encoder packs this into the latent's noise mask.
- grow_mask_by - pixels to dilate the mask by, default 6. If you're getting inpainted edges that cut through detail, bump this; if the repaired area is leaking outside the region, drop it.
- cleanup - the four Chinese levels from the wrapper family: 不做任何清理 (none, default), 单次缓存清理 (cache empty), 卸载显存模型 (unload VRAM models), 卸载全量模型 (full unload + deep GC).
Output is one LATENT carrying the masked sample, which goes straight into your sampler.
The gotcha
Same as every wrapper in this family: the default cleanup is "no cleanup," so out of the box it's a pixel-identical drop-in for the core node. The performance is not faster, and if you set the nuclear unload on a node that executes every frame of a loop, you'll pay reload costs over and over. Treat cleanup as a deliberate pre-step for the big encode, not a permanent setting.
Installing it
Not standalone - it ships with XB_ToolBox. Via Manager: search "XB_ToolBox" and install. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/WJLUOXIAO/XB_ToolBox.git
Restart ComfyUI after. No extra pip packages are needed for this node - it calls ComfyUI's own VAEEncodeForInpaint - though the pack installs opencv-python and easyocr for its other modules. If Manager is set to auto-install requirements and you see those in the log, that's normal.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| pixels | IMAGE | — | |
| vae | VAE | — | |
| mask | MASK | — | |
| grow_mask_by | INT | 60–64 | — |
| cleanup | COMBO | 不做任何清理 | 4 options: 不做任何清理, 单次缓存清理, 卸载显存模型, 卸载全量模型 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |