已合并
QuantBatchMatmul伪量化MXA8W4算子迁移blaze框架 #7921
QuantBatchMatmul伪量化MXA8W4算子迁移blaze框架 #7921
已合并
sunduiyang创建于 7月24日
sunduiyang
sunduiyang成员
7月24日

描述

本PR完成了QuantBatchMatmulV4伪量化MXA8W4算子从CMCT迁移到blaze框架的实现,并移除了cmct相关代码,同时对kernel性能进行了优化,主要改动如下:

  • Tiling部分从cost model tiling算法切换到SWAT tiling算法;
  • 数据流校验拦截继承已有基类复用代码;
  • Kernel实现部分新增blaze组件,具体参考 ops-tensor仓 PR187 说明。

关联的Issue

#4352

测试

本地tiling UT验证,白盒、泛化、二级冒烟验证通过。

文档更新

不涉及

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 sunduiyang 的贡献)
sunduiyangsunduiyang成员
7月24日 创建了 pull request,commit fdccb5e4
atomgit-bot
atomgit-bot
7月24日 评论:

变更摘要

本PR将 QuantBatchMatmulV4 伪量化 MXA8W4 算子从 CMCT 框架迁移到 blaze 框架,移除了所有 CMCT 相关 kernel 代码,新增基于 SWAT(自适应分块)算法的 tiling 求解器和 blaze kernel 实现;同时重构了 tiling 基类 QuantBatchMatmulV4TilingBase,将数据校验逻辑上移至基类以复用代码,并将 QuantBatchMatmulV4RegBase 子类独立为单独文件。

主要改动

  • CMCT 代码移除与 blaze kernel 新增:删除了 cmct/ 目录下的 block_mmad_mx_weight_from_ub.hblock_scheduler_swizzle_in_mn_core_nn.hblock_prologue_b_cast_scsc_nn.hcmct_convertor.h 共四个 CMCT 组件文件;新增 quant_batch_matmul_v4_weight_quant_mx_blaze.h,基于 Blaze::Gemm 组件(BlockMmadBlockSchedulerMatmulSwatWithTailSplitGemmUniversal)实现 MX 伪量化 kernel。

  • SWAT Tiling 算法替代 Cost Model:新增 WeightQuantMxSwatTilingSolver.h + .cpp,约 700 行)实现自适应分块求解器,从 L0/L1/UB 容量约束出发计算 baseM/baseN/baseKtileShapeKL1、尾块拆分等 tiling 参数;新增 QuantBatchMatmulV4WeightQuantMxSwatTiling tiling 策略类,其 DoOpTiling 先后尝试 2-buffer 和 4-buffer 求解,失败时回退到保守策略。

  • Tiling 基类重构以复用数据校验:将 CheckA8W4ParamsCustomCheckCheckCoreNumGetTilingKey 从子类 QuantBatchMatmulV4RegBase 上移至基类 QuantBatchMatmulV4TilingBase;基类新增 CheckTilingDataCapacitySerializeTilingData 通用方法替代原先各自实现的 PostTiling 序列化逻辑;QuantBatchMatmulV4RegBase 拆分到独立的 .h/.cpp 文件中。

  • 新增 SWAT 专用 Tiling 数据结构:在 quant_batch_matmul_v4_tiling_data_apt.h 中新增 QuantBatchMatmulV4WeightQuantMxSwatTilingData 结构体(含 baseM/baseN/baseKtileShapeKL1mTailTile/nTailTilemBaseTailSplitCnt/nBaseTailSplitCnt 等字段),并在 tiling key 中将 MX 场景的模板参数结构体从 QuantBatchMatmulV4TilingDataParams 切换为该新结构体。

  • 算子注册分发调整:在 quant_batch_matmul_v4_tiling_registry.cpp 中新增 QuantBatchMatmulV4WeightQuantMxSwatTiling(优先级 7)和 QuantBatchMatmulV4RegBase(优先级 1)两个 tiling 策略注册项;kernel 入口 quant_batch_matmul_v4.cpp 中 MX 分支从调用 QuantBatchMatmulV4::InvokeKernel 改为调用 QuantBatchMatmulV4::Arch35::InvokeWeightQuantMxBlazeSwat

likedislike
不准确?
atomgit-bot
atomgit-bot
7月24日 评论:

代码审查

Closing Summary

已逐文件审查完毕,以下是所有变更文件的审查结论:

文件 审查结果
quant_batch_matmul_v4_reg_base_tiling.cpp 无问题
quant_batch_matmul_v4_reg_base_tiling.h 无问题
quant_batch_matmul_v4_tiling.cpp 无问题
quant_batch_matmul_v4_tiling.h 无问题
quant_batch_matmul_v4_weight_quant_mx_swat_tiling.cpp P2 ×1, P3 ×1
quant_batch_matmul_v4_weight_quant_mx_swat_tiling.h 无问题
quant_batch_matmul_v4_weight_quant_mx_swat_tiling_solver.cpp 无问题
quant_batch_matmul_v4_weight_quant_mx_swat_tiling_solver.h 无问题
quant_batch_matmul_v4_tiling_registry.cpp 无问题
quant_batch_matmul_v4.cpp (kernel) 无问题
quant_batch_matmul_v4_tiling_data_apt.h 无问题
quant_batch_matmul_v4_tiling_key.h 无问题
quant_batch_matmul_v4_weight_quant_mx_blaze.h 无问题
test_quant_batch_matmul_v4_tiling.cpp 无问题
test_quant_batch_matmul_v4_tiling.csv 无问题

发现问题汇总:

  • P2: 1 个(SWAT tiling workspace 乘法溢出风险)
  • P3: 1 个(日志函数返回值冗余建议)

整体风险判断: 低。核心逻辑迁移(CMCT→blaze、cost model tiling→SWAT tiling)结构清晰,数据校验被合理上移到基类复用。唯一的 P2 问题在极端 shape 下才可能触发,修复简单。建议在合入前修复 workspace 溢出问题。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
不准确?
CANN-robotCANN-robot成员
7月24日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月24日 评论:

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
cmake 刘波, 商晓波 (2/2) 刘波, 商晓波 (2/1)
matmul 徐炳麟, 刘波, 刘泱, 商晓波 (4/2) 刘泱, 商晓波 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
此处折叠了91条消息 查看更多
liubo75成员
7月30日 评论:

/approve
/lgtm

likedislike
CANN-robotCANN-robot成员
7月30日 添加了label:lgtm
CANN-robotCANN-robot成员
7月30日 关闭了关联的issue
CANN-robotCANN-robot成员
7月30日 合入了pull request
CANN-robot
CANN-robot成员
7月30日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike