{"record":{"id":"ed38e4ffd0d3d4af","repo":"invoke-ai/InvokeAI","slug":"wan-latents-to-video-requires-non-empty-temporal-a","errorCode":null,"errorMessage":"Wan latents-to-video requires non-empty temporal and spatial dimensions.","messagePattern":"Wan latents-to-video requires non-empty temporal and spatial dimensions\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_latents_to_video.py","lineNumber":103,"sourceCode":"        ge=1,\n        le=120,\n        description=\"Frames-per-second for the encoded MP4. Wan 2.2 was trained at 16 FPS.\",\n    )\n\n    @torch.no_grad()\n    def invoke(self, context: InvocationContext) -> VideoOutput:\n        latents = context.tensors.load(self.latents.latents_name)\n        _validate_video_latent_batch(latents)\n        if latents.ndim == 4:\n            # Promote 4D (single-frame) to 5D so this node can also serve as a\n            # one-frame \"video\" encode if someone wires it that way.\n            latents = latents.unsqueeze(2)\n        if latents.ndim != 5:\n            raise ValueError(\n                f\"Wan latents-to-video expects a 5D latent tensor [B, C, T, H, W]; got {tuple(latents.shape)}.\"\n            )\n        if any(size == 0 for size in latents.shape[2:]):\n            raise ValueError(\"Wan latents-to-video requires non-empty temporal and spatial dimensions.\")\n\n        vae_info = context.models.load(self.vae.vae)\n        if not isinstance(vae_info.model, AutoencoderKLWan):\n            raise TypeError(f\"Expected AutoencoderKLWan for Wan VAE, got {type(vae_info.model).__name__}.\")\n\n        if latents.shape[1] != vae_info.model.config.z_dim:\n            raise ValueError(\n                f\"Latent channel mismatch: these latents have {latents.shape[1]} channels but the \"\n                f\"selected VAE expects {vae_info.model.config.z_dim}. A14B models need the 16-channel Wan 2.1 VAE; \"\n                \"TI2V-5B needs the 48-channel Wan 2.2 VAE.\"\n            )\n\n        _, _, t_lat, h_lat, w_lat = latents.shape\n        spatial_scale = getattr(vae_info.model.config, \"scale_factor_spatial\", None) or 8\n        temporal_scale = getattr(vae_info.model.config, \"scale_factor_temporal\", None) or 4\n        t_pixel = (t_lat - 1) * temporal_scale + 1\n        h_pixel, w_pixel = h_lat * spatial_scale, w_lat * spatial_scale\n        optimize_memory = context.config.get().wan_memory_optimization","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_latents_to_video.py#L85-L121","documentation":"A 5D latent tensor whose temporal (T) or spatial (H/W) dimensions contain a zero cannot be decoded into a video, so invoke() rejects it early with this ValueError. This guards the VAE against empty video tensors that would produce zero or undefined frames.","triggerScenarios":"Passing latents where any of shape[2], shape[3], shape[4] is 0 — usually the result of an upstream slicing bug, an empty sequence after frame dropping, or an arithmetic error in latent size computation (e.g. (0 pixels) // downscale).","commonSituations":"Off-by-one slicing producing T=0; failed upstream resize leaving H or W at 0; conditional pipelines that emit placeholder empty tensors when a branch is skipped.","solutions":["Fix the upstream computation/slicing so T, H, W are all >= 1.","Validate latents.shape[2:] before invoking and abort the workflow branch early.","Check that source image/video dimensions are non-zero before latent generation."],"exampleFix":"// before\nlatents = denoise(prompt, num_frames=0)  # T == 0\nvideo = wan_latents_to_video(latents=latents)  # ValueError\n// after\nassert latents.shape[2] > 0 and latents.shape[3] > 0 and latents.shape[4] > 0\nvideo = wan_latents_to_video(latents=latents)","handlingStrategy":"validation","validationCode":"if latents.ndim == 5 and any(s == 0 for s in latents.shape[2:]):\n    raise ValueError(f\"Wan video latents have an empty T/H/W dim: {tuple(latents.shape)}\")","typeGuard":"def has_nonempty_video_dims(t) -> bool:\n    return t.ndim == 5 and all(s > 0 for s in t.shape[2:])","tryCatchPattern":"try:\n    video = node.invoke(context)\nexcept ValueError as e:\n    if \"non-empty temporal and spatial\" in str(e):\n        raise WorkflowSkip(\"video branch produced empty latents\")\n    raise","preventionTips":["Guard upstream slicing so frame/size computations never hit 0.","Check source media dimensions before latent generation.","Skip video branches early when inputs are placeholders.","Assert all latent dims > 0 before invoke."],"tags":["wan","empty-tensor","validation","video"],"backgroundTag":"empty-tensor-dimension","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}