已合并
[Feature][op][eqbsa-03] expose plugin API and golden test #515
[Feature][op][eqbsa-03] expose plugin API and golden test #515
已合并
lanwangli创建于 23 天前
lanwangli成员
23 天前

Which issue(s) this PR fixes or accomplishes

Fix part of #197

关联 Issue:https://gitcode.com/Ascend/MindIE-SD/issues/197

Purpose

上库 eagle_quant_block_sparse_attention 算子和 plugin 适配,关联 RFC: #197。

该算子用于叠加量化和块稀疏 Attention 能力:Q/K 采用 INT8 量化,P/V 相关路径采用 FP8 低精度表示,并通过 block sparse mask/index 降低长序列 Attention 的计算和访存开销。

本 PR 暴露 MindIE-SD PyTorch plugin / torch schema / Python wrapper / fake op,并新增 golden 精度测试。上层可通过 torch.ops.mindiesd.eagle_quant_block_sparse_attention 调用该算子;测试覆盖 block sparse mask 与 index 两种模式,并与 CPU reference 比较误差。

Scope

  • csrc/CMakeLists.txt
  • csrc/plugin/eagle_quant_block_sparse_attention.cpp
  • csrc/plugin/eagle_quant_block_sparse_attention.h
  • csrc/plugin/register_ops.cpp
  • mindiesd/layers/_custom_ops.py
  • tests/ops/eagle_quant_block_sparse_attention/eagle_quant_block_sparse_attention_golden.py

Overall Sequence

  1. 构建兼容性: !512
  2. 算子源码 + attention infra + 构建启用: !514
  3. Plugin API + golden 测试: !515

Merge Safety

该 PR 需要在 !514 算子本体与构建启用合入后再合入。测试脚本通过 torch.ops.mindiesd.eagle_quant_block_sparse_attention 调用算子。本 PR 不修改 kernel / tiling。

Test Plan

  1. Plugin 编译
    • build/build_plugin.shpython setup.py bdist_wheel
  2. 单算子精度(Ascend 950)
    • python tests/ops/eagle_quant_block_sparse_attention/eagle_quant_block_sparse_attention_golden.py
    • 覆盖 mask(int8)与 index(int32)两种 block sparse 模式
    • 与 CPU reference 比较,EB 阈值 1e-2

Test Report

测试环境: Ascend 950,CANN 9.x

测试项 命令/步骤 结果
plugin/API plugin 源文件与 _custom_ops.py 注册
golden 精度 python tests/ops/eagle_quant_block_sparse_attention/eagle_quant_block_sparse_attention_golden.py ✅ 已在 Ascend 950 上完成验证

Ascend 950 golden 精度测试通过

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 lanwangli 的贡献)
Llanwangli成员
23 天前 创建了 pull request,commit 3f811478
Llanwangli成员
23 天前 关联了issue:[RFC]: 上库 eagle_quant_block_sparse_attention 算子和 plugin 适配
atomgit-bot
atomgit-bot
23 天前 评论:

变更摘要

本 PR 为 eagle_quant_block_sparse_attention 算子补齐 MindIE-SD 的 PyTorch plugin 暴露与 golden 精度测试:在 register_ops.cpp 中新增 torch.ops.mindiesd.eagle_quant_block_sparse_attention 的 schema 与 PrivateUse1 实现注册,新增 eagle_quant_block_sparse_attention.cpp / eagle_quant_block_sparse_attention.h 封装 aclnnEagleQuantBlockSparseAttention 内核调用,在 mindiesd/layers/_custom_ops.py 中新增 Python 包装函数与 fake op,并新增 golden 测试脚本验证 mask 与 index 两种 block sparse 模式下与 CPU reference 的精度误差。

主要改动

  • 新增算子 schema 与注册register_ops.cpp 通过 m.def("eagle_quant_block_sparse_attention(...)") 定义了包含 block_sparse_maskblock_shape、layout、量化 scale、*_dtype 等参数的接口,并将 eagle_quant_block_sparse_attention_impl_npu 注册到 PrivateUse1 后端。
  • 新增 NPU plugin 实现eagle_quant_block_sparse_attention_impl_npu 校验 q_input_layout/kv_input_layoutTND 布局所需的 actual_seq_lengths,通过 ResolveOutputDtype 解析输出 dtype,分配 attentionOutsoftmaxLse,并调用 aclnnEagleQuantBlockSparseAttention
  • 新增可选 dtype 校验逻辑CheckOptionalInputDtype 允许 query_dtype/key_dtype/value_dtype 与 INT8 存储类型(at::kChar)不一致的 FP8 逻辑 dtype,用于量化 bitcast 调用路径的 API 兼容校验。
  • 新增 Python 包装与 fake op_custom_ops.py 新增 eagle_quant_block_sparse_attention 函数按条件组装 torch.ops.mindiesd 调用参数,并新增 eagle_quant_block_sparse_attention_fake 依据 layout 生成 attention_outsoftmax_lse 的 shape/dtype。
  • 新增 golden 精度测试eagle_quant_block_sparse_attention_golden.py 覆盖 mask(int8)与 index(int32)两种 block sparse 模式,对 Q/K 做 INT8 分块量化、P/V 使用 FP8,并与 CPU reference 比较相对误差,EB_TOL1e-2
likedislike
atomgit-bot
atomgit-bot
23 天前 评论:

代码审查

✅ 未发现问题

likedislike
ascend-robotascend-robot成员
23 天前 添加了label:ascend-cla/yes
Llanwangli成员
23 天前 修改了pull request 的描述
ascend-robot
ascend-robot成员
23 天前 评论:

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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-Ascend/MindIE-SD weixin_44144262, changetheway (2/2) weixin_44144262 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
ascend-robotascend-robot成员
23 天前 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
23 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
23 天前 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
23 天前 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
23 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
23 天前 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
23 天前 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
23 天前 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
23 天前 评论:
流水线 PR-pipeline_MindIE-SD_gitcode#1745 [ commitID:4d7080d6 ] 已完成
>>>代码风格自动修复执行失败,具体请查看日志,不影响流水线执行及PR合入
阶段 任务名 状态 详情
编译构建 Build_linux_x86_abi1 >>>
Build_linux_arm_abi1 >>>
Build_linux_arm_abi0 >>>
恶意代码检查 Antipoison >>>
开源片段检查 SCA >>>
开发者测试 UT_linux_arm >>>
流水线 PR-pipeline_MindIE-SD_gitcode >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
Llanwangli成员
23 天前 修改标题为 “[Feature][op][eqbsa-03] expose plugin API and golden test”,原标题为“[Feature][op][eqbsa-04] expose plugin API and golden test”
Llanwangli成员
23 天前 修改了pull request 的描述
changetheway成员
23 天前 评论:

/lgtm

likedislike
lijinxi
lijinxi成员
23 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
23 天前 添加了label:lgtm
lijinxi
lijinxi成员
23 天前 评论:

/approve

likedislike
ascend-robotascend-robot成员
23 天前 添加了label:approved
blian
blian成员
15 天前 评论:

/merge

likedislike
ascend-robotascend-robot成员
15 天前 添加了label:keeper_approved
ascend-robotascend-robot成员
15 天前 合入了pull request