Skip to content

fix(wan): use device-agnostic default for get_i2v_mask - #14883

Open
li-lizhe wants to merge 2 commits into
huggingface:mainfrom
li-lizhe:fix/wan-animate-device-default-v2
Open

li-lizhe wants to merge 2 commits into
huggingface:mainfrom
li-lizhe:fix/wan-animate-device-default-v2

Conversation

@li-lizhe

@li-lizhe li-lizhe commented Sep 27, 2026 •

Copy link
Copy Markdown

Fixes #14881

Description: Fix the get_i2v_mask method's device="cuda" default parameter which causes a crash on non-CUDA accelerators (Ascend NPU, Intel XPU, Apple MPS, etc.) when called without an explicit device argument.

Change:

  • Default device from "cuda" to None
  • Add device = device or self._execution_device at the function top
  • Follows the established pattern used in prepare_reference_image_latents, encode_image, and other pipeline methods

Verification on Ascend 910B (torch 2.15.0.dev20260917+cpu + torch_npu 2.15.0.dev20260917+gitec69335, CANN 9.2.0-beta.2):

  • Old code: torch.zeros(1, device="cuda") crashes with AssertionError: Torch not compiled with CUDA enabled
  • Fix: device = device or self._execution_device resolves to npu:0, tensor created successfully on NPU

Second occurrence (included in this PR): the module-level helper get_i2v_mask at
src/diffusers/modular_pipelines/wan_animate_2/encoders.py:84 carried the same device="cuda" default. It is a
plain function (no self._execution_device to fall back to), so its default is now None and it raises a
clear ValueError when device is omitted instead of silently allocating on CUDA. Both in-tree call sites
already pass device= explicitly (wan_animate_2/denoise.py:128 and :220), so existing callers are
unaffected.

Scope note (see #14881): all in-tree call sites in both files already pass device explicitly, so this is a
latent default / API-hygiene fix rather than a fix for a currently-failing in-tree path.

(Replaces #14765, which the issue-link auto-close bot closed on 2026-09-25 and which GitHub refused to reopen - same commit, unchanged content.)

The `get_i2v_mask` method had a hardcoded `device="cuda"` default,
which crashes on non-CUDA accelerators (Ascend NPU, etc.) with
"Torch not compiled with CUDA enabled" when called without an
explicit device argument.

Change the default to None and resolve via `self._execution_device`,
matching the pattern used across other pipeline methods.

Verified on Ascend 910B NPU: torch.zeros(device="cuda") crashes,
fix with device-agnostic resolution creates tensors on the correct
device.
…v_mask`

`get_i2v_mask` in `modular_pipelines/wan_animate_2/encoders.py` defaulted its `device` argument to
`"cuda"`, so any call that omitted it allocated the mask on CUDA and failed on non-CUDA accelerators
(NPU/XPU/MPS/CPU) with `AssertionError: Torch not compiled with CUDA enabled`. The default is now
`None` and raises a clear `ValueError` instead of silently allocating on CUDA.

All in-tree call sites already pass `device=` explicitly (`wan_animate_2/denoise.py` lines 128 and 220),
so behaviour for existing callers is unchanged.

Same fix as the one applied to `WanAnimatePipeline.get_i2v_mask` in this PR.
@li-lizhe

Copy link
Copy Markdown
Author

Note: like #14785/#14786, this PR's CI runs will sit in action_required until a maintainer approves them once for this contributor (fork PR workflow approval).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WanAnimatePipeline.get_i2v_mask() defaults device to "cuda", which raises on non-CUDA accelerators (NPU/XPU/MPS)

1 participant