{"record":{"id":"49484e60477f3c41","repo":"Comfy-Org/ComfyUI","slug":"invalid-input-shape-x-shape","errorCode":null,"errorMessage":"Invalid input shape: {x.shape}","messagePattern":"Invalid input shape: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/lightricks/vae/causal_video_autoencoder.py","lineNumber":1115,"sourceCode":"\n\ndef patchify(x, patch_size_hw, patch_size_t=1):\n    if patch_size_hw == 1 and patch_size_t == 1:\n        return x\n    if x.dim() == 4:\n        x = rearrange(\n            x, \"b c (h q) (w r) -> b (c r q) h w\", q=patch_size_hw, r=patch_size_hw\n        )\n    elif x.dim() == 5:\n        x = rearrange(\n            x,\n            \"b c (f p) (h q) (w r) -> b (c p r q) f h w\",\n            p=patch_size_t,\n            q=patch_size_hw,\n            r=patch_size_hw,\n        )\n    else:\n        raise ValueError(f\"Invalid input shape: {x.shape}\")\n\n    return x\n\n\ndef unpatchify(x, patch_size_hw, patch_size_t=1):\n    if patch_size_hw == 1 and patch_size_t == 1:\n        return x\n\n    if x.dim() == 4:\n        x = rearrange(\n            x, \"b (c r q) h w -> b c (h q) (w r)\", q=patch_size_hw, r=patch_size_hw\n        )\n    elif x.dim() == 5:\n        x = rearrange(\n            x,\n            \"b (c p r q) f h w -> b c (f p) (h q) (w r)\",\n            p=patch_size_t,\n            q=patch_size_hw,","sourceCodeStart":1097,"sourceCodeEnd":1133,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/lightricks/vae/causal_video_autoencoder.py#L1097-L1133","documentation":"Raised by the patchify helper in causal_video_autoencoder.py when x.dim() is neither 4 (2D images) nor 5 (3D video). Patch folding is only implemented for image and video layouts; other dimensionalities cannot be rearranged.","triggerScenarios":"Calling patchify (or a caller that uses it, e.g. per-latent patch handling) on a 3-dim or 6-dim tensor, such as an unbatched tensor or one with an extra frame-packing axis.","commonSituations":"Custom node code that slices latents and loses the batch dim; mixing 2D and 3D VAE code paths; feeding patchified tensors in twice.","solutions":["Ensure input is (B, C, H, W) or (B, C, F, H, W) before calling patchify","Add the batch dimension if it was squeezed away","Skip patchify when patch_size_hw == 1 and patch_size_t == 1, as it is a no-op"],"exampleFix":"# before\nx = patchify(clip_tensor, patch_size_hw=2)  # clip_tensor.dim() == 3\n\n# after\nx = patchify(clip_tensor.unsqueeze(0), patch_size_hw=2)","handlingStrategy":"type-guard","validationCode":"if x.dim() not in (4, 5):\n    raise ValueError(f\"patchify expects 4D or 5D input, got {x.dim()}D\")","typeGuard":"def is_patchifiable(t) -> bool:\n    return t.dim() in (4, 5)","tryCatchPattern":null,"preventionTips":["Keep latents batched as (B,C,H,W)/(B,C,F,H,W) through the patchify path","Skip patchify when patch sizes are 1 — it is a no-op"],"tags":["shapes","patchify","video-vae","ltx"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}