Repository navigation
[PERF] Ascend NPU: Optimize Wan2.2 inference to surpass vLLM-Omni on 910B2 - #58
Merged
Merged
Conversation
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.
Eliminate major Ascend 910B2 bottlenecks under strict BF16 eager + SDPA +
model-level CPU offload parity (Wan2.2-TI2V-5B 864x480 121f 50-step UniPC):
- Keep scalar-timestep t_mod at seq_len=1 ([B, 1, 6, dim]) for broadcasting
instead of expanding and materializing [B, seq_len, 6, dim] per block
- Add RMSNorm.forward_npu via torch_npu.npu_rms_norm
- Add apply_rotary_emb NPU path via torch_npu.npu_rotary_mul(interleave)
and cache device RoPE cos/sin frequencies on WanModel
- Avoid redundant pure-BF16 torch.autocast('npu') upcasts in TI2V denoising
and VAE decode stages, and avoid float64 NPU fallbacks in sinusoidal
embeddings and UniPC linalg.solve
- Replace redundant einops.rearrange/double-reshapes with unflatten/flatten,
use torch.addcmul in GateModule and in-place modulation on NPU
- Add persistent pinned CPU parameter mirror and NPU non_blocking transfers
in BaseModel offload, plus device-side uint8 conversion before D2H in
tensor2video
Measured on Atlas 910B2 64GB (matched vllm-ascend v0.23.0.post1 / CANN 9.1.0,
4 runs: 1 cold + 3 warm):
- TeleFuser baseline (PR Tele-AI#42): 147.06s warm median (0.82 fps, ~132s denoise)
- vLLM-Omni 0.23.0rc1: 106.95s warm median (1.13 fps, ~96s denoise)
- TeleFuser optimized: 98.90s warm median (1.22 fps, ~90s denoise)
(1.49x faster than baseline; 8.05s / 7.5% faster than vLLM-Omni;
middle-frame PSNR 31.39 dB / Pearson r 0.9939 vs baseline)
This was referenced Nov 26, 2026
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.
Summary
Ascend 910B2 inference optimizations built on top of #42 (
main) and the MindIE-SD attention backend from #43. Under strict apples-to-apples parity (Wan2.2-TI2V-5B, 864×480, 121 frames, 50-step UniPC, CFG=5, BF16 eager +TORCH_SDPA+ model-level CPU offload, no feature caching or quantization), end-to-end warm latency on a single Atlas 910B2 64 GB drops from 147.06 s → 98.90 s (1.49× speedup), surpassing vLLM-Omni 0.23.0rc1 (106.95 s) by 8.05 s (-7.5%).Key Changes
telefuser/ops/rotary.py,telefuser/models/wan_video_dit.py)_apply_rotary_emb_npubacked bytorch_npu.npu_rotary_mul(..., rotary_mode="interleave").(freqs_cos, freqs_sin)per(f, h, w, freq_start_idx, freq_interval, device, dtype)onWanModel(cleared onoffload_device), eliminating per-forward CPUcomplex128concatenation, H2D transfers, andfloat64 → float32casts (~22.6 s saved across 50 CFG steps).[B, seq_len, 6, dim]modulation materialization (telefuser/models/wan_video_dit.py)t_modat[B, 1, 6, dim]for broadcasting in T2V mode while preserving per-token[B, seq_len, 6, dim]sharding for I2V and USP, avoiding 3,000 × 462.8 MB allocations and ~2.78 TB of redundant HBM traffic (~11–12 s saved).RMSNorm(telefuser/ops/normalization.py)RMSNorm.forward_npuviatorch_npu.npu_rms_norm(~8.5 s saved).autocast("npu")upcasts &float64fallbacks (ti2v_denoising.py,vae.py,wan_video_dit.py,unipc.py)torch.autocast("npu")when model parameters and inputs already match target BF16 without quantization (~5.3 s saved in DiT, ~1.5 s in VAE).float32on NPU insinusoidal_embedding_1dand run tiny2×2linalg.solveon CPU inFlowUniPCMultistepSchedulerto avoidaten::_linalg_solve_exNPU fallback syncs.telefuser/models/wan_video_dit.py)einops.rearrange/ double-reshapes aroundrope_applywithunflatten/flatten, usetorch.addcmulinGateModuleon NPU, and apply modulation in-place on freshly normalized activations (~2.0 s saved).uint8frame conversion (base_model.py,base_pipeline.py,wan22_video_vae.py,wan22_ti2v.py)non_blocking=TrueH2D transfers withcurrent_platform.synchronizeon NPU and retain a pinned CPU parameter mirror during inference sooffload_deviceavoids repeated D2H copies,pin_memory()host allocations, andgc.collect()stalls.uint8on device before D2H in single-processWan22TI2VPipeline(tensor2video: 1.70 s → 0.14 s; total non-denoising overhead reduced by ~6.0 s).AttnImplType.MINDIE_ATTN, from [PERF] Ascend NPU: MindIE-SD attention backend and VAE-parallel enablement #43)mindiesd.attention_forwarddispatch for environments with MindIE-SD installed.Benchmark & Quality Verification
Measured sequentially on the same isolated Atlas 910B2 64 GB card inside
quay.nju.edu.cn/ascend/vllm-ascend:v0.23.0.post1(CANN 9.1.0, Python 3.12.13, PyTorch2.10.0+cpu,torch_npu 2.10.0.post4, Diffusers 0.38.0), 4 serial runs per engine (1 cold + 3 warm):main/ #42)0.23.0rc1sha256: 17961dba...). Compared against the [FEATURE] Support Ascend 910B NPU runtime and Wan2.2 T2V with public vllm-omni image #42 baseline output on the same seed/prompt, middle-frameMAE = 3.01 / 255,PSNR = 31.39 dB,Pearson r = 0.9939, with visually identical scene structure and no NaN/Inf.tests/unit/ops/test_npu_optimizations.pycovering NPURMSNorm, NPURoPEhalf/full-dim dispatch, broadcastt_modequivalence, and RoPE cache lifecycle.ruff check,ruff format --check,ruff check --select I,tests/docs,test_architecture_boundaries.py, and unit test suites pass locally.Supersedes #43.