[Python] RuntimeError in torch.cat during VACE-Wan2.1 inference: mask and video tensor shape...

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using the Wan2.1-VACE video generation model, and during inference I encountered a RuntimeError related to mismatched tensor shapes in a torch.cat operation inside the vace_latent() function.

    From the debug output:

    src_video tensor size before generation: torch.Size([3, 1, 848, 464])
    src_mask tensor size before generation: torch.Size([1, 1, 848, 464])


    This causes the following error when the code tries to concatenate tensors from video and mask:

    RuntimeError: Sizes of tensors must match except in dimension 0. Expected size 3 but got size 2 for tensor number 1 in the list.


    The error comes from this part of the code:

    return [torch.cat([zz, mm], dim=0) for zz, mm in zip(z, m)]


    It seems that the batch/frame count along dim=0 doesn't match between video and mask, but I'm not sure how to fix this properly or what the expected input shape should be.

    To fix the shape mismatch, I tried manually expanding the mask tensor’s channel dimension to match the video input. Here’s what I did:

    if src_mask is not None and src_mask[0].shape[1] == 1:
    src_mask[0] = src_mask[0].expand(-1, 3, -1, -1)
    print(f"DEBUG: src_mask channel expanded to 3: {src_mask[0].shape}")


    I expected this would make the mask and video inputs have matching channel sizes (both with shape [3, 1, H, W]), so the model could concatenate them without error. However, I still got the same RuntimeError during torch.cat, complaining about size mismatch along dimension 0.

    This is how I’m running the inference:

    python vace/vace_wan_inference.py \
    --src_video assets/videos/src_video_rgb.mp4 \
    --src_mask assets/videos/src_mask_rgb.mp4 \
    --src_ref_images "assets/ref/hamer_61.png,assets/ref/pose_61.png" \
    --prompt "重建一隻符合骨架姿勢與結構的真實人手,寫實風格,聚焦手部細節"


    It seems like either the number of frames or some dimension is still misaligned, but I’m unsure whether I should be expanding on batch/frame dimension or just channel-wise. Any guidance is appreciated!

    Continue reading...

Compartilhe esta Página