已关闭
[Bug-Report|缺陷反馈] MultiScaleDeformableAttentionGrad 输出形状错误 #6732
KaranocaVe创建于 13 天前关闭于 8 天前
yuning_chen
13 天前 评论:
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 用例。


12 天前 将 wanshilin 设为负责人
yuning_chen
12 天前 评论:
12 天前 评论:
您好,问题已收到,当前 @wanshilin 正在处理中。


8 天前 关闭了 issue
7 天前 添加了label:resolved
[Bug-Report|缺陷反馈] MultiScaleDeformableAttentionGrad 输出形状错误
问题描述
固定源码
cann/ops-nn@ae873b119fb5499c41a6893f920171551fb0a197中,HostInferShape 为
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]。当前 HostInferShape 错误推导为
[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一致。attnWeight的 point 数等于location 第 4 维;输出检查要求
gradAttnWeight与attnWeight同形。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-nnae873b119fb5499c41a6893f920171551fb0a197grad_attention_weights最后一维从 location 第 5 维改为第 4 维;UT 改用合法输入 rank 和匹配的预期输出。结果
[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 检查因本次没有对应文件而跳过。结论
固定源码中的索引与接口 shape 契约不一致;最小修复已形成。轻量检查确认修复索引与合法用例预期相符,完整算子 UT 仍需在具备匹配 CANN Toolkit/OPP 的环境运行。