{"record":{"id":"bdde9ea667ef78e4","repo":"Comfy-Org/ComfyUI","slug":"seedvr2-videoautoencoderklwrapper-decode-latent-i","errorCode":null,"errorMessage":"SeedVR2 VideoAutoencoderKLWrapper.decode: latent input must be 4-D collapsed (B, {SEEDVR2_LATENT_CHANNELS}*T, H, W) or 5-D (B, {SEEDVR2_LATENT_CHANNELS}, T, H, W); got shape {tuple(z.shape)}.","messagePattern":"SeedVR2 VideoAutoencoderKLWrapper\\.decode: latent input must be 4-D collapsed \\(B, (.+?)\\*T, H, W\\) or 5-D \\(B, (.+?), T, H, W\\); got shape (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/seedvr/vae.py","lineNumber":1496,"sourceCode":"        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)\n\n        if enable_tiling:\n            decode_seedvr2_args = dict(seedvr2_tiling)\n            decode_seedvr2_args.pop(\"enable_tiling\", None)\n            tile_h, tile_w = decode_seedvr2_args.get(\"tile_size\", (512, 512))\n            ov_h, ov_w = decode_seedvr2_args.get(\"tile_overlap\", (64, 64))\n            decode_seedvr2_args[\"tile_overlap\"] = (","sourceCodeStart":1478,"sourceCodeEnd":1514,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/seedvr/vae.py#L1478-L1514","documentation":"decode() only handles two latent rank layouts: 4-D collapsed (B, C*T, H, W) and 5-D (B, C, T, H, W). Any other rank (e.g. a 3-D or 6-D tensor) is rejected with the observed shape, since the decoder has no defined interpretation for it.","triggerScenarios":"decode(z) where z.ndim is not 4 or 5 — e.g. passing a flat batch of patch tokens (3-D), or an extra leading frame dim (6-D).","commonSituations":"Forgetting to batch a single sample; consuming transformer patch-token output directly instead of unpatchified latents; double-batching.","solutions":["Reshape the tensor to (B, C*T, H, W) or (B, C, T, H, W) before decoding.","If it came from a patchified transformer output, run the model's unpatchify step first.","Add z.ndim in (4, 5) as a pre-condition check in your pipeline."],"exampleFix":"# before\nout = vae.decode(patched_tokens)  # ndim == 3\n# after\nlatent = unpatchify(patched_tokens).reshape(b, c*t, h, w)\nout = vae.decode(latent)","handlingStrategy":"validation","validationCode":"if z.ndim not in (4, 5):\n    raise ValueError(f\"latent must be 4-D or 5-D, got {tuple(z.shape)}\")\nvae.decode(z)","typeGuard":"def is_seedvr_latent_rank(z) -> bool:\n    return z.ndim in (4, 5)","tryCatchPattern":null,"preventionTips":["Always carry a batch dimension.","Unpatchify transformer token outputs before decoding."],"tags":["seedvr","vae","decode","tensor-rank"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}