Skip to content

[WIP] feat: add NPU SAS + LI patch for DeepSeek-V4 without mindspeed - #260

Open
0hujun wants to merge 1 commit into
modelscope:mainfrom
0hujun:dsv4
Open

[WIP] feat: add NPU SAS + LI patch for DeepSeek-V4 without mindspeed#260
0hujun wants to merge 1 commit into
modelscope:mainfrom
0hujun:dsv4

Conversation

@0hujun

@0hujun 0hujun commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What is changed

为 DeepSeek-V4 的注意力层添加 NPU 融合算子 patch:

  1. SAS(SparseAttnSharedKV):将原始稀疏注意力替换为 twinkle.kernel.ops.dsv4_sas_li.aclnn_ops.SparseAttnSharedKV 融合算子;
  2. LI(LightningIndexer):将原始 torch 实现 top-k 索引替换为 twinkle.kernel.ops.dsv4_sas_li.aclnn_ops.LightningIndexer 融合算子。

两个 patch 均为 NPU-only,非 NPU 环境保持默认行为不变。

Motivation

DeepSeek-V4 的混合注意力结构中,稀疏注意力计算和 lightning indexer 索引计算在 NPU 上使用通用 PyTorch 算子串行执行,存在 kernel launch 开销大、显存占用高、耗时波动剧烈等问题。

Performance Results

速度提升(6 层对比)

配置 稳态每 step(s) 每层耗时(s) 提升 稳定性
不开 patch 8.56 1.427 1.0x 5.1~13.3s(极不稳定)
开 SAS+LI 3.60 0.600 2.38x 3.4~3.9s(稳定)

LI 增量收益(12 层对比)

配置 稳态每 step(s) 每层耗时(s) 相对 SAS-only
只开 SAS 7.80 0.650 1.0x
开 SAS+LI 7.34 0.612 1.06x(快 5.9%)

显存与可训练层数

配置 8 卡最大层数 显存峰值 2 机训练
不开 patch 6 层(8 层 OOM) 64GB/卡 不支持
开 SAS+LI ≥12 层 显著降低 支持

Summary

  • SAS+LI patch 使每层训练耗时降低 58%(1.427→0.600s/层),每 step 提速 2.38 倍;
  • 突破显存瓶颈,8 卡可训练层数从 6 层提升至 12+ 层,支持 2 机扩展;
  • LI 在 SAS 基础上额外提供约 6% 增量加速,并显著减少耗时毛刺。

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.

1 participant