Merged
A5 QSMLA 支持N泛化和LSE #9167
A5 QSMLA 支持N泛化和LSE #9167
Merged
CccccccAdd on Jul 25
Ccccccc
CccccccCollaborators
Jul 25

描述

A5 QSMLA 支持N泛化:【1,128】全泛化
和支持lse输出

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Ccccccc's contribution.)
CccccccCccccccCollaborators
Jul 25 Created pull request, commit 26e07322
atomgit-bot
atomgit-bot
Jul 25 Comments:

变更摘要

此 PR 为 quant_sparse_flash_mla 注意力算子新增 softmax LSE(Log-Sum-Exp)输出 功能,同时修复了 Split-G 模式下 G 轴切分的计算逻辑。调整涉及 Host 端参数解析、Tiling 数据传递、Kernel 端数据流处理、CPU 参考实现以及测试验证全链路。

主要改动

  • 新增 Softmax LSE 输出支持:在 QSMLAParaInfo、QSMLATilingInfo 和 Tiling 数据结构中增加 returnSoftmaxLse 字段;InferShapeQuantSparseFlashMla 根据 layoutQ(TND/BSND)动态计算 softmaxLseShape;InferDataTypeQuantSparseFlashMla 将 LSE 输出数据类型设为 DT_FLOAT;Kernel 入口宏 QSMLA_OP_IMPL 将 softmax_lse 指针传入 Init,LoopSOuterOffsetInit 负责计算不同 Layout 下的 softmaxLseOffset。

  • 修复 Split-G 模式下 G 轴分配逻辑:ComputeAxisIdxByBnAndGs1 中 goIdx 由硬编码 0/64 改为 ceil(gSize/2) 动态计算,并新增 gSplitSize 字段记录每个 AIC 实际处理的 G 轴行数;ComputeSouterParam 中 mRealSize 由右移一位改为 s1RealSize * gSplitSize;LoopSOuterOffsetInit 中 Split-G 的 LSE 偏移也采用 aicIdx >> 1 统一处理。

  • 测试框架适配双输出验证:test_qsmla_quant_process_graph 和 test_qsmla_quant_process_ci 返回四元组(NPU 主输出、CPU 主输出、NPU LSE、CPU LSE);test_quant_sparse_flash_mla_batch.py 和 test_quant_sparse_flash_mla_single.py 分别校验主输出和 LSE 精度,失败时合并输出结果;GeneralizedSFAQuant 新增 lse_trans_bnsd_to_target_layout 方法并返回 softmax_lse。

  • 元数据 Kernel Split-G 条件变更:ParamsInit 中触发 isSplitG_ 的条件从 numHeadsQ_ == 128 改为 groupSize_ > 64U,使 Split-G 判断更通用。

  • Host 端参数传递与常量补充:新增 SOFTMAX_LSE_NAME、DIM_IDX_ZERO 常量;QSMLAInfoParser::GetAttrParaInfo 读取 returnSoftmaxLse 属性并写入 Tiling 信息;CleanOutput 接口增加 softmaxLse 参数。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 25 Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
Jul 25 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 25 Comments:

CLA Signature Pass

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

likedislike
43 messages are collapsed here。 See more
wangzhe123456789
wangzhe123456789Collaborators
Jul 27 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 27 Added label: approved
songjionghui
songjionghuiCollaborators
Jul 27 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 27 Added label: lgtm
CANN-robotCANN-robotCollaborators
Jul 27 Merged pull request