{"record":{"id":"ba4b3c4971247273","repo":"invoke-ai/InvokeAI","slug":"wan-reference-condition-requires-batch-size-1-got","errorCode":null,"errorMessage":"Wan reference condition requires batch size 1; got {condition.shape[0]}.","messagePattern":"Wan reference condition requires batch size 1; got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/wan_denoise.py","lineNumber":106,"sourceCode":"    if variant == WanVariantType.TI2V_5B and (width % 32 or height % 32):\n        raise ValueError(\n            f\"TI2V-5B requires width and height to be multiples of 32 (got {width}x{height}). \"\n            \"Wan 2.2-VAE 16x spatial * transformer patch_size 2 = pixel dims must divide by 32.\"\n        )\n\n\ndef _validate_ref_condition_shape(\n    condition: torch.Tensor,\n    *,\n    channels: int,\n    frames: int,\n    height: int,\n    width: int,\n) -> None:\n    if condition.ndim != 5:\n        raise ValueError(f\"Wan reference condition must be a 5D tensor; got shape {tuple(condition.shape)}.\")\n    if condition.shape[0] != 1:\n        raise ValueError(f\"Wan reference condition requires batch size 1; got {condition.shape[0]}.\")\n    if condition.shape[1] != channels:\n        raise ValueError(f\"Wan reference condition requires {channels} channels; got {condition.shape[1]}.\")\n    if condition.shape[2] != frames:\n        expected = \"a single latent frame\" if frames == 1 else f\"{frames} latent frames\"\n        raise ValueError(f\"Wan reference condition requires {expected}; got {condition.shape[2]}.\")\n    if condition.shape[3:] != (height, width):\n        raise ValueError(\n            f\"Wan reference condition requires {width}x{height} latent spatial dimensions; \"\n            f\"got {condition.shape[4]}x{condition.shape[3]}.\"\n        )\n\n\ndef _scheduler_path_for_transformer(context: InvocationContext, transformer_field: WanTransformerField) -> Path | None:\n    \"\"\"Return the on-disk ``scheduler/`` directory for the main model, or None.\"\"\"\n    config = context.models.get_config(transformer_field.transformer)\n    model_root = context.models.get_absolute_path(config)\n    if model_root.is_file():\n        return None","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/wan_denoise.py#L88-L124","documentation":"The reference condition must have batch size exactly 1 (shape[0] == 1). Batched conditioning is not supported by this Wan path, so _validate_ref_condition_shape rejects any tensor whose first dimension is greater than 1.","triggerScenarios":"Passing a condition tensor produced with batch size 2+ (e.g. batch-generating latents, duplicating the image latent along dim 0, or a upstream node configured with batch_size > 1) into the Wan ref-condition input.","commonSituations":"Users setting a global batch size > 1 for speed and expecting ref conditioning to follow, batched img2img pipelines feeding a single-video ref input, scripting that stacks multiple reference images along the batch axis.","solutions":["Set batch size to 1 for the conditioning path (condition = condition[:1] or don't batch it)","Generate each batch item in a separate invocation instead of batching the ref condition","If multiple reference images are needed, stack along the frames dimension only if the model supports it, otherwise use one ref per run","Check the upstream latents/condition node's batch setting"],"exampleFix":"// before\ncondition = torch.cat([ref1, ref2], dim=0)  # batch 2\n// after\ncondition = ref1.unsqueeze(0)  # batch 1; run a second invocation for ref2","handlingStrategy":"validation","validationCode":"if condition.shape[0] != 1:\n    condition = condition[:1]  # keep only the first batch item before invoking","typeGuard":"def is_batch_1(t) -> bool:\n    import torch\n    return isinstance(t, torch.Tensor) and t.ndim == 5 and t.shape[0] == 1","tryCatchPattern":"try:\n    result = denoise.invoke(context)\nexcept ValueError as e:\n    if \"requires batch size 1\" in str(e):\n        denoise.ref_condition = denoise.ref_condition[:1]\n        result = denoise.invoke(context)\n    else:\n        raise","preventionTips":["Keep global batch size at 1 when using reference conditioning","Generate batch items via separate invocations, not batched conditions","Never stack multiple reference images along dim 0","Assert condition.shape[0] == 1 in custom scripts before invoking"],"tags":["wan","tensor-shape","batch-size"],"backgroundTag":"tensor-rank-mismatch","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}