已关闭
[Bug-Report|缺陷反馈] MultiScaleDeformableAttentionGrad 输出形状错误 #6732
KaranocaVe创建于  13 天前关闭于  8 天前
KaranocaVe
KaranocaVe
13 天前 创建

[Bug-Report|缺陷反馈] MultiScaleDeformableAttentionGrad 输出形状错误

问题描述

固定源码 cann/ops-nn@ae873b119fb5499c41a6893f920171551fb0a197 中,Host
InferShape 为 grad_attention_weights 生成最后一维时,读取了
sampling_locations 的第 5 维。该维表示坐标分量,接口约束其长度为 2;最后一维应取
sampling_locations 第 4 维的 num_points。

例如 sampling_locations=[1,3,2,4,5,2]、attention_weights=[1,3,2,4,5] 时,公开契约要求
grad_attention_weights 与 attention_weights 同形,应为 [1,3,2,4,5]。当前 Host
InferShape 错误推导为 [1,3,2,4,2],当 num_points != 2 时输出形状错误。

证据

  • vfusion/multi_scale_deformable_attention_grad/op_host/multi_scale_deformable_attention_grad_infershape.cpp
    将 samplingLocationsShape->GetDim(5) 作为梯度 attention weights 的最后一维。
  • 同算子文档规定 location 形状为
    (bs,num_queries,num_heads,num_levels,num_points,2),gradAttnWeight 形状与
    attnWeight 一致。
  • ACLNN 参数检查要求 location 最后一维为 2,并验证 attnWeight 的 point 数等于
    location 第 4 维;输出检查要求 gradAttnWeight 与 attnWeight 同形。
  • 原 Host InferShape UT 使用不符合公开 rank 约束的输入,并将 location 的第 5 维写进
    expected attention-gradient shape,未覆盖该契约。

修复建议

推导梯度 attention weights 最后一维时改用 location 的第 4 维,并将 Host InferShape
UT 输入改为满足各输入 rank 的合法形状,明确检查梯度输出与 attention weights 同形。

相关工作

Issue #6658 / PR !11919 补充输入 rank 与 unknown-rank 处理;其当前 diff 未修正有效 rank 输入下
将 GetDim(5) 用作 num_points 的问题。

Validation

验证记录

固定对象

  • 仓库:cann/ops-nn
  • 源码 commit:ae873b119fb5499c41a6893f920171551fb0a197
  • 修改:Host InferShape 将 grad_attention_weights 最后一维从 location 第 5 维改为第 4 维;UT 改用合法输入 rank 和匹配的预期输出。

结果

  • 编译并运行独立 C++ shape 检查,输入 location [1,3,2,4,5,2],断言推导结果为 [1,3,2,4,5]:通过。
  • 源码断言检查修复索引为 GetDim(4),UT 覆盖上述合法 rank 输入和 [1,3,2,4,5] 预期:通过。
  • git diff --check:通过。
  • 在当前上游 master 基线应用修复后,对两个改动的 C++ 文件运行目标仓库定向 pre-commit:通过(含 clang-format、codespell 和 OAT);Python、YAML、JSON 检查因本次没有对应文件而跳过。
  • 未运行仓库 InferShape UT 或 CANN 集成构建:当前机器只有 Ascend driver,没有 CANN Toolkit/OPP 开发头文件及库,无法完成该构建。

结论

固定源码中的索引与接口 shape 契约不一致;最小修复已形成。轻量检查确认修复索引与合法用例预期相符,完整算子 UT 仍需在具备匹配 CANN Toolkit/OPP 的环境运行。

likedislike
yuning_chen
yuning_chen成员
13 天前 评论:

初步分析

感谢反馈。

现象理解:MultiScaleDeformableAttentionGrad 的 Host InferShape 用 sampling_locations 的第 5 维作为 grad_attention_weights 的最后一维。该维是长度为 2 的坐标分量,点数应取第 4 维。num_points 不是 2 时,梯度 shape 会和 attention_weights 不一致。

当前判断:初步判断,待复现确认。需要用 location 为 [1,3,2,4,5,2]、attention_weights 为 [1,3,2,4,5] 看推导结果是不是 [1,3,2,4,2]。

涉及范围:multi_scale_deformable_attention_grad 的 Host InferShape。

下一步:确认索引后,最后一维改用 location 的第 4 维,并用满足 rank 约束的输入补 InferShape 用例。

likedislike
yuning_chenyuning_chen成员
12 天前 将 wanshilin 设为负责人
yuning_chen
yuning_chen成员
12 天前 评论:

您好,问题已收到,当前 @wanshilin 正在处理中。

likedislike
万万世林成员
9 天前 关联了pull request:更新文档
CANN-robotCANN-robot成员
8 天前 关闭了 issue
CANN-robotCANN-robot成员
7 天前 添加了label:resolved