Merged
[QFA][HIFP8]: 支持 HIF8 per-tensor 量化模式 #9573
[QFA][HIFP8]: 支持 HIF8 per-tensor 量化模式 #9573
Merged
杨志鹏Add on Aug 4
杨志鹏
杨志鹏Collaborators
Aug 4

描述

quant_flash_attn/quant_flash_attn_metadata接口是全量化FA专用接口
本PR将fused_infer_attention_v2接口的HIF8全量化适配至quant_flash_attn和quant_flash_attn_metadata接口
需先调用quant_flash_attn_metadata获取metadata信息,然后将其传入quant_flsah_attn接口,功能与fused_infer_attention_v2保持一致

关联的Issue

关联Issue #4561

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 杨志鹏's contribution.)
杨志鹏杨志鹏Collaborators
Aug 4 Created pull request, commit 58276639
atomgit-bot
atomgit-bot
Aug 4 Comments:

变更摘要

该 PR 为 quant_flash_attn 算子新增了 HIF8 per-tensor 量化模式支持(QfaQuantMode::A8C8_QKV_HIF8_P_PER_TENSOR_SOFTMAX_FP32 = 7),与现有的 MXFP8 per-tensor 模式并存。HIF8 模式下,Q/K/V 张量数据类型为 DT_HIFLOAT8,descale 采用 per-tensor 的 FLOAT32 标量(shape 为 (1,)),而非 MXFP8 的 FLOAT8_E8M0 块级 descale。同时引入了专属的 Cube/Vector/Kernel 实现文件及新的 tiling 配置(S2=256 对齐),并通过模板实例化在 kernel 入口处根据 quantMode 进行路由分发。

主要改动

  • 新增 HIF8 量化模式枚举与常量: 在 qfa_tiling_info.h 中新增 QfaQuantMode::A8C8_QKV_HIF8_P_PER_TENSOR_SOFTMAX_FP32 = 7;在 quant_flash_attn_common_def.h 中新增 QFA_HIF8_FP32_PREFILL = 7 以及 Config_S1Aligned128_S2Aligned256_DAligned64/128 两组 tiling 配置,为 HIF8 模式提供编译期标识与参数组合。

  • 新增 HIF8 专属内核文件: 新增 quant_flash_attn_block_cube_hif8.h(矩阵乘法 Cube 块,直接使用普通 MatMul 无 MX scale)、quant_flash_attn_block_vec_hif8.h(向量处理 Vec 块,不使用 pScale,v_scale 在 vec2 中应用)和 quant_flash_attn_kernel_hif8.h(HIF8 内核主逻辑,从 GM 读取 per-tensor 的 float32 scale 并传递给 vec block),三者共同构成完整的 HIF8 量化计算管线。

  • 输入类型与 descale 校验适配: common_checker.cpp 中 Q/K/V 的数据类型校验改为根据 quantMode 区分:MXFP8 模式要求 DT_FLOAT8_E4M3FN,HIF8 模式要求 DT_HIFLOAT8。quant_checker.cpp 与 quant_flash_attn_def.cpp 中 descale 输入同时接受 DT_FLOAT8_E8M0 和 DT_FLOAT,HIF8 模式下 descale shape 固定为 1D (1,),dtype 为 FLOAT32。

  • Tiling 策略分化与布局约束扩展: HIF8 模式下 sInnerFactor_ 设为 SINNER_256(MXFP8 为 SINNER_512);UpdateTilingKeyConfig 和 AdjustSinnerAndSouter 均加入 HIF8 分支;QFA_LAYOUT_CONSTRAINT_TABLE 新增 HIF8 对应的 layout 约束(layout_q=TND,layout_kv∈{TND, BSND, BNSD});新增 CheckHeadDimConstraint 方法限制 HIF8 下 head_dim ≤ 128。

  • Kernel 入口路由: quant_flash_attn.cpp 中新增 quant_flash_attn_hif8 模板函数,当 ORIG_DTYPE_Q == DT_HIFLOAT8 且 quantMode == QFA_HIF8_FP32_PREFILL 时分发到 HIF8 Kernel;模板实例化 key 的描述更新以包含 Config_S1Aligned128_S2Aligned256_DAligned64/128 和 QFA_HIF8_FP32_PREFILL。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 4 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 4 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
*/*/op_host/*_def.cpp ✅ 王永光, 黄俊健, 刘丹 (3/2) ✅ 王永光 (1/1)
attention ✅ shen_weiling, 黄俊健, 刘丹 (3/2) ✅ 刘丹, shen_weiling, 黄俊健 (3/1)
sig-ops-transformer ✅ 黄俊健, 刘丹 (2/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

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

likedislike
CANN-robotCANN-robotCollaborators
Aug 4 Set hz36amy_00,coder_linx,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,tang-lei01,liudan12,shasha_an,wangzhe123456789,cc-z,shen_weiling,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,wangyongguang,haijie_699874,zzy__,yuhao_,L_Euler as approver
831 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 27 Added label: lgtm
CANN-robot
CANN-robotCollaborators
Aug 27 Comments:

The MR can not be merged, because of CodeReview discussion not resolved

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

likedislike
shen_weilingshen_weilingCollaborators
Aug 27 Resolved final issue
CANN-robotCANN-robotCollaborators
Aug 27 Closed associated issue
CANN-robotCANN-robotCollaborators
Aug 27 Merged pull request