ComfyUI Node

Batch Controller

Batch Controller — force any tensor to exactly the batch size you want

By aesethtics·Created about a year ago·Updated about a year ago· 1
Batch Controller
  • input
  • output
batch_size1

Batch sizes are ComfyUI's quiet troublemaker. You load 12 frames, a node down the line expects 8, and suddenly you're staring at a shape mismatch error that doesn't tell you which node is at fault. This node is the referee: it takes any tensor and forces its first dimension to exactly the batch size you specify, no matter what came in. Bigger batch? It trims it. Smaller batch? It tiles it up. Same size? It passes through untouched.

It's from the Utilitools pack, and it's a wildcard node - the input type is *, meaning it works on images, latents, masks, or anything else with a batch dimension. Two required inputs: input (any tensor) and batch_size (an INT from 1 to 64, default 1). One output, output, the resized tensor.

The mechanism - read this before you trust it

What the node does with a mismatched batch is the part you need to understand:

  • Too many items - it slices the tensor down to input[:batch_size], silently dropping the rest. This is a truncation. Feed it 12 frames and ask for 8 and you get frames 0–7. No warning, no error, the last four frames just vanish.
  • Too few items - it repeats the whole batch until it reaches the target, then slices to the exact count. Feed it 3 frames and ask for 8 and you get [f0, f1, f2, f0, f1, f2, f0, f1]. It tiles, it does not invent new content, and it does not interpolate.
  • Not a tensor - if the input has no .shape attribute at all, it passes through unchanged.

The tiling is the bit that surprises people. The node is not upscaling your batch or generating anything - it's duplicating existing frames to pad the count. For images that's usually fine (a repeated frame is still a valid frame). For latents feeding a sampler, just know that some of your "batch" is literally the same content twice.

Where you'll actually use it

The honest use cases: matching a latent batch to an image batch before a mask or conditioning operation that demands equal sizes; forcing an exact frame count for animation pipelines; or capping an over-large batch so a heavy node doesn't eat all your VRAM at once. It's a sledgehammer for "make these match," and it works because it's wildcard-typed.

The trap is that silent truncation. If you're doing animation work and your source has 12 frames but somewhere upstream it became 11, this node will happily "fix" it to 8 and you'll never be told a frame went missing. If correctness matters, verify your counts before this node, not after - the pack's Image Dimensions node (which reports batch size) is a good spot to check.

Installing it

Same routine as everything in this pack:

cd ComfyUI/custom_nodes
git clone https://github.com/aesethtics/ComfyUI-Utilitools

or search "Utilitools" in ComfyUI Manager, then restart ComfyUI. It's under Utilitools → Data. No dependencies, no model downloads - the whole pack is pure Python (plus torch, which ComfyUI already ships). It's a small, rarely-discussed pack, and this is one of its genuinely useful members - just don't let it hide your missing frames.

CategoryUtilitools/Data

Inputs (2)

NameTypeDefaultDescription
input*
batch_sizeINT11–64

Outputs (1)

NameTypeDescription
output*