Skip to content

[PERF] Ascend NPU: Optimize Wan2.2 inference to surpass vLLM-Omni on 910B2 - #58

Merged
lzx1413 merged 2 commits into
Tele-AI:mainfrom
yx0716:perf/ascend-910b-wan22
Nov 26, 2026
Merged

lzx1413 merged 2 commits into
Tele-AI:mainfrom
yx0716:perf/ascend-910b-wan22

Conversation

@yx0716

@yx0716 yx0716 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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

  1. Fused Ascend NPU RoPE & device frequency caching (telefuser/ops/rotary.py, telefuser/models/wan_video_dit.py)
    • Add _apply_rotary_emb_npu backed by torch_npu.npu_rotary_mul(..., rotary_mode="interleave").
    • Cache device-resident (freqs_cos, freqs_sin) per (f, h, w, freq_start_idx, freq_interval, device, dtype) on WanModel (cleared on offload_device), eliminating per-forward CPU complex128 concatenation, H2D transfers, and float64 → float32 casts (~22.6 s saved across 50 CFG steps).
  2. Eliminate per-block [B, seq_len, 6, dim] modulation materialization (telefuser/models/wan_video_dit.py)
    • Keep scalar-timestep t_mod at [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).
  3. Fused Ascend NPU RMSNorm (telefuser/ops/normalization.py)
    • Implement RMSNorm.forward_npu via torch_npu.npu_rms_norm (~8.5 s saved).
  4. Skip redundant pure-BF16 autocast("npu") upcasts & float64 fallbacks (ti2v_denoising.py, vae.py, wan_video_dit.py, unipc.py)
    • Bypass outer 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).
    • Use float32 on NPU in sinusoidal_embedding_1d and run tiny 2×2 linalg.solve on CPU in FlowUniPCMultistepScheduler to avoid aten::_linalg_solve_ex NPU fallback syncs.
  5. Layout & residual micro-optimizations (telefuser/models/wan_video_dit.py)
    • Replace redundant einops.rearrange / double-reshapes around rope_apply with unflatten / flatten, use torch.addcmul in GateModule on NPU, and apply modulation in-place on freshly normalized activations (~2.0 s saved).
  6. Zero-D2H pinned CPU parameter offload & device-side uint8 frame conversion (base_model.py, base_pipeline.py, wan22_video_vae.py, wan22_ti2v.py)
    • Enable non_blocking=True H2D transfers with current_platform.synchronize on NPU and retain a pinned CPU parameter mirror during inference so offload_device avoids repeated D2H copies, pin_memory() host allocations, and gc.collect() stalls.
    • Convert decoded frames to uint8 on device before D2H in single-process Wan22TI2VPipeline (tensor2video: 1.70 s → 0.14 s; total non-denoising overhead reduced by ~6.0 s).
  7. Optional MindIE-SD attention backend (AttnImplType.MINDIE_ATTN, from [PERF] Ascend NPU: MindIE-SD attention backend and VAE-parallel enablement #43)
    • Preserves opt-in mindiesd.attention_forward dispatch 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, PyTorch 2.10.0+cpu, torch_npu 2.10.0.post4, Diffusers 0.38.0), 4 serial runs per engine (1 cold + 3 warm):

Engine Cold (Run 0) Warm 1 Warm 2 Warm 3 Warm Median 50-Step Denoise FPS vs vLLM-Omni
TeleFuser (main / #42) 149.92 s 146.95 s 147.06 s 147.49 s 147.06 s ~132 s (2.65 s/it) 0.82 +40.11 s (+37.5%)
vLLM-Omni 0.23.0rc1 107.16 s 106.75 s 106.95 s 107.21 s 106.95 s ~96 s (1.91 s/it) 1.13 baseline
TeleFuser (this PR) 100.89 s 98.88 s 98.90 s 98.92 s 98.90 s ~90 s (1.81 s/it) 1.22 -8.05 s (-7.5%, 1.08×)
  • Determinism & Quality: All 4 runs produce byte-identical 121×480×864×3 RGB8 outputs (sha256: 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-frame MAE = 3.01 / 255, PSNR = 31.39 dB, Pearson r = 0.9939, with visually identical scene structure and no NaN/Inf.
  • Unit & Lint Checks:
    • Added tests/unit/ops/test_npu_optimizations.py covering NPU RMSNorm, NPU RoPE half/full-dim dispatch, broadcast t_mod equivalence, 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.

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)
@lzx1413
lzx1413 merged commit ed6c682 into Tele-AI:main Nov 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants