Closed
[Bug-Report|缺陷反馈]: MoeTokenUnpermuteWithEpGrad InferShape 将动态维窄化为超大正数 #5805
KaranocaVeAdd on  Oct 5Closed at  1 day ago
KaranocaVe
KaranocaVe
Oct 5 Create

[Bug-Report|缺陷反馈]: MoeTokenUnpermuteWithEpGrad InferShape 将动态维窄化为超大正数

问题描述

MoeTokenUnpermuteWithEpGrad 的 Host InferShape 将 shape getter 返回的有符号维度存入 uint32_t。动态维 -1 因此变成 4294967295,使输出 shape 错误。该算子已声明支持动态 shape。

重现

使用动态 token 维 [-1, 64] 和动态 sortedIndices 长度 -1 调用 Host InferShape。输出第 0 维实际为 4294967295,而应为 -1。动态 hidden 维也覆盖同一窄化路径。

影响

错误的输出描述会破坏动态图构建时的 shape 传播。本问题的复现和验证范围是 Host InferShape。

修复与验证

将两个输出维度暂存变量改为 int64_t,并增加动态 token 维和 hidden 维回归用例。修复后 Host tiling 与 InferShape 定向测试 34/34 通过。

关联 PR: https://gitcode.com/cann/ops-transformer/merge_requests/13339

likedislike
KaranocaVeKaranocaVe
Oct 5 Associated pull request
weihao18
weihao18Collaborators
Oct 5 Comments:

/assign @KaranocaVe

likedislike
CANN-robotCANN-robotCollaborators
Oct 5 Assign KaranocaVe as responsible person
KaranocaVeKaranocaVe
Oct 5 Modify description of issue
周云飞
周云飞Collaborators
Oct 17 Comments:

感谢提供清晰的复现条件和修复建议。

问题分析

该类型转换确实会丢失动态维信息。InferShape 中的两处赋值分别将 rowIdMapShape 的第 0 维和 unpermutedOutputDShape 的第 1 维存入 uint32_t 变量 inputGradDim0、hiddenSize。当维度值为 -1 时,转换结果为 4294967295,不再保留“维度未知”的含义。这与您报告的输出第 0 维异常一致,动态 hidden 维也存在同样的转换问题。

处理方向

将这两个暂存变量改为 int64_t 是合理的修复方向,可以保留动态维的 -1,同时避免对有符号维度值进行无符号窄化。回归用例应分别覆盖动态 token 维和动态 hidden 维,确认输出对应维度仍为 -1,并保持静态维度推导行为不变。

您提供了关联 PR #13339,并报告 Host tiling 与 InferShape 定向测试 34/34 通过。目前尚未核实该 PR 的具体改动和合入状态;上述测试结果按本次报告记录,不能据此推断设备侧动态 shape 执行已得到验证。

likedislike
周云飞周云飞Collaborators
2 days ago Assign liuguoyue、Larry_liuyi、azyuli as responsible person
Yuan BinYuan BinCollaborators
1 day ago Assign aaaakai as responsible person
Yuan BinYuan BinCollaborators
1 day ago Associated pull request
Yuan BinYuan BinCollaborators
1 day ago changed custom state from 进行中 to 已解决
Yuan BinYuan BinCollaborators
1 day ago Close issue
周云飞
周云飞Collaborators
1 day ago Comments:

PR #17544 已合入:将 MoeTokenUnpermuteWithEpGrad InferShape 中传给 SetDim 的两个维度变量从 uint32_t 改为 int64_t,使表示未知维度的 -1 能正确传递,避免被转换为超大正数。PR 描述称已进行本地泛化测试。

关联 PR:PR #17544

likedislike