{"record":{"id":"50bc1ec354e5ce26","repo":"Comfy-Org/ComfyUI","slug":"seedvr2-videoautoencoderklwrapper-decode-5-d-late","errorCode":null,"errorMessage":"SeedVR2 VideoAutoencoderKLWrapper.decode: 5-D latent input must have {SEEDVR2_LATENT_CHANNELS} channels; got shape {tuple(z.shape)}.","messagePattern":"SeedVR2 VideoAutoencoderKLWrapper\\.decode: 5-D latent input must have (.+?) channels; got shape (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/seedvr/vae.py","lineNumber":1481,"sourceCode":"        z = p.squeeze(2)\n        return z, p\n\n    def encode(self, x):\n        z, _ = self._encode_with_raw_latent(x)\n        return z\n\n    def decode(self, z, seedvr2_tiling=None):\n        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); \"","sourceCodeStart":1463,"sourceCodeEnd":1499,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/seedvr/vae.py#L1463-L1499","documentation":"decode() accepts a 5-D latent of shape (B, C, T, H, W) but requires C to equal SEEDVR2_LATENT_CHANNELS, because the decoder's conv stack is hard-wired to that channel count. A 5-D tensor with any other channel count means the latent came from a different VAE or was reshaped incorrectly, and downstream convs would fail opaquely, so it fails fast with the actual shape in the message.","triggerScenarios":"decode(z) with z.ndim == 5 and z.shape[1] != SEEDVR2_LATENT_CHANNELS — e.g. feeding a 16-channel SD/Wan latent to the SeedVR2 decoder, or collapsing time into the channel dim of a 5-D view incorrectly.","commonSituations":"Mixing latents across model families in one workflow; sampling from a DiT whose latent channels don't match the SeedVR2 VAE; manually re-expanding a 4-D latent with the wrong reshape order.","solutions":["Feed a latent produced by the matching SeedVR2 encoder/autoencoder, not another VAE.","If starting from the 4-D collapsed form (B, C*T, H, W), reshape as z.reshape(b, -1, T, h, w) so channels land in dim 1, or just pass the 4-D tensor and let decode reshape it.","Check z.shape[1] == SEEDVR2_LATENT_CHANNELS before calling decode."],"exampleFix":"# before\nlatent_5d = z.reshape(b, t, SEEDVR2_LATENT_CHANNELS, h, w)  # wrong dim order\nout = vae.decode(latent_5d)\n# after\nlatent_5d = z.reshape(b, SEEDVR2_LATENT_CHANNELS, t, h, w)\nout = vae.decode(latent_5d)","handlingStrategy":"validation","validationCode":"C = z.shape[1]\nif z.ndim == 5 and C != SEEDVR2_LATENT_CHANNELS:\n    raise ValueError(f\"latent has {C} channels, expected {SEEDVR2_LATENT_CHANNELS}; wrong VAE?\")\nvae.decode(z)","typeGuard":"def is_valid_5d_seedvr_latent(z) -> bool:\n    return z.ndim == 5 and z.shape[1] == SEEDVR2_LATENT_CHANNELS","tryCatchPattern":null,"preventionTips":["Only feed latents produced by the matching SeedVR2 encoder.","When reshaping 4-D to 5-D, put channels in dim 1: reshape(b, C, t, h, w)."],"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"}