Merged
feat: 为三个 DeepSeek V4.1 算子提供 JIT 和 ACLNN 入口 #1067
feat: 为三个 DeepSeek V4.1 算子提供 JIT 和 ACLNN 入口 #1067
Merged
xuzhenghao8Add on 13 days ago
xuzhenghao8
xuzhenghao8Collaborators
13 days ago

改动

在 ops/pro/deepseek_v4_1/ 为三个算子提供 PyPTO JIT 直接调用和 ACLNN 预编译调用。238 上的隔离测试中,三个算子的 JIT 均在禁用 gym 扩展后运行成功,ACLNN 均在禁用 PyPTO 后运行成功。

  • attn_prologue 沿用私仓已有的两个入口和核调度。FRACTAL_NZ 权重的物理形状由目标分支公共 ACLNN 辅助函数传递。
  • quant_lightning_indexer(QLI) 在私仓二进制实现上补充公开 JIT 入口,两路共用 AICPU 任务规划和 AI Core 计算逻辑。Attention 与 QLI 的预编译 AI Core 代码段均已逐字节核对,与各自私仓版本一致。
  • engram_hash 在公开仓 JIT 基础上补充 ACLNN。两路共用整数哈希实现。单 token 带 mask 时并行处理各层和表,短序列、长 n-gram 且表少时并行处理各前缀。

构建与门禁

上游默认构建清单保持原样。238 用 python3 build_ci.py --clean --pkg-type whl --ops attn_prologue,engram_hash,quant_lightning_indexer 显式构建并安装三个算子。

3fd0ec9 已修复 QLI 在新 master 上的 Torch 绑定 CMake 配置,以及冷安装缺少头文件和 AICPU planner 的问题。238 上独立构建并冷安装 wheel 后,在禁止导入 PyPTO 的进程中,三个 ACLNN 算子均通过各自的 golden。QLI 的两处已安装 JIT 入口也通过 golden,进程实际加载的 native 库均来自该 wheel。

提交 1f7bbec 仅修改测试代码。CodeCheck 官方复扫由 20 项降为 15 项,新增的 5 项测试告警全部消除,致命和严重均为 0。其余 15 项已按“规范例外场景”提交审核:11 项来自沿用的私仓计算源码,3 项涉及公开 Python 签名,1 项涉及 QLI 设备 ABI。openLiBing 显示未解决 0、审核中 15,审核人为 congqiannan,该提交的 CodeCheck 门禁结果为 no pass。官方报告 · 流水线 #1289

238 重建私仓 QLI 时,旧构建脚本引用的 pypto_pro.runtime.aicpu_codegen 在该工具链中已迁移。对照包用当前 native 构建接口编译私仓原始 planner。PR 的 JIT 和 ACLNN 生成的 AICPU 设备 ELF 均为 14,152 字节,SHA-256 相同。

功能与精度

238 上以 PR d8c4475 与主线 cf5f0da 的预合并树 78d47d97 重新构建并安装 wheel。JIT 和 Torch 模式各通过 127 项(Attention 17、QLI 69、Engram 41)。三个直接 JIT 在屏蔽 gym 扩展后均通过 golden,三个 ACLNN 在禁止导入 PyPTO 后均通过 golden。

算子 基线与精度证据
Attention 沿用私仓 JIT 和 ACLNN。14 组原规格及 3 组新种子边界均通过私仓 BF16 和 FP64 判据,四条路径的输出及 KV、启用时的 QR 逐字节一致。预编译 AI Core 和 4 个 JIT tiling key 的可执行段与私仓分别相同。
QLI 在私仓 ACLNN 基础上新增正式 JIT,两路都先运行 AICPU 规划,再运行 AI Core。52 组原规格及 12 组补测通过私仓 TopK 和 BF16 Scheme A 判据,私仓 ACLNN、PR ACLNN 和 PR JIT 的四个输出逐字节一致。预编译 AI Core 可执行段与私仓相同。
Engram 提交 7577c2b 与主线 cf5f0da 的预合并树 255b4b47 在 238 重新构建。JIT、ACLNN 各通过 53 项,另测 52 组输入,主线 JIT 和 PR 两入口的 INT32 输出均与主线 CPU golden 逐元素相等。

输入校验有两处可观察差异。非连续 RoPE 在私仓 Attention JIT 上会产生错误结果,PR 两入口均报错。Engram 主线会转换文档未支持的 int32 mask,PR 两入口均要求 bool 或 uint8,并检查 ND 存储。

NPU 计算 kernel 性能

