Closed
[Bug-Report|缺陷反馈] DynamicQuant large-shape copy length overflow #8907
chuboningAdd on  5 days agoClosed at  4 days ago
chuboning
chuboning
5 days ago Create

Describe the current behavior / 问题描述 (Mandatory / 必填)

在 Ascend960DT 环境下,aclnnDynamicQuant 处理 FP16/BF16 输入时,最后一维大于 34816 后会进入 large-shape 路径,输入数据搬入长度发生 16 位截断,导致 per-token scale 计算错误,量化输出也存在错误风险。Ascend950 相同形状下未出现该问题。

Environment Information / 环境信息 (Mandatory / 必填)

  • 昇腾硬件型号:Ascend960DT(__NPU_ARCH__ == 9201);对照平台为 Ascend950。
  • 输入类型:FP16/BF16。
  • 影响路径:common per-token large-shape、per-tensor large-shape;代码检视进一步确认 MOE large-shape、MOE per-tensor large-shape 和 per-token large multicore 存在相同根因。
  • CANN 版本:ops-nn master 中相关 DynamicQuant arch35 实现。

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 在 Ascend960DT 上调用 aclnnDynamicQuant,使用 FP16/BF16 输入,将最后一维设置为大于 34816,例如 34817。
  2. tiling 根据 960 的 UB 容量切换至 large-shape,计算得到的 innerLoopEle 可达到 47744。
  3. CopyInByEle 将 elementNum * sizeof(T) 写入 uint16_t 类型的 DataCopyParams::blockLen。以 34817 个 FP16/BF16 元素为例,期望拷贝 69634 字节,截断后仅为 4098 字节。
  4. 后续仍按原始元素个数计算最大值和 scale,因此使用了未完整搬入的数据。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

各平台的 large-shape 路径均应完整搬入输入及 smooth 数据,正确计算 scale 和量化输出,避免后续芯片因 UB 或分块增大再次触发同类问题。

NA

Special notes for this issue/备注 (Optional / 选填)

修复方案见 PR #14544:全部五条 large-shape 实现路径不再按芯片类型区分,统一使用 DataCopyExtParams 和 DataCopyPadExtParams<T>,以 32 位 blockLen 完成输入及 smooth 拷贝,避免后续芯片继续出现同类问题。

关联 PR:https://gitcode.com/cann/ops-nn/merge_requests/14544

likedislike
chuboningchuboning
5 days ago Change title to "[Ascend960] DynamicQuant large-shape copy length overflow", originally titled "[Ascend960] DynamicQuant large-shape 输入拷贝长度溢出导致结果错误".
chuboningchuboning
5 days ago Modify description of issue
chuboningchuboning
5 days ago Associated pull request
chuboningchuboning
5 days ago Modify description of issue
chuboningchuboning
5 days ago Change title to "[Bug-Report|缺陷反馈] DynamicQuant large-shape copy length overflow", originally titled "[Ascend960] DynamicQuant large-shape copy length overflow".
chuboningchuboning
5 days ago Modify description of issue
yuning_chenyuning_chenCollaborators
5 days ago Assign chuboning as responsible person
chuboningchuboning
5 days ago Modify description of issue
yuning_chen
yuning_chenCollaborators
5 days ago Comments:

收到。DynamicQuant 大 shape 下 copy length 溢出,典型是 uint32/int32 长度字段在高元素数时溢出(numel 超过 2^31 或 4G 边界)。建议:①长度计算统一用 int64,并在 tiling 阶段校验 numel 上限;②补大 shape UT(临界 2^31 元素);③同族 *Quant 算子一并核对长度字段类型。

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Close issue
CANN-robotCANN-robotCollaborators
4 days ago changed custom state from 待办的 to 已完成
CANN-robotCANN-robotCollaborators
4 days ago Added label: resolved