{"record":{"id":"4eecd02dfa75f0b2","repo":"invoke-ai/InvokeAI","slug":"wan-latents-to-image-requires-batch-size-1-got-l","errorCode":null,"errorMessage":"Wan latents-to-image requires batch size 1; got {latents.shape[0]}.","messagePattern":"Wan latents-to-image requires batch size 1; got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_latents_to_image.py","lineNumber":58,"sourceCode":"    version=\"1.0.0\",\n    classification=Classification.Prototype,\n)\nclass WanLatentsToImageInvocation(BaseInvocation, WithMetadata, WithBoard):\n    \"\"\"Decodes Wan latents back to RGB.\"\"\"\n\n    latents: LatentsField = InputField(description=FieldDescriptions.latents, input=Input.Connection)\n    vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)\n\n    @torch.no_grad()\n    def invoke(self, context: InvocationContext) -> ImageOutput:\n        latents = context.tensors.load(self.latents.latents_name)\n\n        if latents.ndim not in (4, 5):\n            raise ValueError(\n                f\"Wan latents-to-image expects a 4D or 5D latent tensor [B, C, (T), H, W]; got {tuple(latents.shape)}.\"\n            )\n        if latents.shape[0] != 1:\n            raise ValueError(f\"Wan latents-to-image requires batch size 1; got {latents.shape[0]}.\")\n\n        # This node decodes exactly one image. Multi-frame video latents would otherwise\n        # run the full (expensive) multi-frame VAE decode — under a working-memory\n        # estimate that assumed one frame — and then die in an opaque einops rank error\n        # at the final rearrange. Checked before the VAE is even loaded.\n        if latents.ndim == 5 and latents.shape[2] != 1:\n            raise ValueError(\n                f\"These latents hold {latents.shape[2]} frames of video; this node decodes a single \"\n                \"image. Use 'Latents to Video - Wan 2.2' (wan_l2v) for video latents.\"\n            )\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        spatial_scale = getattr(vae_info.model.config, \"scale_factor_spatial\", None) or 8\n        estimated_working_memory = estimate_vae_working_memory_wan(\n            operation=\"decode\",","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_latents_to_image.py#L40-L76","documentation":"The node decodes exactly one image, so the latents batch dimension must be 1. Batched latents (>1) are rejected explicitly rather than decoding only the first frame silently, which would hide data loss.","triggerScenarios":"Feeding latents with shape[0] > 1 (e.g., from a batched generation or a manual torch.stack of multiple latent tensors) into Wan Latents to Image.","commonSituations":"Batch workflows built for txt2img SD pipelines reused for Wan; users stacking multiple encoded images into one tensor.","solutions":["Slice off a single batch item: latents[0:1] before decoding","Run the node once per batch element instead of batching","If downstream expects images, add a per-item loop or use a batch-capable node"],"exampleFix":"// before\nlatents.shape == (4, C, H, W) -> error\n// after\nlatents = latents[:1]  # or latents[i:i+1] per item","handlingStrategy":"validation","validationCode":"if latents.shape[0] != 1:\n    latents = latents[:1]  # or loop over batch items","typeGuard":"def is_single_batch(t: torch.Tensor) -> bool:\n    return t.shape[0] == 1","tryCatchPattern":"try:\n    out = wan_latents_to_image.invoke(context)\nexcept ValueError as e:\n    if 'batch size 1' in str(e):\n        out = [decode_one(latents[i:i+1]) for i in range(latents.shape[0])]\n    else:\n        raise","preventionTips":["Avoid batching with Wan image decode; iterate instead","Slice latents[:1] when only one output is needed","Keep per-item processing loops for batch workflows"],"tags":["invokeai","wan","batch-size","validation"],"backgroundTag":"unsupported-batch-size","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}