Pull Request has been successfully merged by CANN-robot.
(Thank you for 杨志鹏's contribution.)变更摘要
该 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。


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


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.


描述
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
测试
文档更新
类型标签