Closed
QuantAllReduce 返回 shape 文档错误 #6277
KaranocaVeAdd on Oct 19Closed at 9 days ago
Oct 19 Associated pull request
游震
Oct 19 Comments:
Oct 19 Comments:
/assign @KaranocaVe


Oct 19 Assign KaranocaVe as responsible person
Oct 19 Modify description of issue
9 days ago Close issue
9 days ago changed custom state from 进行中 to 已完成
9 days ago Added label: resolved
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 推导中缩小维度。证据
(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 inputxrank and dimensions. InferShape UTs cover both 2D and 3D inputs and expect the output shape to matchx; the Torch Meta implementation also creates the output withx.size(). Update the documented return shape to match the input shape.验证
git apply --check,report、validation、upstream-pr 三份材料通过git diff --check。未运行构建或 UT;改动仅为文档。关联 PR: https://gitcode.com/cann/ops-transformer/merge_requests/14048