Merged
修改aclnnstack golden #6240
zhanglei842Add on Oct 12
修改aclnnstack golden #6240
Merged
Merged fromzhanglei842/ops-math_packmasterintocann/ops-mathmaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for zhanglei842's contribution.)Oct 12 Created pull request, commit a21eb4c7
atomgit-bot
Oct 12 Comments:
Oct 12 Comments:
变更摘要
本 PR 重写 conversion/pack/tests/assets/golden.py 中的 pack 算子 golden 定义:明确 pack 为纯数据搬运算子(kernel 等价 torch.stack,输出逐 bit 拷贝),统一以 binary_equal 作为精度标准、取消冗余的 third_party 声明,并将 aclnnStack、pack、torch.stack 三条通路分别封装为 TestSpec 格式的 spec 类与 __spec__ 注册表,同时补全按 dtype 分发的 golden 计算逻辑与通路支持说明。
主要改动
- 引入规范注册与精度标准:新增
__spec__映射(pack/aclnnStack/torch.stack对应各TestSpec类)和_BINARY_TOLERANCE,将全部 dtype 统一声明为binary_equal精度标准,__golden__中的aclnn与kernel映射同步格式化。 - 重构
pack_golden通路逻辑:改为对标torch.stack,对 fp8/bf16 等扩展 dtype(_NUMPY_ONLY_DTYPES)走np.stack、对complex32(float16 + 尾维 [2] 存储)做负 axis 归一化后np.stack,其余情况经torch.from_numpy计算,并统一返回列表形式结果。 - 新增 aclnn 侧 dtype 提升与转换工具:增加
_cann_promote(复刻 CANNPromoteType提升规则)、_resolve_np_dtype、_np_value_cast、_stack_output_dtype以及_ACLNN_TORCH_DTYPES映射,用于复现算子 cast 链与输出 dtype 转换。 - 重写
aclnn_stack_golden:按输入是否为numpy.ndarray分派,同 dtype 场景以uint8载体张量做逐字节 stack,异 dtype 场景按promote→np.stack→输出 dtype 转换,torch 输入场景在 stack 后按声明输出 dtype 调to。 - 新增 e2e 侧
stack_torch_golden与 spec 类:新增PackTestSpec、AclnnStackTestSpec、StackTorchTestSpec,并为 framework-api 通路增加stack_torch_golden(torch 输入直通torch.stack,numpy 输入同 dtype 走位搬运并 view 为uint8,混合 dtype 抛NotImplementedError)。
🧩 本次 Review 已使用自定义 Skill:


Incorrect?
atomgit-bot
Oct 12 Comments:
Oct 12 Comments:


Incorrect?
Oct 12 Added label: cann-cla/yes
CANN-robot
Oct 12 Comments:
Oct 12 Comments:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| conversion/pack | ✅ 汤平川, zhanw_coding (2/2) | ✅ zhanw_coding, 汤平川 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zhanglei842, thanks for your pull request. All authors of the commits have signed the CLA. 👍


41 messages are collapsed here。 See more
15 days ago Added label: ci-pipeline-running
15 days ago Removed label: ci-pipeline-running
15 days ago Added label: ci-pipeline-passed
15 days ago Closed associated issue
15 days ago Merged pull request
描述
pack 是纯数据搬运算子(kernel
Pack语义等价torch.stack),输出为输入按 axis 拼接的逐 bit 拷贝。现有测试 golden(conversion/pack/tests/assets/golden.py)存在以下不足:aclnn_stack_golden仅执行torch.stack(tensors, dim),未建模aclnnStack(op_api/aclnn_stack.cpp)的实际执行链——输入 cast 到 promoteType 后打包、输出侧再 cast 到输出 dtype,混合 dtype 用例的 golden 与设备行为不一致;float8_e5m2/float8_e4m3fn/hifloat8/bfloat16等以 ml_dtypes/en_dtypes 扩展 numpy dtype 到达 golden 的输入,torch.from_numpy不识别,旧 golden 无处理路径;complex32以 float16 + 尾维 [2](real/imag 交错)存储,负 axis 须归一化到尾维之前,旧 golden 未处理;torch.stack)通路 golden。关联的Issue
https://gitcode.com/cann/ops-math/issues/3687
测试
通过ttk验证了直调、geir、ete模式的调用验证,golden结果和npu,竞品相同
文档更新
类型标签