Comfy-Org/ComfyUI · error · RuntimeError

SeedVR2 VideoAutoencoderKLWrapper.decode: latent input must

Error message

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)}.

What it means

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.

Source

Thrown at comfy/ldm/seedvr/vae.py:1496

        if z.ndim == 5:
            _, c, _, _, _ = z.shape
            if c != SEEDVR2_LATENT_CHANNELS:
                raise RuntimeError(
                    "SeedVR2 VideoAutoencoderKLWrapper.decode: 5-D latent input must "
                    f"have {SEEDVR2_LATENT_CHANNELS} channels; got shape {tuple(z.shape)}."
                )
            latent = z
        elif z.ndim == 4:
            b, tc, h, w = z.shape
            if tc % SEEDVR2_LATENT_CHANNELS != 0:
                raise RuntimeError(
                    "SeedVR2 VideoAutoencoderKLWrapper.decode: 4-D latent input must "
                    f"use collapsed channel layout (B, {SEEDVR2_LATENT_CHANNELS}*T, H, W); "
                    f"got shape {tuple(z.shape)}."
                )
            latent = z.reshape(b, SEEDVR2_LATENT_CHANNELS, -1, h, w)
        else:
            raise RuntimeError(
                "SeedVR2 VideoAutoencoderKLWrapper.decode: latent input must be "
                f"4-D collapsed (B, {SEEDVR2_LATENT_CHANNELS}*T, H, W) or "
                f"5-D (B, {SEEDVR2_LATENT_CHANNELS}, T, H, W); "
                f"got shape {tuple(z.shape)}."
            )
        scale = BYTEDANCE_VAE_SCALING_FACTOR
        shift = BYTEDANCE_VAE_SHIFTING_FACTOR
        latent = latent / scale + shift

        self.device = latent.device
        enable_tiling = seedvr2_tiling.get("enable_tiling", False)

        if enable_tiling:
            decode_seedvr2_args = dict(seedvr2_tiling)
            decode_seedvr2_args.pop("enable_tiling", None)
            tile_h, tile_w = decode_seedvr2_args.get("tile_size", (512, 512))
            ov_h, ov_w = decode_seedvr2_args.get("tile_overlap", (64, 64))
            decode_seedvr2_args["tile_overlap"] = (

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Reshape the tensor to (B, C*T, H, W) or (B, C, T, H, W) before decoding.
  2. If it came from a patchified transformer output, run the model's unpatchify step first.
  3. Add z.ndim in (4, 5) as a pre-condition check in your pipeline.

Example fix

# before
out = vae.decode(patched_tokens)  # ndim == 3
# after
latent = unpatchify(patched_tokens).reshape(b, c*t, h, w)
out = vae.decode(latent)
Defensive patterns

Strategy: validation

Validate before calling

if z.ndim not in (4, 5):
    raise ValueError(f"latent must be 4-D or 5-D, got {tuple(z.shape)}")
vae.decode(z)

Type guard

def is_seedvr_latent_rank(z) -> bool:
    return z.ndim in (4, 5)

Prevention

When it happens

Trigger: 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).

Common situations: Forgetting to batch a single sample; consuming transformer patch-token output directly instead of unpatchified latents; double-batching.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/bdde9ea667ef78e4. Report an issue: GitHub.