Nodes/ComfyUI/Rebatch Latents
ComfyUI Node Runs on cloud

Rebatch Latents

Rebatch latents when the batch size stops fitting your plan

By Comfy-Org·Created 4 years ago·Updated about 3 hours ago· 129,870
Rebatch Latents
  • latents
  • LATENT
batch_size1

Somewhere in a video workflow you end up with a list of latents: one per frame, one per chunk, one per clip segment. Now you want to run a node that expects them in neat batches of a certain size, or you want to pack them bigger to save GPU round-trips. That's the job of Rebatch Latents - it takes a list of latents and re-slices them into a new list where every entry holds exactly batch_size samples.

Think of it as the latent equivalent of a deck-splitting routine: it doesn't change what's in the cards, just how they're dealt.

What it actually does

Under the hood it pulls three things out of each input latent - the samples, the noise mask, and a batch_index that tracks where each sample came from - concatenates the ones it can, then slices them into batch_size chunks. The remainder that doesn't fill a full batch gets appended as its own output entry rather than dropped, which is the polite behavior that keeps you from silently losing frames. The batch_index is preserved throughout, which matters if you later use LatentFromBatch or a mask-aware node that needs to know which sample is which.

Inputs and outputs

  • latents (LATENT, list) - the collection you want re-chunked.
  • batch_size (INT, 1–4096, default 1) - the target size of each output entry.

Output is a single LATENT list, so anything downstream that consumes a list slots straight in.

How you get it

It ships with ComfyUI core - no extension, nothing to install. It's also one of the old guard; it's been in the codebase since the early days (2023), so it's not a shiny recent addition, just a quietly dependable utility.

The traps

The main one: Rebatch Latents will not merge latents of different spatial sizes. If two list entries have different height/width, it keeps them in separate output entries rather than trying to concatenate them - the concat would be shape-invalid anyway. If you actually want a single batch out of mixed sizes, upscale to a common resolution first.

Second: batch_size of 1 is not useless, it's a specific tool - it splits everything into single-item batches, which is exactly what you want when you're about to process each latent independently. If you set it absurdly high, you get one big batch and possibly a VRAM surprise. Pick the size that matches your GPU's comfort zone, not the largest number available.

Third, worth knowing: this node is the latent twin of RebatchImages, which does the same reshaping for image tensors. If you're juggling both, they behave the same way, and they're both built in.

Categorymodel/latent/batch

Inputs (2)

NameTypeDefaultDescription
latentsLATENT
batch_sizeINT11–4096

Outputs (1)

NameTypeDescription
LATENTLATENT