VAE Encode Batch Chunked
Push a big image batch into the latent space without OOMing first
- pixels
- vae
- latent
Every big img2img batch has to start somewhere, and that somewhere is usually a VAE encode. Stock ComfyUI encodes the whole image batch in one shot; VAE Encode Batch Chunked does it in slices so the encode step stops being the thing that kills your run.
It's the encode-side partner to SamplerCustomAdvancedChunked and VAE Decode Batch Chunked. The full chain from this pack:
IMAGE batch -> VAE Encode Batch Chunked -> SamplerCustomAdvanced Chunked -> VAE Decode Batch Chunked
That reads like a normal img2img graph with "chunked" sprinkled in, which is exactly the point - the pack keeps the standard SamplerCustomAdvanced path intact and just slices memory-heavy steps.
How it works
Inputs are minimal: pixels (IMAGE), vae (VAE), chunk_size (INT, default 8), and clear_cache_between_chunks (BOOLEAN, default off). It iterates over the batch in chunk_size-sized slices, runs vae.encode(...) on each, and concatenates the results into a single latent (LATENT) output ready for the sampler.
Two behaviors worth knowing about, straight from the source:
- It trims extra image channels. Before calling
vae.encode, it drops anything past the first three channels of each pixel slice. That keeps RGBA-style image batches from crashing the encode while leaving ordinary RGB input untouched. If you feed it a transparent image, be aware the alpha channel is ignored rather than encoded. clear_cache_between_chunks(default off) runs a soft cache clear between slices. Flip it on if you're encoding a long batch and VRAM usage creeps up across runs; leave it off for speed.
The one knob you set
chunk_size is really the whole UI. Default 8 is fine for typical batches; drop it toward 2–4 if a long batch still OOMs, raise it if you have a 24 GB card and want fewer, fatter chunks. That's the whole node, honestly - and that's a feature. It doesn't invent new behavior, it just keeps a stock operation from exhausting memory.
The latent output feeds directly into SamplerCustomAdvancedChunked's latent_image input, and the noise/guider/sampler/sigmas wires come from your normal custom-sampling setup.
Installing it
Part of the xmarre/ComfyUI-ChunkedSampling pack. In ComfyUI Manager, search "ComfyUI-ChunkedSampling" and install; or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/xmarre/ComfyUI-ChunkedSampling
Restart ComfyUI. No requirements.txt to satisfy and no models to download - the pack only calls ComfyUI's own VAE API.
Gotchas
The honest version: this is a memory tool, not a speed tool, so a giant batch still costs the same total encode time. And the pack is young and niche, so don't expect a big community around it yet. But for the "I have 60 reference frames and a 12 GB card" problem, encode-in-chunks is the boring, correct answer - you'd rather have it and not need it than find out the hard way that your whole batch was one encode away from dying.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| pixels | IMAGE | — | |
| vae | VAE | — | |
| chunk_size | INT | 81–4096 | — |
| clear_cache_between_chunks | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | — |