Merged
feat(mixed_quant_sparse_flash_mla): migrate TurboQuant support to 9.2.0 #12425
feat(mixed_quant_sparse_flash_mla): migrate TurboQuant support to 9.2.0 #12425
Merged
wangbin207Add on Sep 19
wangbin207
wangbin207Collaborators
Sep 19

描述

将 TurboQuant 能力迁移至 MixedQuantSparseFlashMla,为 arch22 新增 quant_mode=3 执行路径,同时保留 arch35 原有 quant_mode=1/2 能力。

主要修改如下:

  • 新增 arch22 TurboQuant Kernel:

    • 迁移 Cube、Vector、调度及公共数据结构实现。
    • 支持 FP16/BF16 Query、原始 KV 和输出。
    • 支持 UINT8 存储的 TQ4 compressed KV。
    • 支持 TND Query 与 PA_BBND 分页 KV 布局。
  • 迁移 TQ4 计算与性能优化:

    • 支持 256 字节 packed code 与 FP16 scale 组成的 258 字节 compact slot。
    • BF16 路径使用 byte LUT 一次完成两个 4bit code 的 centroid 查表。
    • 支持批量反量化和尾块处理。
    • 保留 FP16 原有反量化路径。
    • 迁移预加载、流水并行及临时缓存复用逻辑。
  • 接入 MixedQuantSparseFlashMla 现有接口:

    • 不新增或调整对外参数顺序。
    • 新增 quant_mode=3 的 TilingData、TilingKey、workspace 和 Kernel dispatch。
    • ACLNN 预处理在 quant_mode=3 时保留 compressed KV 的 UINT8 类型。
    • Metadata 接口的 quant_mode 支持范围扩展至 3。
  • 按 SOC 隔离数据类型与量化模式:

    • ascend910b/ascend910_93 支持 FP16/BF16 + UINT8 TQ4。
    • ascend950 保留原有 BF16 + FP8。
    • arch22 仅允许 quant_mode=3。
    • arch35 继续仅允许 quant_mode=1/2。
  • 迁移滑动窗口 Mask 修复:

    • MTP 多 token 场景根据每个 Query token 的实际位置计算左右边界。
    • 避免同一 tile 内多个 Query token 错误共用窗口范围。
  • 完善边界场景与参数校验:

    • 支持 TurboQuant TND 场景下 Query token 数为 0。
    • 完善 dtype、layout、block size、stride、top-k 和可选输入校验。
    • stride 校验覆盖 block size、KV head 数和 compact slot 大小。
    • 限制 TurboQuant 使用 TND/PA_BBND 布局及对应输入组合。
  • 完善 Torch Extension:

    • 根据 quant_mode 设置原始 KV 和 compressed KV 的 ACL 数据类型。
    • 支持 TurboQuant 空 Query 的 Meta 和输出 Tensor 构造。
    • 保留 9.2.0 原有的设备分配及空指针检查逻辑。

关联的 Issue

无。

测试

新增和完善以下测试:

  • TQ4 compact slot 格式验证。
  • signed nibble 与 centroid 映射验证。
  • BF16 byte LUT 全量映射验证。
  • BF16 批量反量化及尾块覆盖测试。
  • BF16 优化路径与原浮点查表路径的精度误差验证。
  • FP16 计算精度验证。
  • Attention fold 等价性及原始、压缩区域组合验证。
  • MTP 多 token 滑动窗口 Mask 验证。
  • arch22 FP16/BF16 TurboQuant Tiling 测试。
  • 非法 top-k、量化模式及空 Query 场景测试。

已完成:

  • TurboQuant 数值测试:12 passed
  • pre-commit、clang-format、ruff、codespell 和 OAT 检查
  • 静态差异及格式检查

当前环境仅安装 CANN 9.0.1,本次尚未执行 9.2.0 算子编译及 NPU 实机测试。

文档更新

本次为保持迁移改动最小化,未迁移 README 和独立算子文档,仅同步更新 ACLNN 头文件中的类型及 quant_mode 接口说明。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wangbin207's contribution.)
wangbin207wangbin207Collaborators
Sep 19 Created pull request, commit d67ea3ca
CANN-robotCANN-robotCollaborators
Sep 19 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 19 Comments:

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.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
9.2.0 ✅ gcw_kUomxQ2l, 蔡雯雯 (2/2) ✅ gcw_kUomxQ2l (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 19 Set guijianwei,hz36amy_00,yangziqi_007,coder_linx,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,huang-wei-chen,tang-lei01,liudan12,shasha_an,wangzhe123456789,Wei_NaChuan,zhangshuoleiokok,luwei_1104,cc-z,kdy18482276080,xuchengyang,shen_weiling,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,wangyongguang,haijie_699874,zzy__,Julius47,yuhao_,L_Euler,wangxun21 as approver
CANN-robotCANN-robotCollaborators
Sep 19 Set guijianwei,hz36amy_00,yangziqi_007,coder_linx,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,huang-wei-chen,tang-lei01,liudan12,shasha_an,wangzhe123456789,Wei_NaChuan,zhangshuoleiokok,luwei_1104,cc-z,kdy18482276080,xuchengyang,shen_weiling,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,wangyongguang,haijie_699874,zzy__,Julius47,yuhao_,L_Euler,wangxun21 as approver
195 messages are collapsed here。 See more
caiwenwen
caiwenwenCollaborators
Sep 24 Comments:

/approve
/lgtm

likedislike
CANN-robot
CANN-robotCollaborators
Sep 24 Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: 蔡雯雯

likedislike
CANN-robotCANN-robotCollaborators
Sep 24 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 24 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 24 Merged pull request