{"record":{"id":"5edaacbd8e3e8ad9","repo":"invoke-ai/InvokeAI","slug":"streaming-wan-vae-decode-does-not-support-spatial","errorCode":null,"errorMessage":"Streaming Wan VAE decode does not support spatial tiling.","messagePattern":"Streaming Wan VAE decode does not support spatial tiling\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/wan/vae_decode.py","lineNumber":14,"sourceCode":"from collections.abc import Iterator\n\nimport torch\nfrom diffusers.models.autoencoders import AutoencoderKLWan\nfrom diffusers.models.autoencoders.autoencoder_kl_wan import unpatchify\n\n\ndef iter_wan_vae_decode_chunks(vae: AutoencoderKLWan, latents: torch.Tensor) -> Iterator[torch.Tensor]:\n    \"\"\"Decode one latent frame at a time while preserving Wan causal-convolution state.\"\"\"\n    _, _, num_frames, height, width = latents.shape\n    tile_latent_min_height = vae.tile_sample_min_height // vae.spatial_compression_ratio\n    tile_latent_min_width = vae.tile_sample_min_width // vae.spatial_compression_ratio\n    if vae.use_tiling and (width > tile_latent_min_width or height > tile_latent_min_height):\n        raise ValueError(\"Streaming Wan VAE decode does not support spatial tiling.\")\n\n    vae.clear_cache()\n    try:\n        hidden_states = vae.post_quant_conv(latents)\n        for frame_index in range(num_frames):\n            vae._conv_idx = [0]\n            decoded = vae.decoder(\n                hidden_states[:, :, frame_index : frame_index + 1],\n                feat_cache=vae._feat_map,\n                feat_idx=vae._conv_idx,\n                first_chunk=frame_index == 0,\n            )\n            if vae.config.patch_size is not None:\n                decoded = unpatchify(decoded, patch_size=vae.config.patch_size)\n            yield decoded.clamp(-1.0, 1.0)\n    finally:\n        vae.clear_cache()\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/wan/vae_decode.py#L1-L32","documentation":"`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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Disable VAE tiling (`vae.use_tiling = False`) if memory allows, or use the standard full/tiled `vae.decode` path for large latents","Reduce the video resolution so latent height/width stay within the tile thresholds","Decode spatially tiled output with the standard decoder and use the streaming path only for small-latent cases"],"exampleFix":"# before\nfor chunk in iter_wan_vae_decode_chunks(vae, latents):  # ValueError for big latents\n    ...\n# after\nif vae.use_tiling and (latents.shape[-1] > vae.tile_sample_min_width // vae.spatial_compression_ratio or\n                       latents.shape[-2] > vae.tile_sample_min_height // vae.spatial_compression_ratio):\n    video = vae.decode(latents).sample\nelse:\n    for chunk in iter_wan_vae_decode_chunks(vae, latents):\n        ...","handlingStrategy":"validation","validationCode":"def supports_streaming_wan_decode(vae, latents) -> bool:\n    _, _, _, h, w = latents.shape\n    if not vae.use_tiling:\n        return True\n    return (w <= vae.tile_sample_min_width // vae.spatial_compression_ratio\n            and h <= vae.tile_sample_min_height // vae.spatial_compression_ratio)\n\nif not supports_streaming_wan_decode(vae, latents):\n    video = vae.decode(latents).sample  # fall back to standard decode","typeGuard":null,"tryCatchPattern":"try:\n    frames = list(iter_wan_vae_decode_chunks(vae, latents))\nexcept ValueError as e:\n    if \"spatial tiling\" in str(e):\n        frames = [vae.decode(latents).sample]\n    else:\n        raise","preventionTips":["Check latent H/W against tile thresholds before choosing the streaming decoder","Disable vae.use_tiling when you intend to use the streaming path on small latents","Keep generation resolution within limits compatible with single-tile decode","Write a unit test that exercises the streaming decoder at your target resolution"],"tags":["value-error","vae","tiling","video-decode","unsupported-operation"],"backgroundTag":"feature-not-supported-for-config","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}