Comfy-Org/ComfyUI · error · ValueError

ar_video sampler requires 5-D video latents [B,C,T,H,W], got

Error message

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).

What it means

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.

Source

Thrown at comfy/k_diffusion/sampling.py:1862

@torch.no_grad()
def sample_ar_video(model, x, sigmas, extra_args=None, callback=None, disable=None,
                    num_frame_per_block=1):
    """
    Autoregressive video sampler: block-by-block denoising with KV cache
    and flow-match re-noising for Causal Forcing / Self-Forcing models.

    Requires a Causal-WAN compatible model (diffusion_model must expose
    init_kv_caches / init_crossattn_caches) and 5-D latents [B,C,T,H,W].

    All AR-loop parameters are passed via the SamplerARVideo node, not read
    from the checkpoint or transformer_options.
    """
    extra_args = {} if extra_args is None else extra_args
    model_options = extra_args.get("model_options", {})
    transformer_options = model_options.get("transformer_options", {})

    if x.ndim != 5:
        raise ValueError(
            f"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)."
        )

    inner_model = model.inner_model.inner_model
    causal_model = inner_model.diffusion_model

    if not (hasattr(causal_model, "init_kv_caches") and hasattr(causal_model, "init_crossattn_caches")):
        raise TypeError(
            "ar_video sampler requires a Causal-WAN compatible model whose diffusion_model "
            "exposes init_kv_caches() and init_crossattn_caches(). The loaded checkpoint "
            "does not support this interface — choose a different sampler."
        )

    seed = extra_args.get("seed", 0)

    bs, c, lat_t, lat_h, lat_w = x.shape
    frame_seq_len = -(-lat_h // 2) * -(-lat_w // 2) # ceiling division

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Use a Causal-WAN video VAE/model path so latents stay 5-D [B,C,T,H,W]
  2. If latents were reshaped, restore the time dimension before sampling (view/reshape back to 5-D with correct T)
  3. Choose a non-AR sampler (e.g. dpmpp_2m) for 4-D image latents

Example fix

# before
x = latents  # shape [B, C, H*W] or [B,C,H,W] image latents
out = sample_ar_video(model, x, ...)
# after
x = latents.reshape(B, C, T, H, W)  # restore 5-D causal video latents
out = sample_ar_video(model, x, ...)
Defensive patterns

Strategy: validation

Validate before calling

if x.ndim != 5:
    raise ValueError('ar_video needs 5-D latents [B,C,T,H,W]')
# or reshape beforehand:
# x = x.view(B, C, T, H, W)

Type guard

def is_video_latents(x: torch.Tensor) -> bool:
    return x.ndim == 5

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/37a81c38e7bb8f9a. Report an issue: GitHub.