已关闭
[Bug-Report|缺陷反馈]: dynamic_quant_v2示例代码groupIndex数据构造错误且group资源未释放 #5571
cuijie创建于  4 天前关闭于  4 天前
cuijie成员
4 天前 创建

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

aclnnDynamicQuantV2 算子的示例代码 quant/dynamic_quant_v2/examples/test_aclnn_dynamic_quant_v2.cpp 存在两处缺陷:

  1. groupIndex 数据构造错误groupHostData = {2, rowNum} 仅 2 个元素,而 groupShape = {groupNum}(4 个元素),CreateAclTensor 按 shape 大小(16 字节)执行 aclrtMemcpy H2D 拷贝,对仅 8 字节的 host 向量越界读。同时语义错误:group_index 应为各专家负责的累计行数(递增,末值等于 x 总行数,见算子 README 约束),{2, 4} 既非递增累计值也不满足末值约束。
  2. group 资源泄漏:示例结束时释放了其余 5 个 tensor,但遗漏了 aclDestroyTensor(group)aclrtFree(groupDeviceAddr)

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

缺陷位于示例代码与文档层面,代码审查阶段发现,与具体硬件型号无关;文档标注该算子支持 Ascend 950PR/950DT、Atlas A3、Atlas A2、Atlas 推理/训练系列产品。

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

  1. 打开 quant/dynamic_quant_v2/examples/test_aclnn_dynamic_quant_v2.cpp(master 分支 7e2f34e5e 版本),定位 main() 中 std::vector<int32_t> groupHostData = {2, rowNum};
  2. 对照 groupShape = {groupNum}(4 元素)与 CreateAclTensorGetShapeSize(shape) * sizeof(T) 的 memcpy 拷贝字节数;
  3. 检查步骤 6/7 的资源释放列表,group tensor 缺失。

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

  1. groupHostData 元素个数与 groupShape 一致,取值为各专家累计行数(如 {1, 2, 3, rowNum}),末值等于 x 总行数;
  2. 所有创建的 aclTensor 与 device 内存均正确释放,无泄漏。

修复 diff 见关联 PR:https://gitcode.com/cann/ops-nn/pulls/9883(涉及 2 个文件:example cpp 与 docs 内嵌示例同步)。

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

关联修复 PR:https://gitcode.com/cann/ops-nn/pulls/9883

likedislike
Ccuijie成员
4 天前 添加了label:bug-report
Ccuijie成员
4 天前 将 cuijie25 设为负责人
CANN-robotCANN-robot成员
4 天前 关闭了 issue
CANN-robotCANN-robot成员
3 天前 添加了label:resolved