[PERF] Ascend NPU: MindIE-SD attention backend and VAE-parallel enablement - #43
Draft
yx0716 wants to merge 3 commits into
Draft
[PERF] Ascend NPU: MindIE-SD attention backend and VAE-parallel enablement#43yx0716 wants to merge 3 commits into
yx0716 wants to merge 3 commits into
Conversation
Wan22VideoVAE.decode's parallel branch called torch.stack on its input, assuming a list of per-video tensors, but VAEStage.decode_video passes a batched [B, C, T, H, W] tensor; the serial branch only worked because iterating a tensor yields its batch slices. Any enable_vae_parallel run of the Wan2.2 48-channel VAE therefore failed with TypeError regardless of platform. Normalize tensor inputs before stacking. Found while enabling spatially parallel VAE decode on Ascend 910B2; the parallel path now proceeds to communicator setup (further multi-communicator progress on that host is limited by its CANN driver, see branch notes).
Concurrent worker groups sharing the same NPU devices (e.g. denoising plus VAE workers) collide on HCCL's default data-plane socket range and fail comm init with EJ0003 ("IP address and port have been bound already"). Allocate a distinct HCCL_IF_BASE_PORT per spawned group on NPU platforms, mirroring the existing per-group MASTER_PORT allocation; other platforms are untouched.
Verified: single-group 4-card Wan2.2-TI2V-5B regression on Ascend 910B2 passes with the env applied (33.4s generate, parity with baseline).
yx0716
marked this pull request as draft
September 1, 2026 06:01
Add AttnImplType.MINDIE_ATTN, routed through mindiesd.attention_forward (auto-tuned Ascend kernels including LaserAttention) for dense BNSD attention. Availability is probed like the sageattention backend (optional import, NPU platform only), so default behavior is unchanged on every platform and the enum is strictly opt-in. Verified on Atlas 910B (CANN 8.2): kernel microbench 1.29-1.53x over SDPA across wan shapes (holds at ulysses head-sharded 12-head shapes); unmodified wan22_t2v_5b example end to end: 720p 121f 477.8->405.0s (1.18x) on 1 card and 173.9->157.6s (1.10x) on 4 cards, 480p 121f 180.9->162.6s on 1 card; a 480p 4-card regression (87.0->103.0s) is documented in the PR - the backend is recommended for compute-dominated configurations. Output is bit-identical to SDPA at probed shapes; dispatch covered by a mock unit test; ruff clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Ascend NPU acceleration on top of #42, in two parts:
AttnImplType.MINDIE_ATTN) that routes dense attention throughmindiesd.attention_forward(auto-tuned Ascend kernels including LaserAttention), with measured end-to-end gains of 1.10–1.18× over the [FEATURE] Run Wan2.2 pipelines on Ascend NPU #42 baseline on compute-dominated configurations.enable_vae_parallelinput contract for the Wan2.2 48-channel VAE (currently broken on every platform), and isolate HCCL socket ranges per worker group so concurrent groups can coexist on NPU hosts.Default behavior is unchanged on every platform: the backend is strictly opt-in, and the VAE/HCCL fixes are inert outside
enable_vae_parallel/ multi-group NPU runs.Motivation
mindiesd(open-sourced MindIE-SD) provides faster Ascend attention kernels behind a stable API — measured 1.29–1.53× over SDPA at wan-typical shapes.Wan22VideoVAE.decode's parallel branch callstorch.stackon its input, assuming a list, butVAEStage.decode_videopasses a batched tensor; anyenable_vae_parallelrun of a Wan2.2-VAE pipeline fails withTypeErrortoday, on CUDA as well as NPU.EJ0003); a distinct per-groupHCCL_IF_BASE_PORT(mirroring the existing per-groupMASTER_PORT) removes the collision.Type of Change
Changes Made
telefuser/core/config.py,telefuser/ops/attention/backends.py,telefuser/ops/attention/attention_impl.py,docs/en/attention.md: addAttnImplType.MINDIE_ATTNwith a sageattention-style availability probe (optionalmindiesdimport, NPU platform only), a BNSD dispatch branch, and documentation. This intentionally adds one public enum value; no dependency is added topyproject.toml(optional import, like sageattention).tests/unit/ops/test_attention_backends.py: mock-based dispatch unit test for the new backend (runs on CPU CI).telefuser/models/wan22_video_vae.py: normalizedecode's input before the parallel-branchtorch.stack— batched tensors pass through, lists are stacked as before.telefuser/worker/parallel_worker.py: allocate a distinctHCCL_IF_BASE_PORTper spawned worker group on NPU platforms; other platforms untouched.Testing
pytest tests/)Test commands:
tests/unit/ops/test_attention_backends.py11 passed (includes the new dispatch test; mock-based, platform-independent); fulltests/unitgreen.MINDIE_ATTNoutput is bit-identical toTORCH_SDPAat probed BNSD bf16 shapes on Atlas 910B.Performance Impact
Measured against the #42 baseline (same host, same unmodified example, same commands; Atlas 910B 8× 910B2, CANN 8.2, torch 2.9.0 + torch_npu 2.9.0.post1, 50 denoising steps,
MODEL_CPU_OFFLOAD):TORCH_SDPA)MINDIE_ATTN)Kernel microbench (BNSD bf16, head_dim 128):
mindiesdattention is 1.29–1.53× faster than torch_npu SDPA across S = 12.5k–45.8k, at both 24 and 12 heads (the ulysses head-sharded shape).Lossless stack (same task, same quality; configuration only):
MINDIE_ATTNplus resident weights (NO_CPU_OFFLOADinstead of the example'sMODEL_CPU_OFFLOAD) measures 407.6 s on 1 card (1.17×) and 151.9 s on 4 cards (1.14×) at 720p/121 frames. The weight-residency gain is visible at 4 cards (−5.7 s) and within run noise at 1 card.For reference only (not part of this PR's performance claims): combining the above with the existing in-tree RIFE VFI stage (generate 61 frames, interpolate to 121) measures 193.1 s / 94.4 s — but that changes the generation itself (the model's temporal prior operates at half the frame rate and interpolation reconstructs the rest), so it is a quality trade-off that needs content-level motion validation rather than a lossless optimization.
Guidance: the backend is opt-in and recommended for compute-dominated configurations (single-card, and multi-card at high resolution / long schedules). The 480p 4-card regression persists even though the kernel itself is faster at exactly those shapes, which points at an interaction with the ulysses async-communication overlap when per-step compute is small;
TASK_QUEUE_ENABLE=2does not recover it. DefaultTORCH_SDPAbehavior is unchanged, and the VAE/HCCL fixes have no effect on standard single-group runs (verified at parity).Related Issues
Complements #42 (Ascend NPU enablement); all baseline numbers above are from #42's Performance Impact section. Independently mergeable.
Additional Notes
Wan22VideoVAErequires full model weights and the parallel branch needs an initialized process group; the normalization is a two-line input guard exercised by the example path.mindiesdis available from PyPI (pip install mindiesd); when absent or off-NPU, the probe leaves the backend unavailable and nothing changes.GPU Architecture Support
No CUDA kernels are added or modified. The new backend calls prebuilt
mindiesdkernels on Ascend NPU only; CUDA behavior is unchanged.Checklist
ruff)pre-commit run --all-files— ruff + ruff-format; also covered by the lint CI job)pytest tests/)test_attention_backends.pydispatch test)docs/en/attention.md, docstrings)[TYPE] Brief description