Closed
QuantAllReduce 返回 shape 文档错误 #6277
KaranocaVeAdd on  Oct 19Closed at  9 days ago
KaranocaVe
KaranocaVe
Oct 19 Create

QuantAllReduce 返回 shape 文档错误

问题

固定源码提交 0f1cf7d13da8f8be942b746759dd317d1ebb83ec 的 mc2/quant_all_reduce/docs/torchapi_quant_all_reduce.md 将输出 y 的 shape 写为 (b*s/world_size, h)。实现保留输入 x 的 shape 和 rank,world_size 不会在输出 shape 推导中缩小维度。

证据

  • 文档第 93 行把输出 shape 写成 (b*s/world_size, h);同一文档第 71 行则规定 x 可为二维 (bs,h) 或三维 (b,s,h)。
  • mc2/quant_all_reduce/op_host/quant_all_reduce_infershape.cpp:125-134 将输出 rank 设为输入 x 的 rank,并按二维或三维分支复制 x 的对应维度。
  • mc2/quant_all_reduce/tests/ut/op_host/test_quant_all_reduce_infershape.cpp:42-57 验证二维 x=[1024,5120]、world_size=8 时输出仍为 [1024,5120];同文件第 186-201 行验证三维 x=[8,128,5120] 时输出仍为 [8,128,5120]。
  • mc2/quant_all_reduce/torch_extension/quant_all_reduce.py:109-116 的 Torch Meta 实现使用 torch.empty(x.size()) 创建输出。

预期与实际

例如二维输入 x=[8,5120]、world_size=2,文档会使调用方推断输出为 [4,5120];当前 InferShape 和 Torch Meta 推导出的输出为 [8,5120]。三维输入也保留 (b,s,h) rank 和各维大小。

影响与修复

输出 shape 说明会让调用方误以为 QuantAllReduce 按 world_size 缩小 batch,并可能错误安排后续 shape 处理。修复仅需将 Torch API 文档的返回值说明改为:输出 shape 与输入 x 相同,二维输入对应 (bs,h),三维输入对应 (b,s,h)。

English summary

The Torch API documentation says that QuantAllReduce returns shape (b*s/world_size, h), while the implementation preserves the input x rank and dimensions. InferShape UTs cover both 2D and 3D inputs and expect the output shape to match x; the Torch Meta implementation also creates the output with x.size(). Update the documented return shape to match the input shape.

验证

  • 修复 hunk 上下文通过 git apply --check,report、validation、upstream-pr 三份材料通过 git diff --check。未运行构建或 UT;改动仅为文档。

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

likedislike
KaranocaVeKaranocaVe
Oct 19 Associated pull request
游震
游震Collaborators
Oct 19 Comments:

/assign @KaranocaVe

likedislike
CANN-robotCANN-robotCollaborators
Oct 19 Assign KaranocaVe as responsible person
KaranocaVeKaranocaVe
Oct 19 Modify description of issue
CANN-robotCANN-robotCollaborators
9 days ago Close issue
CANN-robotCANN-robotCollaborators
9 days ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
9 days ago Added label: resolved