Pull Request已成功合入, 合并人@ascend-robot
(感谢 lanwangli 的贡献)变更摘要
本 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_mask、block_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_layout及TND布局所需的actual_seq_lengths,通过ResolveOutputDtype解析输出 dtype,分配attentionOut与softmaxLse,并调用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_out与softmax_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_TOL为1e-2。


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


ascend docs pipeline is running...


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


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_linux_x86_abi1 | ✅ | >>> |
| Build_linux_arm_abi1 | ✅ | >>> | |
| Build_linux_arm_abi0 | ✅ | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_linux_arm | ✅ | >>> |
| 流水线 | PR-pipeline_MindIE-SD_gitcode | ✅ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/lgtm


/lgtm


/approve


/merge


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
Overall Sequence
Merge Safety
该 PR 需要在 !514 算子本体与构建启用合入后再合入。测试脚本通过
torch.ops.mindiesd.eagle_quant_block_sparse_attention调用算子。本 PR 不修改 kernel / tiling。Test Plan
build/build_plugin.sh或python setup.py bdist_wheelpython tests/ops/eagle_quant_block_sparse_attention/eagle_quant_block_sparse_attention_golden.py1e-2Test Report
测试环境: Ascend 950,CANN 9.x
_custom_ops.py注册python tests/ops/eagle_quant_block_sparse_attention/eagle_quant_block_sparse_attention_golden.py