已合并
fix(indexer_quant_cache): reject odd cache headDim for MX-FP4 mode #9613
fix(indexer_quant_cache): reject odd cache headDim for MX-FP4 mode #9613
已合并
wangxun21创建于 19 天前
wangxun21成员
19 天前

描述

修复 indexer_quant_cache 算子在 quantMode=3(MX-FP4)模式下,cache.headDim 为奇数时产生精度错误/数据错位的问题。

根因:MX-FP4 每字节打包 2 个 fp4 逻辑元素。当 headDim 为奇数时,相邻逻辑行的起始位置会交替落在字节的高 4 位 / 低 4 位。当前 kernel 把 cache 声明为 GlobalTensor<int8_t>,仅支持整字节地址的 CopyOut,无法表达这种半字节偏移,导致输出数据错位/精度错误。

修复方案:在 host tiling (indexer_quant_cache_tiling_arch35.cpp) 的 CalcOpTiling 中新增校验——quantMode=3 时要求 cache.headDim(连续场景)以及 cache 分页 view 的 row/block stride(分页场景)必须为偶数,不满足则直接返回 GRAPH_FAILED,从"跑出错误数据"变为"直接报错拒绝非法输入"。同步更新文档约束说明,并新增 host UT 拒绝用例。

该做法与 CANN 内其他 FP4/MX-FP4 打包量化算子(如 scatter_pa_kv_cachek_head_size/v_head_size 的偶数校验、dynamic_mx_quantinput.shape[-1] 的偶数要求)保持一致——均选择在 host tiling 阶段拒绝奇数尾轴,而不是尝试支持半字节寻址。

关联的Issue

关联 Issue #4137

测试

  • 端到端验证:用 TTK aclnn 模式构造了 headDim=65(奇数)和 headDim=64(偶数)两个 MX-FP4 用例,前者 aclnnIndexerQuantCacheGetWorkspaceSize 阶段报错拒绝(ACLNN_ERR_INNER_NULLPTR),plog 确认报错发生在 indexer_quant_cache_tiling_arch35.cpp:332,未进入 kernel;后者正常执行,精度 PASS。
  • Host UT:新增测试用例 indexer_quant_cache_tiling_mxfp4_odd_headdim_rejected,验证奇数 headDim(129)在 tiling 阶段返回 GRAPH_FAILED。(本机 host UT 框架本身有环境问题——TilingContext 构造为空指针、所有用例均 segfault,与本次改动无关,已用 gdb 确认崩溃点在框架代码 tiling_case_executor.cpp:316 而非算子逻辑)

文档更新

更新了 attention/indexer_quant_cache/docs/aclnnIndexerQuantCache.md 的约束说明,新增一条:

MX-FP4(quantMode=3)模式下,cache.headDim 必须为偶数

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 wangxun21 的贡献)
Wwangxun21成员
19 天前 创建了 pull request,commit 2a2a09f8
Wwangxun21成员
19 天前 关联了issue:[Bug-Report|缺陷反馈]: indexer_quant_cache MX-FP4(quantMode=3)奇数 cache.headDim 导致精度错误
atomgit-bot
atomgit-bot
19 天前 评论:

变更摘要

该 PR 修复了 indexer_quant_cache 算子在 MX-FP4(quantMode=3)模式下 cache.headDim 为奇数时产生精度错误/数据错位的问题。根本原因是 MX-FP4 每字节打包 2 个 fp4 元素,奇数 headDim 会导致相邻行起始位置交替落在字节高/低半字节,而现有 kernel 仅支持整字节寻址(GlobalTensor<int8_t> + CopyOut),无法表达半字节偏移。修复方案是在 host tiling 阶段 CalcOpTiling 中新增校验,拒绝非法输入并返回 GRAPH_FAILED,将"产出错误数据"变为"直接报错拒绝",与 CANN 内其他 FP4/MX-FP4 打包量化算子的策略保持一致。

主要改动

  • 连续场景 headDim 校验:在 CalcOpTiling 中新增 OP_CHECK_IF,当 quantMode_ == MXFP4_QUANT_MODEcacheLastDim % FP4_PACK_NUM != 0 时,输出错误日志并返回 ge::GRAPH_FAILED,拒绝奇数 headDim 的连续 cache 输入。
  • 分页场景 stride 校验:在分页 view 处理分支中新增 OP_CHECK_IF,要求 cacheRowStride_cacheBlockStride_ 均为偶数(% FP4_PACK_NUM == 0),否则同样打印错误日志并返回 ge::GRAPH_FAILED,防止半字节偏移无法表达。
  • 新增 Host UT 拒绝用例:在 test_indexer_quant_cache_tiling.cpp 中新增 indexer_quant_cache_tiling_mxfp4_odd_headdim_rejected 测试,构造 headDim=129(奇数)的 MX-FP4 输入,验证 tiling 阶段返回 GRAPH_FAILED
  • 文档约束更新:在 aclnnIndexerQuantCache.md 中新增约束说明——MX-FP4(quantMode=3)模式下 cache.headDim 必须为偶数。
likedislike
CANN-robotCANN-robot成员
19 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
19 天前 评论:

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
*/*/docs/acl*.md 陈娇, 杜慧萍 (2/2) 陈娇 (1/1)
attention yang-binrong, songjionghui (2/2) yang-binrong, songjionghui (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
此处折叠了101条消息 查看更多
CANN-robotCANN-robot成员
13 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
13 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
13 天前 添加了label:ci-pipeline-passed
CANN-robotCANN-robot成员
13 天前 关闭了关联的issue
CANN-robotCANN-robot成员
13 天前 合入了pull request