FlatLatentsIntoSingleGrid
Turn a Latent Batch Into One Big Grid Latent
- latents
- LATENT
FlatLatentsIntoSingleGrid takes a batch of N latents and rearranges them into one grid-shaped latent - a single 4D tensor where the batch is laid out side by side. It's the latent-space cousin of "make me a contact sheet," and it's the node to reach for when you want to sample an entire batch in one pass and end up with a single tiled image.
Why you'd reach for it
ComfyUI batches are everywhere, but a lot of downstream nodes (and a lot of model architecture) behave differently on a [N, ...] batch than on a single image. This node collapses the batch into the spatial dimensions: N latents become one latent that's a grid of tiles, roughly ceil(sqrt(N)) wide. From there you can run it through a single KSampler pass or feed it to nodes that want one image-sized latent.
Where people actually use it: batch-to-grid previews, tiled upscaling (grid the latents, upscale the whole thing, then split it back), and any workflow where "N separate images in a row" beats "one node processing N images as a batch." If you've already got a stack of latents you'd like to see as a grid before committing to decoding each, this is the tool.
How it works
It reads the batch size N from the latent, computes length_in_tiles = ceil(sqrt(N)), and allocates a new latent with enough height for ceil(N / length_in_tiles) rows and length_in_tiles columns. Each latent is copied into its slot in reading order: left to right, top to bottom. Tiles that don't fill the last row are left as zeros - worth knowing if you decode the grid and see an empty band on the right of the bottom row.
The single input is latents (a LATENT batch). The single output is a LATENT - one grid, ready for a sampler or a VAE decode.
Install
Part of bmad4ever's pack:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
then restart ComfyUI. Manager users search "comfyui_bmad_nodes". It's pure PyTorch tensor work, so the pack's heavier Python dependencies don't matter for this node.
Common issues
- Not a power of two count. No problem - the grid just leaves empty space in the last row, which reads as black when decoded.
- "This changed my batch dimension!" Yes - that's the entire point. If something downstream expects N samples, you've collapsed them into one. Split the result if you need the originals back.
- Feeding a single latent. A one-item batch still grids to 1×1, so don't bother for single latents.
When you want your whole batch as one picture without decoding each latent separately, this is the cleanest path in the pack.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| latents | LATENT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |