{"record":{"id":"6eb221dc31b63707","repo":"Comfy-Org/ComfyUI","slug":"invalid-input-shape-sample-shape","errorCode":null,"errorMessage":"Invalid input shape: {sample.shape}","messagePattern":"Invalid input shape: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/lightricks/vae/causal_video_autoencoder.py","lineNumber":272,"sourceCode":"\n        if self.latent_log_var == \"uniform\":\n            last_channel = sample[:, -1:, ...]\n            num_dims = sample.dim()\n\n            if num_dims == 4:\n                # For shape (B, C, H, W)\n                repeated_last_channel = last_channel.repeat(\n                    1, sample.shape[1] - 2, 1, 1\n                )\n                sample = torch.cat([sample, repeated_last_channel], dim=1)\n            elif num_dims == 5:\n                # For shape (B, C, F, H, W)\n                repeated_last_channel = last_channel.repeat(\n                    1, sample.shape[1] - 2, 1, 1, 1\n                )\n                sample = torch.cat([sample, repeated_last_channel], dim=1)\n            else:\n                raise ValueError(f\"Invalid input shape: {sample.shape}\")\n        elif self.latent_log_var == \"constant\":\n            sample = sample[:, :-1, ...]\n            approx_ln_0 = (\n                -30\n            )  # this is the minimal clamp value in DiagonalGaussianDistribution objects\n            sample = torch.cat(\n                [sample, torch.ones_like(sample, device=sample.device) * approx_ln_0],\n                dim=1,\n            )\n\n        return sample\n\n    def forward_orig(self, sample: torch.FloatTensor, device=None) -> torch.FloatTensor:\n        r\"\"\"The forward method of the `Encoder` class.\"\"\"\n\n        max_chunk_size = get_max_chunk_size(sample.device if device is None else device) * 2  # encoder is more memory-efficient than decoder\n        frame_size = sample[:, :, :1, :, :].numel() * sample.element_size()\n        frame_size = int(frame_size * (self.conv_in.out_channels / self.conv_in.in_channels))","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/lightricks/vae/causal_video_autoencoder.py#L254-L290","documentation":"Raised in the Encoder's output post-processing (sample recombination path) when a per-channel/uniform latent tensor's dimensionality is neither 4 (B,C,H,W) nor 5 (B,C,F,H,W). The code repeats the last channel to rebuild the mean/std pair and only has 2D and 3D variants.","triggerScenarios":"Calling the encoder's output transform on a tensor with 3 or 6 dims, e.g. feeding a raw unbatched tensor or an already-patched/packed representation whose dim() is not 4 or 5.","commonSituations":"Custom pipelines that reshape latents before decode; feeding patchified latents directly back without unpatchifying; batch-dimension bugs that drop or add a dim.","solutions":["Ensure the tensor entering the VAE path is (B, C, H, W) or (B, C, F, H, W)","Unpatchify latents before passing them back if they were patchified elsewhere","Add a batch dimension with x.unsqueeze(0) if it is missing"],"exampleFix":"# before\nout = vae.decode(latents)  # latents.dim() == 3\n\n# after\nlatents = latents.unsqueeze(0)  # -> (1, C, H, W)\nout = vae.decode(latents)","handlingStrategy":"type-guard","validationCode":"if sample.dim() not in (4, 5):\n    raise ValueError(f\"expected (B,C,H,W) or (B,C,F,H,W), got {tuple(sample.shape)}\")","typeGuard":"def is_vae_latent_layout(t) -> bool:\n    return t.dim() in (4, 5)","tryCatchPattern":null,"preventionTips":["Check tensor.dim() before VAE encode/decode round trips","Unpatchify and re-add batch dims before feeding latents back into the VAE"],"tags":["shapes","runtime","video-vae","ltx"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}