{"record":{"id":"37a81c38e7bb8f9a","repo":"Comfy-Org/ComfyUI","slug":"ar-video-sampler-requires-5-d-video-latents-b-c-t","errorCode":null,"errorMessage":"ar_video sampler requires 5-D video latents [B,C,T,H,W], got {x.ndim}-D tensor with shape {x.shape}. This sampler is only compatible with autoregressive video models (e.g. Causal-WAN).","messagePattern":"ar_video sampler requires 5-D video latents \\[B,C,T,H,W\\], got (.+?)-D tensor with shape (.+?)\\. This sampler is only compatible with autoregressive video models \\(e\\.g\\. Causal-WAN\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/k_diffusion/sampling.py","lineNumber":1862,"sourceCode":"@torch.no_grad()\ndef sample_ar_video(model, x, sigmas, extra_args=None, callback=None, disable=None,\n                    num_frame_per_block=1):\n    \"\"\"\n    Autoregressive video sampler: block-by-block denoising with KV cache\n    and flow-match re-noising for Causal Forcing / Self-Forcing models.\n\n    Requires a Causal-WAN compatible model (diffusion_model must expose\n    init_kv_caches / init_crossattn_caches) and 5-D latents [B,C,T,H,W].\n\n    All AR-loop parameters are passed via the SamplerARVideo node, not read\n    from the checkpoint or transformer_options.\n    \"\"\"\n    extra_args = {} if extra_args is None else extra_args\n    model_options = extra_args.get(\"model_options\", {})\n    transformer_options = model_options.get(\"transformer_options\", {})\n\n    if x.ndim != 5:\n        raise ValueError(\n            f\"ar_video sampler requires 5-D video latents [B,C,T,H,W], got {x.ndim}-D tensor with shape {x.shape}. \"\n            \"This sampler is only compatible with autoregressive video models (e.g. Causal-WAN).\"\n        )\n\n    inner_model = model.inner_model.inner_model\n    causal_model = inner_model.diffusion_model\n\n    if not (hasattr(causal_model, \"init_kv_caches\") and hasattr(causal_model, \"init_crossattn_caches\")):\n        raise TypeError(\n            \"ar_video sampler requires a Causal-WAN compatible model whose diffusion_model \"\n            \"exposes init_kv_caches() and init_crossattn_caches(). The loaded checkpoint \"\n            \"does not support this interface — choose a different sampler.\"\n        )\n\n    seed = extra_args.get(\"seed\", 0)\n\n    bs, c, lat_t, lat_h, lat_w = x.shape\n    frame_seq_len = -(-lat_h // 2) * -(-lat_w // 2) # ceiling division","sourceCodeStart":1844,"sourceCodeEnd":1880,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/k_diffusion/sampling.py#L1844-L1880","documentation":"Raised by sample_ar_video: the autoregressive video sampler operates on chunked video latents and drives the Causal-WAN block loop, so it requires a 5-D tensor [B,C,T,H,W]. Standard image (4-D) or already-flattened latents (3-D) do not carry the temporal axis the AR loop iterates over, and the error fires before the model is touched.","triggerScenarios":"Connecting the ar_video sampler to an image model's 4-D image latents [B,C,H,W], or to a video model whose latents were reshaped/collapsed to 4-D by an intermediary node before KSampler.","commonSituations":"Reusing an image workflow and switching only the sampler name to ar_video; nodes that squeeze/reshape latents (e.g. LatentFromBatch-style reshapers) dropping the time dimension; feeding image2image latents into an AR video pipeline.","solutions":["Use a Causal-WAN video VAE/model path so latents stay 5-D [B,C,T,H,W]","If latents were reshaped, restore the time dimension before sampling (view/reshape back to 5-D with correct T)","Choose a non-AR sampler (e.g. dpmpp_2m) for 4-D image latents"],"exampleFix":"# before\nx = latents  # shape [B, C, H*W] or [B,C,H,W] image latents\nout = sample_ar_video(model, x, ...)\n# after\nx = latents.reshape(B, C, T, H, W)  # restore 5-D causal video latents\nout = sample_ar_video(model, x, ...)","handlingStrategy":"validation","validationCode":"if x.ndim != 5:\n    raise ValueError('ar_video needs 5-D latents [B,C,T,H,W]')\n# or reshape beforehand:\n# x = x.view(B, C, T, H, W)","typeGuard":"def is_video_latents(x: torch.Tensor) -> bool:\n    return x.ndim == 5","tryCatchPattern":null,"preventionTips":["Check x.ndim == 5 before selecting the ar_video sampler","Keep latents on the video VAE path; avoid nodes that collapse the time axis"],"tags":["sampling","ar-video","causal-wan","video","latent-shape","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}