invoke-ai/InvokeAI · error · ValueError

Streaming Wan VAE decode does not support spatial tiling.

Error message

Streaming Wan VAE decode does not support spatial tiling.

What it means

`iter_wan_vae_decode_chunks` decodes one latent frame at a time using Wan VAE's causal-convolution cache, which only works when each frame fits in a single spatial tile. If the latents exceed the VAE's tile thresholds while tiling is enabled, the streaming path cannot reproduce a correct decode and raises instead of silently producing artifacts.

Source

Thrown at invokeai/backend/wan/vae_decode.py:14

from collections.abc import Iterator

import torch
from diffusers.models.autoencoders import AutoencoderKLWan
from diffusers.models.autoencoders.autoencoder_kl_wan import unpatchify


def iter_wan_vae_decode_chunks(vae: AutoencoderKLWan, latents: torch.Tensor) -> Iterator[torch.Tensor]:
    """Decode one latent frame at a time while preserving Wan causal-convolution state."""
    _, _, num_frames, height, width = latents.shape
    tile_latent_min_height = vae.tile_sample_min_height // vae.spatial_compression_ratio
    tile_latent_min_width = vae.tile_sample_min_width // vae.spatial_compression_ratio
    if vae.use_tiling and (width > tile_latent_min_width or height > tile_latent_min_height):
        raise ValueError("Streaming Wan VAE decode does not support spatial tiling.")

    vae.clear_cache()
    try:
        hidden_states = vae.post_quant_conv(latents)
        for frame_index in range(num_frames):
            vae._conv_idx = [0]
            decoded = vae.decoder(
                hidden_states[:, :, frame_index : frame_index + 1],
                feat_cache=vae._feat_map,
                feat_idx=vae._conv_idx,
                first_chunk=frame_index == 0,
            )
            if vae.config.patch_size is not None:
                decoded = unpatchify(decoded, patch_size=vae.config.patch_size)
            yield decoded.clamp(-1.0, 1.0)
    finally:
        vae.clear_cache()

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Disable VAE tiling (`vae.use_tiling = False`) if memory allows, or use the standard full/tiled `vae.decode` path for large latents
  2. Reduce the video resolution so latent height/width stay within the tile thresholds
  3. Decode spatially tiled output with the standard decoder and use the streaming path only for small-latent cases

Example fix

# before
for chunk in iter_wan_vae_decode_chunks(vae, latents):  # ValueError for big latents
    ...
# after
if vae.use_tiling and (latents.shape[-1] > vae.tile_sample_min_width // vae.spatial_compression_ratio or
                       latents.shape[-2] > vae.tile_sample_min_height // vae.spatial_compression_ratio):
    video = vae.decode(latents).sample
else:
    for chunk in iter_wan_vae_decode_chunks(vae, latents):
        ...
Defensive patterns

Strategy: validation

Validate before calling

def supports_streaming_wan_decode(vae, latents) -> bool:
    _, _, _, h, w = latents.shape
    if not vae.use_tiling:
        return True
    return (w <= vae.tile_sample_min_width // vae.spatial_compression_ratio
            and h <= vae.tile_sample_min_height // vae.spatial_compression_ratio)

if not supports_streaming_wan_decode(vae, latents):
    video = vae.decode(latents).sample  # fall back to standard decode

Try / catch

try:
    frames = list(iter_wan_vae_decode_chunks(vae, latents))
except ValueError as e:
    if "spatial tiling" in str(e):
        frames = [vae.decode(latents).sample]
    else:
        raise

Prevention

When it happens

Trigger: Calling `iter_wan_vae_decode_chunks(vae, latents)` with `vae.use_tiling == True` and latent height/width exceeding `tile_sample_min_height/spatial_compression_ratio` or `tile_sample_min_width/spatial_compression_ratio` (i.e. a full decode would have used spatial tiling).

Common situations: Generating high-resolution Wan video (large height/width) while the pipeline has VAE tiling enabled; switching from the standard tiled `vae.decode` path to the streaming chunked decoder without reducing resolution; changing `spatial_compression_ratio`/tile settings so previously fine latents now exceed the threshold.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/5edaacbd8e3e8ad9. Report an issue: GitHub.