已开启
新增 level4 算子 MiniMaxSparseAttentionPrefill/Decode #106
新增 level4 算子 MiniMaxSparseAttentionPrefill/Decode #106
已开启
wesseI创建于 8月28日
wesseI
wesseI
8月28日

新增 level4 算子 MiniMaxSparseAttentionPrefill/Decode

likedislike
合并受阻
atomgit-bot
atomgit-bot
8月28日 评论:

变更摘要

本 PR 为 npu-kernelbench 的 data/kernel_generator/level4 新增两个 level4 算子:MiniMaxSparseAttentionPrefill 和 MiniMaxSparseAttentionDecode,每个算子各包含一份 definition.json 算子定义(含输入/输出规格、op_type 为 attention,以及一段 PyTorch 参考实现)和一份 workload.jsonl 测试用例集。两个算子实现的是 MiniMax Sparse Attention (MSA) 前向计算:通过 index_q/index_k 的点积为每个查询和 GQA group 挑选 top-16 个 key block(block_size=128,含 local block),再在主分支上对选中的 token 做 FP32 缩放点积注意力(64 个查询头、4 个 KV 头、group_size=16),输出为 W_o 投影前的逐头上下文。Prefill 面向 chunked prefill(单样本、[T, 64, 128] 查询、支持因果可见长度),Decode 面向批量单步 decode([B, 64, 128] 查询、样本沿 batch 维度堆叠)。

主要改动

  • 新增 MiniMaxSparseAttentionPrefill/definition.json:定义算子输入(q、index_q、k、v、index_k,均为 bfloat16)、输出 out,并内置 PyTorch 参考实现,实现按块选择(top-16 blocks、stable argsort、local block 强制保留)后按 GQA group 计算 softmax 注意力。
  • 新增 MiniMaxSparseAttentionDecode/definition.json:定义批量 decode 场景下与 Prefill 语义一致的输入输出及参考实现,差异在于每个样本只有一个查询 token、位于各自 KV 序列末尾,且所有样本共享相同的序列长度 L。
  • 新增 MiniMaxSparseAttentionPrefill/workload.jsonl:包含 13 条随机输入测试用例,覆盖 T 为 4096/8192、KV 长度 L 从 4096 到 524288 的不同组合,统一设置容差 max_atol/max_rtol 为 0.02。
  • 新增 MiniMaxSparseAttentionDecode/workload.jsonl:包含 18 条随机输入测试用例,覆盖 batch 30/60/90 与 KV 长度 4096 到 524288 的组合,q/k/v/index_* 均使用 bfloat16 随机数据。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月28日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
ascend-robotascend-robot成员
8月28日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
8月28日 评论:

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.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-Ascend/ascendc-kernelgen-data ❌ (0/2)(You can also ask: 田晟兆, 冯彤, 许涛, 刘莹莹, 何建平) ❌ (0/1)(You can also ask: 冯彤, 文一晴, 田晟兆, 柴光, 李星辰)

💡 Tip:

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

CLA Signature Pass

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

likedislike