已合并
fix(indexer_quant_cache): reject odd cache headDim for MX-FP4 mode #9613
wangxun21创建于 19 天前
fix(indexer_quant_cache): reject odd cache headDim for MX-FP4 mode #9613
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 wangxun21 的贡献)atomgit-bot
19 天前 评论:
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_MODE且cacheLastDim % 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必须为偶数。


19 天前 添加了label:cann-cla/yes
CANN-robot
19 天前 评论:
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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


此处折叠了101条消息 查看更多
13 天前 添加了label:api-check-pass
13 天前 删除了label:ci-pipeline-running
13 天前 添加了label:ci-pipeline-passed
13 天前 关闭了关联的issue
13 天前 合入了pull request
描述
修复
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_cache对k_head_size/v_head_size的偶数校验、dynamic_mx_quant对input.shape[-1]的偶数要求)保持一致——均选择在 host tiling 阶段拒绝奇数尾轴,而不是尝试支持半字节寻址。关联的Issue
关联 Issue #4137
测试
aclnnIndexerQuantCacheGetWorkspaceSize阶段报错拒绝(ACLNN_ERR_INNER_NULLPTR),plog 确认报错发生在indexer_quant_cache_tiling_arch35.cpp:332,未进入 kernel;后者正常执行,精度 PASS。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的约束说明,新增一条:类型标签