VAE Encode (Mira SubPack)
A VAEEncode that won't OOM on your batch — encode tiles one at a time
- pixels
- vae
- samples
The stock VAEEncode is fine until it isn't. Feed it a batch of images - say, the 16 tiles your tiled upscaler just produced - and it tries to encode the whole batch at once, which is exactly how you meet the CUDA out-of-memory error on a 6GB card. VAE Encode (Mira SubPack) is the same node with a batching strategy: encode each image separately, concatenate the latents at the end. That's the entire trick, and it's a genuinely useful one for tiled workflows.
You'll see it doing real work in the Mira tiled-upscale loop this pack is built around: ImageCropTiles → VAEEncode_MiraSubPack → tiled KSampler → VAEDecode_MiraSubPack → OverlappedImageMerge. Encode-then-sample-then-merge is standard hi-res-fix territory (the upscaling doc's tiled-diffusion section), and the encode step is where VRAM dies first because the VAE processes the whole batch as one tensor.
How it works
The mechanism, straight from the source: if the batch has one image, it uses the standard vae.encode() path unchanged. If there are multiple, it loops, encodes pixels[i:i+1] individually, collects each latent, and torch.cats them back into a single samples tensor. Peak VRAM is one image's worth of encoding instead of the whole batch's - you trade a bit of time for a lot of headroom. It handles both dict-style and raw-tensor vae.encode() returns defensively.
Inputs and output
- pixels - the IMAGE batch to encode.
- vae - any ComfyUI VAE (SDXL, FLUX, Qwen Image - they all follow the same
encode()interface).
One output: samples (LATENT), wired straight into a KSampler or the pack's ImageTiledKSamplerWithTagger.
Install
It's part of ComfyUI_MiraSubPack, so:
cd ComfyUI/custom_nodes
git clone https://github.com/mirabarukaso/ComfyUI_MiraSubPack
or search "MiraSubPack" in ComfyUI Manager and restart. Pure PyTorch, zero extra dependencies.
When to reach for it
Honestly, for a single image it's pointless - the stock node does the identical thing with less overhead. This node earns its place the moment your batch grows: tiled upscaling, multi-frame passes, dataset encoding in one go. If you've ever hit OOM "just encoding images," this is the cheap fix that costs nothing to try.
The trade is time - sequential encoding of a 16-tile batch is slower than a parallel attempt that crashes. And there's no real downside to swapping it in permanently in a tiled graph, since the single-image path is byte-for-byte the standard behavior. For the beginners reading this because a tiled workflow told them to grab it: connect pixels and vae, don't touch anything else, and let the merge side of the loop worry about putting the tiles back together.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| pixels | IMAGE | — | |
| vae | VAE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| samples | LATENT | — |