Attention 全部在 ±3% 内。Engram 的 30 个可比规格,两入口的计算耗时均低于主线。 QLI 和 Engram 的 JIT 与 ACLNN 仍有耗时差异。下表正值表示右侧入口耗时更长。

比较 ±3% 内 六轮中位数变化范围
Attention 私仓 JIT → PR JIT 14/14 -1.40% 至 +0.07%
Attention 私仓 ACLNN → PR ACLNN 14/14 -0.61% 至 +0.42%
Attention PR ACLNN → PR JIT 14/14 -1.86% 至 +0.47%
QLI 私仓 ACLNN → PR ACLNN 21/24 -3.18% 至 +4.23%
QLI 私仓 ACLNN → PR JIT 14/24 -3.93% 至 +11.23%
QLI PR ACLNN → PR JIT 14/24 -5.08% 至 +14.43%
Engram PR ACLNN → PR JIT 17/34 -5.73% 至 +12.89%
  • QLI 二进制迁移。 24 个规格中,唯一慢于私仓超过 3% 的规格为 empty_key_PA_BBND-rv0,全量六轮为 +4.23%,另起两进程独立复测六轮为 -0.08%。其他两个超限规格也在复测中落入 ±3%;其中一个规格的私仓 A/A 对照自身相差 +5.11%。
  • QLI 双入口。 24 个规格中 8 个 JIT 慢于 ACLNN 超过 3%,2 个快于 ACLNN 超过 3%。全量差距最大的 empty_query_TND-rv0 为 ACLNN 2.266 µs、JIT 2.593 µs(+14.43%),独立六轮为 +0.26%。另外两组专项复测仍慢 6.28% 和 10.79%。34 个 tiling key 的 68 个 Cube/Vector 函数在两条编译路径下均有指令差异。
    Engram 对主线。 以下为原先两个入口均回退的三个规格,列出全量六轮相对主线 JIT 的计算耗时变化。
token 数 / n-gram / 层数 / 表数 PR JIT PR ACLNN
1 / 3 / 2 / 8,有 mask -3.62% -11.41%
9 / 17 / 1 / 1,无 mask -44.34% -47.37%
9 / 17 / 1 / 1,有 mask -45.75% -49.16%

另有 4 个规格超出主线 JIT 的流核数上限,仅有 PR 两入口的实测结果。

上述三个规格另测六轮,JIT 耗时较主线降低 4.93% 至 44.53%,ACLNN 降低 13.79% 至 48.88%。

单 token 再固定 mask 为 0、1 各测,覆盖 n-gram 3 和 4。对主线 JIT 的变化范围为 PR JIT -83.68% 至 +2.51%,PR ACLNN -85.28% 至 -9.28%。

238 Ascend 950,CANN 9.3.0,PyPTO 0.3.0。msprof 开启 L2 和 task-time,逐样本在 NPU 读写各 192 MiB 并同步,覆盖 128 MiB L2。两进程各三轮,每轮每侧预热 3 次、采样 7 次,A/B 交替并逐轮反转先后。从 op_summary 只取计算任务的 Task Duration,排除刷缓存和 QLI AICPU,先取轮内中位数,再取六轮中位数。Attention、QLI 沿用 d8c4475 实测数据。Engram 在 7577c2b 重新采集 9,660 个正式样本,覆盖全量、原回退规格专项及单 token 的两种 mask 取值。另对 QLI 超限规格进行 A/A 与 A/B 专项复测。msprof 字段说明

Attention 精度标准 · QLI 测试 · Engram 测试

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for xuzhenghao8's contribution.)
xuzhenghao8xuzhenghao8Collaborators
13 days ago Created pull request, commit 625a59b2
CANN-robotCANN-robotCollaborators
13 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
13 days ago Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/pypto-gym ✅ congqiannan, liulufang_gitcode (2/2) ✅ congqiannan, liulufang_gitcode (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

xuzhenghao8, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
13 days ago Set xinweiliu,pan-boyi,lim-jiunnbin,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,li-shengxian3,yinjie27_,liulufang_gitcode,congqiannan,tsungl4,gaoxingwang,zhangxiangjie,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
13 days ago Set xinweiliu,pan-boyi,lim-jiunnbin,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,li-shengxian3,yinjie27_,liulufang_gitcode,congqiannan,tsungl4,gaoxingwang,zhangxiangjie,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
189 messages are collapsed here。 See more
congqiannan
congqiannanCollaborators
6 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
6 days ago Added label: approved
liulufang_gitcode
liulufang_gitcodeCollaborators
6 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
6 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
6 days ago Merged pull request