Comfy-Org/ComfyUI · error · RuntimeError

SeedVR2 VideoAutoencoderKLWrapper.decode: 5-D latent input m

Error message

SeedVR2 VideoAutoencoderKLWrapper.decode: 5-D latent input must have {SEEDVR2_LATENT_CHANNELS} channels; got shape {tuple(z.shape)}.

What it means

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.

Source

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

        z = p.squeeze(2)
        return z, p

    def encode(self, x):
        z, _ = self._encode_with_raw_latent(x)
        return z

    def decode(self, z, seedvr2_tiling=None):
        seedvr2_tiling = {} if seedvr2_tiling is None else seedvr2_tiling
        if not isinstance(seedvr2_tiling, dict):
            raise RuntimeError(
                "SeedVR2 VideoAutoencoderKLWrapper.decode: `seedvr2_tiling` must be a dict; "
                f"got {type(seedvr2_tiling).__name__} with value {seedvr2_tiling!r}."
            )

        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); "

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Feed a latent produced by the matching SeedVR2 encoder/autoencoder, not another VAE.
  2. 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.
  3. Check z.shape[1] == SEEDVR2_LATENT_CHANNELS before calling decode.

Example fix

# before
latent_5d = z.reshape(b, t, SEEDVR2_LATENT_CHANNELS, h, w)  # wrong dim order
out = vae.decode(latent_5d)
# after
latent_5d = z.reshape(b, SEEDVR2_LATENT_CHANNELS, t, h, w)
out = vae.decode(latent_5d)
Defensive patterns

Strategy: validation

Validate before calling

C = z.shape[1]
if z.ndim == 5 and C != SEEDVR2_LATENT_CHANNELS:
    raise ValueError(f"latent has {C} channels, expected {SEEDVR2_LATENT_CHANNELS}; wrong VAE?")
vae.decode(z)

Type guard

def is_valid_5d_seedvr_latent(z) -> bool:
    return z.ndim == 5 and z.shape[1] == SEEDVR2_LATENT_CHANNELS

Prevention

When it happens

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

Common situations: 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.

Related errors


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