ComfyUI Node

AssertShape

Pin the exact latent shape and stop guessing why downstream nodes break

By hnmr293·Created about a year ago·Updated about a year ago· 2
AssertShape
  • latent
  • latent
  • first_dim
  • last_dim
shape

Here's a workflow failure you've definitely felt: everything looks right, but the KSampler or a latent-op node rejects your input with a shape error that doesn't say which shape was wrong. AssertShape is the fix - it checks the exact shape of a latent against the one you declare, and errors with both sides on a mismatch. It's AssertDims' stricter sibling: instead of just counting dimensions, it pins every one.

It's part of hnmr293's ComfyUI-latent-ops pack (he's the same Hoshino behind sd-webui-cutoff and llul), and like the rest of the pack it lives under hnmr/latent_ops and needs nothing beyond what ComfyUI already ships.

What it does

The node parses your shape string into a tuple and compares it to latent["samples"].shape. Match? The latent passes through untouched and you get first_dim and last_dim as INT outputs. Mismatch? A ValueError naming both shapes, and the graph stops dead.

The one input that matters is shape, a string. The author's own tooltip spells out the two accepted formats:

(1, 2, 3)
1, 2, 3, 4

Parens are optional, commas are required, whitespace is fine. Write the full shape including the batch dim. For a standard B, C, H, W latent that's four numbers, e.g. 1, 4, 64, 64 for a single SDXL latent at 512×512.

Why you'd reach for it

Two situations. First, img2img: the incoming latent's shape is a contract with the sampler, and a mismatch quietly ruins results. Put AssertShape right after VAE Encode and you'll catch a 1024-pixel input hitting a 512-tuned pipeline before it wastes your time. Second, sharing workflows - a hard assertion tells the person loading your graph exactly what shape your latent-math chain expects, instead of letting it fail vaguely downstream. Batch-sensitive stuff (like a latent that must hold a stacked pair) is another classic spot.

Installing it

Via ComfyUI Manager, search "ComfyUI-latent-ops" and install. Manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/hnmr293/ComfyUI-latent-ops

Restart ComfyUI; the node appears under hnmr/latent_ops.

Troubleshooting

The usual miss is the batch dimension - you assert 1, 4, 64, 64 but your batch is 2, and it errors even though everything else lines up. That's correct behavior; adjust the string or the batch. Parens and whitespace are forgiving, so a copy-pasted (1,4,64,64) from a forum post works as-is. And remember this is a hard stop by design: if you only care about dimensionality, not exact values, AssertDims is the lighter check. Use both - an AssertShape early in a workflow is the cheapest debugging tool you'll add this week.

Categoryhnmr/latent_ops

Inputs (2)

NameTypeDefaultDescription
latentLATENT
shapeSTRINGExample: (1, 2, 3) 1, 2, 3, 4

Outputs (3)

NameTypeDescription
latentLATENT
first_dimINT
last_dimINT