已合并
feat: adapt FRACTAL_NZ D2H/printing and serialization UT for Ascend950 #44315
feat: adapt FRACTAL_NZ D2H/printing and serialization UT for Ascend950 #44315
已合并
wuyouqi1创建于 8 天前
wuyouqi1
wuyouqi1成员
8 天前

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

【修改方案】

同步 #2629(A5/Ascend950 上 FRACTAL_NZ 私有格式 tensor 的 D2H、打印、序列化适配)至本分支,与 v2.7.1 实现(MR !40289)保持一致。本 PR 内容:

  1. torch_npu/utils/tensor_methods.py:新增 _add_repr_patch()。私有格式(FRACTAL_NZ 系列)tensor 在 Tensor.__repr__ 中会命中 _tensor_str 内部格式守卫(cat/stack),导致打印/D2H 失败;patch 在私有格式时先 .cpu() 触发 D2H + format cast,再走原 __repr__。在 _add_tensor_methods() 末尾注册。
  2. torch_npu/csrc/aten/common/FormatCastKernelNpu.cppIsAclnnOnly() 路径下,未显式指定 customize_dtype 时,对 element_size() >= 4 的类型(fp32/int32)将 customizeAcltype 默认置为 ACL_FLOAT16(C0=16),与 aclop 路径的历史行为对齐。
  3. test/npu/test_serialization_format.py:新增 Ascend950 专属用例 TestSerializationFormatAscend950(受 @unittest.skipUnless(IS_ASCEND950, ...) 门控),覆盖 ND save/load、按 dtype 的 FRACTAL_NZ round-trip、NZ tensor D2H/repr/print;原 TestSerializationFormat 在 Ascend950 上跳过。

说明:本分支不含 v2.7.1 MR !40289 中的 __reduce_ex__ 序列化 patch(该 patch 在本分支不需要)。如该 patch 后续需要,将另行评估。

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

测试场景:

  • A2/A3(非 Ascend950):TestSerializationFormat 原用例照常执行,TestSerializationFormatAscend950skipUnless(IS_ASCEND950) 跳过。
  • A5/Ascend950:TestSerializationFormat 跳过,执行 TestSerializationFormatAscend950:fp16/bf16/int8/int32/int64 的 FRACTAL_NZ save/load round-trip 与 D2H/repr/print。

运行方式:python test/npu/test_serialization_format.py -v

新增/变更内容已适配 UT 用例(test_serialization_format.py)。本 PR 为跨版本同步,代码已验证在各目标分支干净 apply、无遗留依赖(不含 _reduce_ex__);具体执行结果以本分支 CI 流水线为准。

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

  • 代码注释完备,正确记录错误日志
  • 代码实现进行了返回值、空指针等校验
  • PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
  • PR持续集成流水线(CI)执行通过,代码检查无异常

Fixes #2629
https://gitcode.com/Ascend/pytorch/issues/2629

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 wuyouqi1 的贡献)
wuyouqi1wuyouqi1成员
8 天前 创建了 pull request,commit 40c172cd
wuyouqi1wuyouqi1成员
8 天前 关联了issue:[Feature]: Enable D2H, printing, and serialization for FRACTAL_NZ private-format tensors on Ascend950
ascend-robot
ascend-robot成员
8 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
8 天前 添加了label:docs-ci-pipeline-running
wuyouqi1wuyouqi1成员
8 天前 修改了pull request 的描述
此处折叠了176条消息 查看更多
ascend-robotascend-robot成员
1 天前 添加了label:approved
xuyun15成员
1 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
1 天前 添加了label:lgtm
ascend-robotascend-robot成员
1 天前 合入了pull request
ascend-robot
ascend-robot成员
1 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14113 [ commitID:d642d977 ] 已完成
likedislike