Pull Request has been successfully merged by CANN-robot.
(Thank you for anakinSkywalker's contribution.)变更摘要
本 PR 为 FIA(Fused Infer Attention)伪量化(anti-quant)场景的 PA(Page Attention)路径增加对 kv 及 kv_scale(dequant scale)张量在 0 轴/1 轴非连续(stride 非默认)布局的支持。整体改动分三层:Host 侧在 tiling 阶段把 key/value 及 k/v descale 的 bnStride/n2Stride 通过 kScaleStrides、vScaleStrides 等新字段下发,并新增 CheckStrideForAntiquant 校验器限定非连续仅允许出现在 0/1 维(BBH 布局仅限 0 维);内核侧在 RunInfo、CVSharedParams、AntiquantTaskParamBaseAPI 与 ConstInfo 中传递这些 stride,并在 CopyKV、CopyKVPageAttention、LoadAntiquant 以及 key/value 核心偏移计算中按非零 stride 动态计算地址,实现 PA 场景下 key、value 与 scale 的 0/1 轴非连续读取。
主要改动
-
新增 stride 下发字段与接口:
flash_attention_score_tiling_regbase_arch35.h为MultiCoreParamsRegbase增加kScaleStrides、vScaleStrides字段及set_/get_方法,util_regbase.h在RunInfo宏与CVSharedParams<true, true>中新增kScaleBnStride、kScaleN2Stride、vScaleBnStride、vScaleN2Stride,用于承载非连续 scale 的 stride 信息。 -
Host 侧 tiling 与合法性校验:
fused_infer_attention_score_tiling_impl.cpp的SetFATilingData将fiaInfo.kScaleStrides/vScaleStrides的 stride 写入inputParams;dequant_checker.cpp新增CheckStrideForAntiquant并接入伪量化特征校验链,非 PA 场景要求 key/value/descale 连续,PA 场景仅允许 0/1 维非连续(BBH 仅允许 0 维),否则报错拒绝。 -
内核参数透传:
flash_attention_score_antiquant_kernel.h将keyStrides、valueStrides、kScaleStrides、vScaleStrides的bnStride/n2Stride写入constInfo;flash_attention_score_antiquant_block_vec.h的SetAntiqParamCommon增加isKey参数以区分 key/value 各自的 kv 与 scale stride,并在scaleN2Stride非 0 时用其计算antiqParamOffset。 -
非连续寻址计算:
flash_attention_score_antiquant_processor.h的AntiquantTaskParamBaseAPI新增kvBnStride、kvN2Stride、scaleBnStride、scaleN2Stride;LoadAntiquant的 scale 偏移与CopyKV/CopyKVPageAttention在 NZ/BBH/BNBD 布局下按自定义 stride 计算headStride、blockStride、batchStride,CopyKV增加kvN2Stride参数以支持非连续的 head 间步长。 -
key/value 核心偏移拆分:
infer_flash_attention_kvcache_fused_infer.h的GetKeyCoreOffsetParam、CalcValueCoreOffsetBSH/TND/BNSD在对应 stride 非 0 时改用自定义headStride/batchStride,并在SyncKeyCoreOffset、ComputeOffsetNonPrefixAIC、ComputeOffsetForAntiquant中依据 stride 是否非 0(或dSize != dSizeV)拆分keyOffset与valueOffset分别计算。


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 | ✅ 王永光, 刘丹 (2/2) | ✅ 王永光 (1/1) |
| attention | ✅ shen_weiling, 刘丹, shasha_an (3/2) | ✅ 刘丹, shasha_an (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Junren6415, 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.


描述
推理场景(FusedInferAttentionScore)的伪量化 PA(PageAttention)目前要求 KV cache 及其反量化参数必须以连续布局传入。实际部署中,KV cache 是多轮写入的长驻tensor,随着预算调度、显存整理,用户侧很容易拿到带 padding 的非连续视图;反量化 scale/offset 也常是同一块物理内存上切出来的非连续切片。此前这些非连续输入要么被框架强制拷贝成连续(多一次全量数据搬运),要么直接不可用,与长 cache、大 batch 的推理成本诉求相悖。
本 PR 让 FIA 伪量化 PA 场景接受非连续输入,用户传入的 stride 会被完整保留并送达到 kernel 侧用于寻址,免除强制连续化带来的拷贝:
其中 INT4 以 INT32 打包存储,口径转换阶段 stride 会被重算成连续值导致非连续信息丢失,本 PR 一并修复,保证 INT4 的非连续 stride 与 shape 同口径送达。
关联的Issue
关联 issue #4720
测试
文档更新
无
类型标签