Nodes/ComfyUI/Get Latent From Batch
ComfyUI Node Runs on cloud

Get Latent From Batch

Reach into a stack and pull one out

By Comfy-Org·Created 4 years ago·Updated about 6 hours ago· 129,874
Get Latent From Batch
  • samples
  • LATENT
batch_index0
length1

A batch in ComfyUI is just a latent with extra items stacked on its first dimension - batch size 4 means four images' worth of latent riding along in one tensor. Get Latent From Batch pulls a contiguous slice out of that stack so you can process one item (or a few) on its own. It's the boring-but-indispensable plumbing node you reach for whenever a workflow wants to treat one latent differently from its siblings.

The two numbers that do everything:

  • batch_index - where the slice starts, counting from 0. Negative values count from the end of the batch, so -1 grabs the last item.
  • length - how many items to take. Default 1, max 64. The node clamps both values to what the batch actually holds, so asking for more than exists just gives you what's there rather than an error.

Output is a LATENT containing only that slice, ready to feed a sampler, a VAE decode, or another latent node.

When you actually need it

Three patterns cover most uses. First, batch cherry-picking: generate a batch of four, pull out index 2, decode just that one to check it before spending a sampler pass on the rest. Second, video frame surgery: a video latent's frames live on the time axis, and video latents in ComfyUI are usually shaped batch × channels × frames × h × w - but some pipelines put frames on the batch axis, and this node is how you grab the first frame for a loop-closing trick or pull a specific frame range for re-rendering. Third, fan-out pipelines: batch a bunch of variations, then split them apart so each one can take a different path (different prompt, different upscale) before you recombine with Latent Batch.

Gotchas worth knowing

The slice is a view-based copy of the latent, but latent dicts carry extra metadata - like a noise_mask if you've used Set Latent Noise Mask - and the node copies that along. That's usually what you want, but if your mask is batch-sized and your slice is length 1, later nodes may behave oddly. Also keep in mind this is slicing, not selecting: it's contiguous runs only. To interleave or reorder items you need Latent Batch plus a few of these, which gets fiddly fast - for anything fancier, a batch-utility pack is the saner tool.

One more practical note: if you're doing the opposite - stacking items into a batch - that's the (deprecated) Latent Batch node or Repeat Latent Batch when you just want N identical copies. This node is purely the extraction half of the pair, and it's the half people forget exists until they need a single frame and don't want to decode everything.

It ships with ComfyUI core; no install, no model files, nothing to download. When in doubt, remember it's just indexing - batch_index 0, length 1 gives you the first item, which is the "I made a batch but only want one" default you'll use constantly.

Categorymodel/latent/batch

Inputs (3)

NameTypeDefaultDescription
samplesLATENT
batch_indexINT0-16384–16384
lengthINT11–64

Outputs (1)

NameTypeDescription
LATENTLATENT