{"record":{"id":"971879068805368a","repo":"Comfy-Org/ComfyUI","slug":"invalid-input-shape-x-shape-971879","errorCode":null,"errorMessage":"Invalid input shape: {x.shape}","messagePattern":"Invalid input shape: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/wan/vae2_2.py","lineNumber":176,"sourceCode":"                x = layer(x)\n        return x + self.shortcut(old_x)\n\n\ndef patchify(x, patch_size):\n    if patch_size == 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, r=patch_size)\n    elif x.dim() == 5:\n        x = rearrange(\n            x,\n            \"b c f (h q) (w r) -> b (c r q) f h w\",\n            q=patch_size,\n            r=patch_size,\n        )\n    else:\n        raise ValueError(f\"Invalid input shape: {x.shape}\")\n\n    return x\n\n\ndef unpatchify(x, patch_size):\n    if patch_size == 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, r=patch_size)\n    elif x.dim() == 5:\n        x = rearrange(\n            x,\n            \"b (c r q) f h w -> b c f (h q) (w r)\",\n            q=patch_size,\n            r=patch_size,\n        )","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/wan/vae2_2.py#L158-L194","documentation":"The Wan 2.2 VAE patchify() only reshapes 4-D spatial tensors (B, C, q*H, r*W) and 5-D spatio-temporal tensors (B, C, F, q*H, r*W). Any other rank cannot be interpreted as patchable image/video data and is rejected.","triggerScenarios":"Calling patchify on a 3-D tensor (C,H,W), a 6-D tensor, or a batch-of-lists converted incorrectly (e.g. double batch dims).","commonSituations":"Forgetting the batch dim; stacking an extra dim from dataloader output; feeding patchified output back into patchify.","solutions":["Ensure input is 4-D (B,C,H,W) or 5-D (B,C,F,H,W); add the batch dim if missing (x.unsqueeze(0)).","Confirm spatial dims are divisible by patch_size — otherwise use unpatchify correctly rather than nesting calls.","Check intermediate shapes in the pipeline with prints/asserts before patchify."],"exampleFix":"# before\nx = patchify(img_c_h_w)  # dim()==3 -> raises\n# after\nx = patchify(img_c_h_w.unsqueeze(0))  # (1,C,H,W)","handlingStrategy":"validation","validationCode":"if x.dim() not in (4, 5):\n    raise ValueError(f\"patchify expects 4-D or 5-D input, got {tuple(x.shape)}\")\nxp = patchify(x, patch_size)","typeGuard":"def is_patchifiable(x) -> bool:\n    return x.dim() in (4, 5)","tryCatchPattern":null,"preventionTips":["Always include the batch dimension in image/video tensors.","Ensure H and W are divisible by patch_size before calling."],"tags":["wan","vae","patchify","tensor-rank"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}