{"record":{"id":"73b320db29e64b5e","repo":"Comfy-Org/ComfyUI","slug":"seedvr2-videoautoencoderklwrapper-decode-4-d-late","errorCode":null,"errorMessage":"SeedVR2 VideoAutoencoderKLWrapper.decode: 4-D latent input must use collapsed channel layout (B, {SEEDVR2_LATENT_CHANNELS}*T, H, W); got shape {tuple(z.shape)}.","messagePattern":"SeedVR2 VideoAutoencoderKLWrapper\\.decode: 4-D latent input must use collapsed channel layout \\(B, (.+?)\\*T, H, W\\); got shape (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/seedvr/vae.py","lineNumber":1489,"sourceCode":"        seedvr2_tiling = {} if seedvr2_tiling is None else seedvr2_tiling\n        if not isinstance(seedvr2_tiling, dict):\n            raise RuntimeError(\n                \"SeedVR2 VideoAutoencoderKLWrapper.decode: `seedvr2_tiling` must be a dict; \"\n                f\"got {type(seedvr2_tiling).__name__} with value {seedvr2_tiling!r}.\"\n            )\n\n        if z.ndim == 5:\n            _, c, _, _, _ = z.shape\n            if c != SEEDVR2_LATENT_CHANNELS:\n                raise RuntimeError(\n                    \"SeedVR2 VideoAutoencoderKLWrapper.decode: 5-D latent input must \"\n                    f\"have {SEEDVR2_LATENT_CHANNELS} channels; got shape {tuple(z.shape)}.\"\n                )\n            latent = z\n        elif z.ndim == 4:\n            b, tc, h, w = z.shape\n            if tc % SEEDVR2_LATENT_CHANNELS != 0:\n                raise RuntimeError(\n                    \"SeedVR2 VideoAutoencoderKLWrapper.decode: 4-D latent input must \"\n                    f\"use collapsed channel layout (B, {SEEDVR2_LATENT_CHANNELS}*T, H, W); \"\n                    f\"got shape {tuple(z.shape)}.\"\n                )\n            latent = z.reshape(b, SEEDVR2_LATENT_CHANNELS, -1, h, w)\n        else:\n            raise RuntimeError(\n                \"SeedVR2 VideoAutoencoderKLWrapper.decode: latent input must be \"\n                f\"4-D collapsed (B, {SEEDVR2_LATENT_CHANNELS}*T, H, W) or \"\n                f\"5-D (B, {SEEDVR2_LATENT_CHANNELS}, T, H, W); \"\n                f\"got shape {tuple(z.shape)}.\"\n            )\n        scale = BYTEDANCE_VAE_SCALING_FACTOR\n        shift = BYTEDANCE_VAE_SHIFTING_FACTOR\n        latent = latent / scale + shift\n\n        self.device = latent.device\n        enable_tiling = seedvr2_tiling.get(\"enable_tiling\", False)","sourceCodeStart":1471,"sourceCodeEnd":1507,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/seedvr/vae.py#L1471-L1507","documentation":"decode() accepts a 4-D latent in the collapsed layout (B, SEEDVR2_LATENT_CHANNELS*T, H, W); the channel dimension must be an exact multiple of SEEDVR2_LATENT_CHANNELS so it can be unambiguously reshaped to (B, C, T, H, W). A non-divisible channel count means the tensor is not a SeedVR2 latent in that layout, and reshape would either fail or silently scramble frames.","triggerScenarios":"decode(z) with z.ndim == 4 and z.shape[1] % SEEDVR2_LATENT_CHANNELS != 0 — e.g. passing a 4-channel SD latent or a 3-channel RGB image tensor.","commonSituations":"Passing a latent from a different VAE (4/8/16 channels with a different channel count basis); passing raw images instead of latents; truncating or slicing the latent channel dim.","solutions":["Verify the tensor is a SeedVR2 latent in collapsed layout and that z.shape[1] is a multiple of SEEDVR2_LATENT_CHANNELS.","If you built the collapsed layout yourself, keep the full channel dim: torch.cat over time must produce C*T channels, not fewer.","Use the 5-D form when T is ambiguous."],"exampleFix":"# before\nout = vae.decode(rgb_image)  # (B,3,H,W): 3 % latent_channels != 0\n# after\nlatent = vae.encode(rgb_image)  # collapsed SeedVR2 latent\nout = vae.decode(latent)","handlingStrategy":"validation","validationCode":"if z.ndim == 4 and z.shape[1] % SEEDVR2_LATENT_CHANNELS != 0:\n    raise ValueError(f\"collapsed channel dim {z.shape[1]} is not a multiple of {SEEDVR2_LATENT_CHANNELS}\")\nvae.decode(z)","typeGuard":"def is_valid_4d_seedvr_latent(z) -> bool:\n    return z.ndim == 4 and z.shape[1] % SEEDVR2_LATENT_CHANNELS == 0","tryCatchPattern":null,"preventionTips":["Never pass raw images or other-VAE latents to the SeedVR2 decoder.","Log latent shapes at pipeline boundaries to catch wrong sources early."],"tags":["seedvr","vae","decode","latent-shape"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}