Closed
omitted range disables every gradient copy #8068
MetastarxAdd on  9 days agoClosed at  3 days ago
Metastarx
Metastarx
9 days ago Create

The call path Tiling4MoeTokenPermuteWithEpGrad (line 438) -> PermuteWithEpGradTilingCompute (line 405) -> Init (line 177) sets param.input.start and param.input.end both to 0 when rangeOptional is absent (lines 214-216). SetTilingData stores those values at lines 344-350. The kernel then only reads input data when an index satisfies start <= index < end: CalPartOutToken checks this at lines 287-301, and CopyProbIn performs the same check at lines 443-463. With the normal non-negative sorted_indices values, no index can satisfy index >= 0 && index < 0, so the token path duplicates zero and writes it at CopyOut (line 326), while the probability path also produces zero. Valid calls that omit rangeOptional therefore return zero gradients instead of processing the full sorted_indices range.

likedislike
周云飞
周云飞Collaborators
9 days ago Comments:

按您描述的调用路径,省略 rangeOptional 后范围变成 [0, 0),确实没有索引能通过范围检查,可能导致 token 和概率梯度均为零。相关算子实现和省略范围时的预期语义仍需确认。

一个可行的处理方向是在 Init 中为未提供范围的情况设置覆盖有效索引的默认范围,同时保留显式传入范围时的行为;具体上界需结合索引含义和输入形状确认。我们会继续分析这一问题。

likedislike
周云飞周云飞Collaborators
4 days ago Assign yu-xinjie62、liuguoyue、azyuli as responsible person
周云飞周云飞Collaborators
4 days ago Removed responsible person yu-xinjie62
azyuliazyuliCollaborators
3 days ago Associated pull request
azyuli
azyuliCollaborators
3 days ago Comments:

Thanks for reporting this!

  1. For direct op/tiling calls where the range attribute is absent (rangePtr == nullptr), PR !15613 (commit 36d2c8261) already updated the else branch in Init() to fall back to [0, sorted_indices.dim(0)).
  2. For aclnnMoeTokenPermuteWithEpGrad calls, moe_token_permute_with_ep_grad_def.cpp defines Attr("range").AttrType(OPTIONAL).ListInt({0, 0}), so passing rangeOptional = nullptr passes [0, 0] (an empty interval [0, 0)) by default, producing all-zero gradients without ignoring probs, and an empty length-0 array is rejected.
  3. To keep the interface documentation consistent with this behavior, we have submitted PR !17196 updating aclnnMoeTokenPermuteWithEpGrad.md, aclnnMoeTokenPermuteWithEpGrad_en.md, README.md, and README_en.md to explicitly document the [0, 0] default for nullptr in aclnn calls and recommend passing [0, sortedIndices.numel] explicitly (or calling aclnnMoeTokenPermuteGrad) when the full range is needed.
likedislike
CANN-robotCANN-robotCollaborators
3 days ago Close issue
CANN-robotCANN-robotCollaborators
3 days ago changed custom state from 待办的 to 已完成
周云飞
周云飞Collaborators
3 days ago Comments:

PR #17196 更新了 aclnnMoeTokenPermuteWithEpGrad 的中英文接口文档和 README,明确:

  • rangeOptional 仅支持长度为 2 的整型数组,不支持空数组。
  • 传入空指针时默认范围为 [0, 0),梯度输出全 0,且不会忽略概率梯度相关参数。
  • 如需处理全量 sortedIndices,应显式传入 [0, sortedIndices.numel],或使用 aclnnMoeTokenPermuteGrad。

本次是文档说明修正,未修改算子代码或改变默认行为。

关联 PR:PR #17196

likedislike
CANN-robotCANN-robotCollaborators
2 days ago Added label: resolved