已合并
fix: route internal-format copy_ to native path and guard NPUStorageDesc access #44450
wuyouqi1创建于 10 天前
fix: route internal-format copy_ to native path and guard NPUStorageDesc access #44450
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 wuyouqi1 的贡献)ascend-robot
10 天前 评论:
10 天前 评论:
atomgit-bot
10 天前 评论:
10 天前 评论:
变更摘要
此PR是一个编排类(chore)变更,主要针对 NPUNativeOpApiFunctions::copy_ 进行两项调整:一是为 A2/A3 芯片增加回退分支,使其走 native copy_ 路径而非 op_api 路径;二是回退此前 D2H(设备到主机)拷贝场景中的 NZ→ND 格式转换保护,简化拷贝逻辑。此外附带一个测试文件的空白行格式微调。
主要改动
- A2/A3 回退分支:在
NPUNativeOpApiFunctions::copy_入口处新增c10_npu::IsAclnnOnly()判断,非纯 ACLNN 模式(A2/A3)直接调用NPUNativeFunctions::copy_回退至 native 实现,仅 A5 继续走 op_api 路径 - 回退 D2H 格式保护:删除
copy_中 D2H 路径的 NZ→ND 格式转换逻辑(原先通过FormatHelper::IsBaseFormatType判断并使用FormatCastHelper::ApplyBaseFormatTensorBy做显式格式转换),改为直接将原始src传入copy_d2h_baseformat_opapi - 测试文件格式微调:在
test/distributed/test_send_recv.py中新增一个空行,无功能影响


atomgit-bot
10 天前 评论:
10 天前 评论:
10 天前 添加了label:ascend-cla/yes
此处折叠了287条消息 查看更多
5 天前 添加了label:approvedlgtm
5 天前 合入了pull request
ascend-robot
5 天前 评论:
5 天前 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
5 天前 评论:
5 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14098 [ commitID:5e4a4aa6 ] 已完成


【合入来源】
关联 issue:https://gitcode.com/Ascend/pytorch/issues/2629
【修改方案】
前置pr为:https://gitcode.com/Ascend/pytorch/pull/40289 实现了修改点中的第一点。
本pr为以下修改点的第二点和第三点:
一、Ascend950 NZ 序列化 / D2H / 打印支持
copy_增加internal_format_opapi: True,内部格式 tensor 进入 op_api 路径;__repr__补丁:先.cpu()触发 d2h + 格式转换再打印。二、copy_ 内部格式路由修复
aclnnInplaceCopy 按 base format 布局写入,会损坏内部格式存储,在
copy_入口按平台分流:copy_(原生路径自行处理格式转换),base format 保持 aclnn 路径;实现细节:入口使用
IsOpInputBaseFormat判断(legacy 加载的 from_blob tensor 视作 base format、不读 desc,legacy load 恢复可用);d2h 分支保留IsBaseFormatType(legacy 保存命中第三部分拦截并抛异常)。三、GetNpuStorageImplDesc 异常值拦截
legacy 序列化的
_write_file/_set_from_file使用at::from_blob产生 plainc10::StorageImpltensor,读取 desc 越界("unknown format type:<垃圾值>")。GetNpuStorageImplDesc增加动态类型检查(typeid== NPUStorageImpl),不满足时抛清晰异常:legacy 序列化保存 NPU tensor 不支持,请改用新版 zipfile 序列化。【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
新增用例:
test/npu/test_serialization_format.py:TestCopyFormat(A2/A3:6 格式 × h2d/d2h + 6×6 d2d 全组合);TestCopyFormatAscend950(A5:base 对照、NZ d2h 遍历 fp16/bf16/i8/i32、NZ h2d/d2d 断言报错)修复前 → 修复后:
验证结果:
【CheckList】