Nodes/ComfyUI_agilly1989_motorway/RebatchLatents_motorway_edition
ComfyUI Node

RebatchLatents_motorway_edition

RebatchLatents from the bus — reshape latent batches without touching pixels

By agilly1989·Created 2 years ago·Updated about a year ago· 7
RebatchLatents_motorway_edition
  • MOTORWAY 🚌💨
  • MOTORWAY 🚌💨
INPUT_latents_keylatents
batch_size1
OUTPUT_LATENT_keyLATENT

In the latent world, "batch" is just a leading dimension on a tensor, and sometimes you need to regroup it. RebatchLatents takes a latent batch - the compressed representation between VAE encode and decode - and reshapes it into batches of batch_size. Same data, same pixels-when-decoded, different grouping.

This matters because downstream nodes have opinions about batch layout. A video workflow that processes latents clip-by-clip, a hi-res pass that wants each image's latents handled separately, or a custom sampler chain that expects a specific batch shape - all of them are reasons to reach for the rebatch node. You'll usually see it used alongside RebatchImages so the latent grouping and the decoded-image grouping stay consistent with each other.

On the bus

The _motorway_edition version reads from the MOTORWAY 🚌💨 bus by key instead of by wire:

  • INPUT_latents_key (default latents) - which bus key holds the latent batch.
  • batch_size (default 1, range 1–4096) - latents per output batch. The default of 1 is genuinely useful: it splits a batch into individual latents, which is what you want when processing each image on its own.
  • OUTPUT_LATENT_key (default LATENT) - where the reshaped batch is written back onto the bus.

The only return is the bus; the reshaped latents ride inside it under LATENT. Keys are case-sensitive and shared by name across the workflow - if the sampler wrote LATENT and you read latents, that's a silent miss, not an error, until something downstream asks for the value and the bus throws.

A couple of practical notes. If the count isn't divisible by batch_size, the last batch is simply smaller - no padding, no error. And rebatching latents is cheap: you're reshaping a tensor dimension, not decoding anything. The cost comes later, when whatever consumes the new layout actually runs.

Install

No dependencies, no models:

cd ComfyUI/custom_nodes
git clone https://github.com/agilly1989/ComfyUI_agilly1989_motorway

or via ComfyUI Manager under the pack title ComfyUI_agilly1989_motorway, then restart.

The fine print

The pack is a beta project - the README literally opens "IF THINGS BREAK ITS BECAUSE I BROKE IT" - and the _motorway_edition clones were auto-generated by a cloner that build 1.1.7 removed. On a fresh install this node may not exist; the stock RebatchLatents in core always does the same job without the bus.

Bus failure is the usual KeyError: 'hash_...' doesn't exist in motorway, meaning a key was never stored upstream - verify the ramp actually put the latents on the bus under the exact name you typed. And the shape lesson from image rebatching applies twice over here: latent tensor shapes are easy to mismatch, and a node that worked on one layout will just error on another. When a latent pipeline breaks after a rebatch, assume shape mismatch before anything cleverer.

Categoryagilly1989 Nodes/Motorway-ed/latent/batch

Inputs (4)

NameTypeDefaultDescription
MOTORWAY 🚌💨MOTORWAY 🚌💨
INPUT_latents_keySTRINGlatents
batch_sizeINT11–4096
OUTPUT_LATENT_keySTRINGLATENT

Outputs (1)

NameTypeDescription
MOTORWAY 🚌💨MOTORWAY 🚌💨