LatentOperationReshape
How to break a latent's shape (and maybe your workflow)
- op
Here's a sentence you should tattoo somewhere: just because you can reshape a latent doesn't mean you should. LatentOperationReshape changes the tensor's shape - (1, 2, 3) becomes valid, 1, 2, 3, 4 becomes valid - and the code happily does it. What it doesn't do is preserve any of the meaning that shape carries. ComfyUI latents are [batch, channels, height, width]; the moment you flatten or reorder that, the downstream sampler and VAE will interpret the data as nonsense. This node exists for one honest reason: feeding the latent's samples to a custom consumer that expects a specific shape. If you're not doing that, you're almost certainly about to break something.
How it works
new_shape = parse_shape(shape) # strips parens, splits on commas
new_latent = latent.reshape(new_shape)
if contiguous:
new_latent = new_latent.contiguous()
return new_latent
Two inputs:
shape(STRING, required) - the target shape, as a tuple-like string. The author's own tooltip shows the accepted formats:(1, 2, 3)or1, 2, 3, 4.parse_shapestrips parentheses and commas, so both styles work.contiguous(BOOLEAN, optional, defaultfalse) - calls.contiguous()after the reshape, which forces the tensor's memory layout to match the new shape. Almost always safe to leave off; occasionally needed to satisfy a consumer that asserts on strides. The tooltip describes it plainly: "Whether to reshape continuously."
The hard constraint: the total number of elements must be unchanged. A [1, 4, 64, 64] latent has 16,384 elements; you can reshape it to [1, 16384] or [16384, 1] or [1, 4, 4096], but not to a shape with a different product. If you try, PyTorch raises a RuntimeError at execution time and the workflow errors out. That's at least a loud failure.
The trap, honestly stated
The danger isn't the error - it's the success. Reshape never checks that your new shape means anything. A [1, 4, 64, 64] latent reshaped to [1, 64, 64, 4] looks fine, runs fine, and is now channel-last data that every subsequent ComfyUI node will misread as [batch, height, width, channels]. You won't get an exception; you'll get a silently mangled image or a decoder that produces noise. That's the failure mode to fear. Reshape is a "I know exactly what my custom tool expects" node, not a "let me see what happens" node.
The op output, and install
Output is op of type LATENT_OPERATION, as with every node in this pack - a deferred closure with no apply node shipped. You'll need a LATENT_OPERATION consumer (Sonar's SonarApplyLatentOperationCFG is the one that exists) or your own apply node; wiring op straight into a VAE Decode gives a type mismatch.
Install is the usual: ComfyUI Manager → search ComfyUI-latent-ops, or git clone https://github.com/hnmr293/ComfyUI-latent-ops into ComfyUI/custom_nodes, then restart. No requirements.txt, no model downloads, plain PyTorch. It's hnmr293's private latent workbench (he wrote sd-webui-cutoff and llul), with no community tutorials to speak of - latent_ops/ops.py is the documentation. Everything lives under hnmr/latent_ops.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| shape | STRING | Example: (1, 2, 3) 1, 2, 3, 4 | |
| contiguousopt | BOOLEAN | false | Whether to reshape continuously. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| op | LATENT_OPERATION | — |