已开启
[RFC]: 上库 eagle_quant_block_sparse_attention 算子和 plugin 适配 #197
lanwangli创建于 6月27日
lanwangli
6月29日 评论:
6月29日 评论:
感谢提交功能建议!本 Issue 已标记为 enhancement 并补充 ai-triaged 标签。\n评估状态:已记录,维护团队将在本周评估实现复杂度。\n\n该 RFC 涉及 eagle_quant_block_sparse_attention 算子的上库方案,建议后续在 PR 中补充设计评审记录和测试覆盖。\n\n---\n关联分析:发现 PR !394 ([Feature][op][eqbsa-05] add golden precision test) 可能与本 Issue 相关。\n该 PR 状态:open,目标分支:dev。\n建议维护者确认关联关系。


7月3日 关联了看板:MindStudio ISSUE管理
7月14日 关联了看板:MindIE-SD
8 天前 关联了pull request:[Feature][op][eqbsa-01] support CANN msprof include layout
8 天前 关联了pull request:[Feature][op][eqbsa-02] add operator source tree
8 天前 关联了pull request:[Feature][op][eqbsa-03] enable operator build registration
8 天前 关联了pull request:[Feature][op][eqbsa-04] expose plugin and Python API
8 天前 关联了pull request:[Feature][op][eqbsa-05] add golden precision test
8 天前 关联了pull request:[Feature][op][eqbsa-01] support CANN msprof include layout
8 天前 关联了pull request:[Feature][op][eqbsa-02] add attention infra scaffolding
8 天前 关联了pull request:[Feature][op][eqbsa-03] add operator source and enable build
8 天前 关联了pull request:[Feature][op][eqbsa-04] expose plugin API and golden test
状态 (Status): Draft
作者 (Authors): lanwangli
创建日期 (Created): 2026-06-27
更新日期 (Updated): 2026-06-27
相关 Issue/PR: 待关联
1. 概述
1.1 简介
本 RFC 提议在 MindIE-SD 中上库
eagle_quant_block_sparse_attention算子及对应 plugin 适配,提供面向 Ascend 950 / arch35 的量化块稀疏 Attention 能力。该算子将量化 Attention 与 Block Sparse Attention 两类优化叠加:在计算路径上对 Q/K 采用 INT8 量化,对 P/V 相关路径采用 FP8 低精度表示,并通过 block sparse mask 或 index 表达稀疏块选择,从而降低长序列 Attention 的计算量、访存压力和中间张量开销。MindIE-SD 侧通过 CANN 自定义算子目录交付 op_host、op_api、op_kernel 和 tiling 实现;通过
libPTAExtensionOPS.so注册torch.ops.mindiesd.eagle_quant_block_sparse_attention;并在mindiesd.layers._custom_ops提供 Python wrapper 与 fake op,供上层模型按稳定接口调用。1.2 动机
图像/视频生成模型中,Attention 是端到端推理的核心耗时来源之一。随着分辨率、帧数和序列长度增长,全量 Attention 的计算和访存成本快速上升。已有块稀疏 Attention 可以跳过低价值 block,量化 Attention 可以降低矩阵计算和数据搬运成本,但单独使用任一方案仍难以覆盖长序列、高吞吐场景的性能诉求。
eagle_quant_block_sparse_attention的目标是把两类收益叠加:torch.ops.mindiesd与 Python wrapper不做该适配的影响包括:
1.3 目标
csrc/ops/eagle_quant_block_sparse_attention,包含 op_host、op_api、op_kernel、tiling 和 arch35 kernel。torch.ops.mindiesd.eagle_quant_block_sparse_attention,并提供 Python wrapper / fake op。非目标
block_sparse_attentionbridge 保持不变,本算子作为新增 eagle quant BSA 路径。2. 方案拆分
为降低单 PR 评审和合入风险,本 RFC 对应的改动按互不重叠的 5 个 PR 拆分:
eagle_quant_block_sparse_attention源码目录build_ops.sh的 CANN 9.x 算子列表3. 接口说明
新增接口:
torch.ops.mindiesd.eagle_quant_block_sparse_attention( query, key, value, block_sparse_mask=None, block_shape=[128, 128], q_input_layout="BNSD", kv_input_layout="BNSD", num_key_value_heads=1, scale_value=1.0, inner_precise=4, actual_seq_lengths=None, actual_seq_lengths_kv=None, softmax_lse_flag=0, q_dequant_scale=None, k_dequant_scale=None, v_dequant_scale=None, ) -> (attention_out, softmax_lse)核心约束:
BNSD/TND布局,Q 和 KV layout 需一致。actual_seq_lengths与actual_seq_lengths_kv。inner_precise=4。block_sparse_mask支持 int8 mask 或 int32 index。4. 测试计划
5. 风险与约束