ComfyUI-WanVideoWrapper
ComfyUI-WanVideoWrapper copied to clipboard
reference_latent in WanVideo Context Options causes device mismatch error (CPU vs CUDA)
Description
When using reference_latent in WanVideoContextOptions, the sampler crashes with a device mismatch error during the torch.cat operation at line 1709 in nodes_sampler.py.
Error
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument tensors in method wrapper_CUDA_cat)
Traceback
File "...\nodes_sampler.py", line 1709, in process
partial_img_emb[:, 0] = torch.cat([image_cond[:4, 0], new_init_image], dim=0)
Cause
At line 1707-1709, new_init_image is moved to intermediate_device, but image_cond may be on a different device (e.g., cuda:0). This causes the torch.cat to fail.
Suggested Fix
Line 1709, change:
partial_img_emb[:, 0] = torch.cat([image_cond[:4, 0], new_init_image], dim=0)
To:
partial_img_emb[:, 0] = torch.cat([image_cond[:4, 0], new_init_image.to(image_cond.device)], dim=0)
This ensures new_init_image is always on the same device as image_cond.
Environment
- ComfyUI-WanVideoWrapper (latest)
- Windows 11
- Dual RTX GPUs
the same issue