{"record":{"id":"7a0fedc4c671427a","repo":"invoke-ai/InvokeAI","slug":"wan-latents-to-video-requires-batch-size-1-got-l","errorCode":null,"errorMessage":"Wan latents-to-video requires batch size 1; got {latents.shape[0]}.","messagePattern":"Wan latents-to-video requires batch size 1; got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_latents_to_video.py","lineNumber":48,"sourceCode":")\nfrom invokeai.app.invocations.model import VAEField\nfrom invokeai.app.invocations.primitives import VideoOutput\nfrom invokeai.app.services.session_processor.session_processor_common import CanceledException\nfrom invokeai.app.services.shared.invocation_context import InvocationContext\nfrom invokeai.app.util.video_encoding import make_mp4_writer\nfrom invokeai.backend.model_manager.load.model_cache.utils import get_effective_device\nfrom invokeai.backend.util.devices import TorchDevice\nfrom invokeai.backend.util.vae_working_memory import estimate_vae_working_memory_wan\nfrom invokeai.backend.wan.vae_decode import iter_wan_vae_decode_chunks\n\n\nclass _FrameWriter(Protocol):\n    def append_data(self, frame: np.ndarray) -> None: ...\n\n\ndef _validate_video_latent_batch(latents: torch.Tensor) -> None:\n    if latents.ndim in (4, 5) and latents.shape[0] != 1:\n        raise ValueError(f\"Wan latents-to-video requires batch size 1; got {latents.shape[0]}.\")\n\n\ndef _iter_decoded_frames(decoded: torch.Tensor) -> Iterator[np.ndarray]:\n    for index in range(decoded.shape[1]):\n        frame = decoded[:, index]\n        frame = frame.clamp(-1, 1).permute(1, 2, 0).cpu().float()\n        yield (127.5 * (frame + 1.0)).round().clamp(0, 255).byte().numpy()\n\n\ndef _write_video_frames(writer: _FrameWriter, frames: Iterable[np.ndarray], is_canceled: Callable[[], bool]) -> None:\n    frames_iter = iter(frames)\n    while True:\n        if is_canceled():\n            raise CanceledException\n        try:\n            frame = next(frames_iter)\n        except StopIteration:\n            return","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_latents_to_video.py#L30-L66","documentation":"_validate_video_latent_batch enforces batch size 1 because the Wan VAE decode and frame-writing path (_FrameWriter) handles exactly one video per invocation. Any latent tensor whose first dimension is not 1 raises this ValueError before any expensive model loading occurs.","triggerScenarios":"Passing a latent tensor with latents.shape[0] > 1 (4D or 5D) into wan_latents_to_video, either directly from a batched denoiser run or by wiring a batch>1 latents output into the node.","commonSituations":"Batch generation upstream (scheduler with num_samples>1) feeding the video node; users expecting per-sample video output; copied diffusion-image workflows where batch>1 is normal.","solutions":["Set the upstream generation batch size to 1 before producing latents.","If multiple samples are needed, split the latents and call the node once per sample (loop over latents[i:i+1]).","Keep the video pipeline single-sample; generate variation via seeds instead of batching."],"exampleFix":"// before\nvideo = wan_latents_to_video(latents=batched_latents)  # shape [4, C, T, H, W]\n// after\nfor i in range(batched_latents.shape[0]):\n    video = wan_latents_to_video(latents=batched_latents[i:i+1])","handlingStrategy":"validation","validationCode":"if latents.ndim in (4, 5) and latents.shape[0] != 1:\n    raise ValueError(f\"Wan video node needs batch size 1, got {latents.shape[0]}; loop over samples instead.\")","typeGuard":"def is_single_video_batch(latents) -> bool:\n    return latents.ndim in (4, 5) and latents.shape[0] == 1","tryCatchPattern":"try:\n    video = node.invoke(context)\nexcept ValueError as e:\n    if \"requires batch size 1\" in str(e):\n        for i in range(latents.shape[0]):\n            process_video(node, latents[i:i+1])\n    else:\n        raise","preventionTips":["Set upstream sampler batch/num_samples to 1 for video workflows.","Split batched latents before the video node.","Don't copy batch>1 assumptions from image workflows.","Add a batch-size assert at the workflow boundary."],"tags":["wan","batch-size","validation","video"],"backgroundTag":"batch-size-not-supported","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}