已合并
fix: fix from blob bug #33191
luochao60创建于 4月7日
fix: fix from blob bug #33191
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 luochao60 的贡献)ascend-robot
4月7日 评论:
4月7日 评论:
ascend-robot
4月7日 评论:
4月7日 评论:
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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/pytorch | ✅ liujunzhu, chujinjin (2/2) | ✅ liujunzhu (1/1) |
| test | ✅ liujunzhu, chujinjin (2/2) | ✅ liujunzhu (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
luochao60, thanks for your pull request. All authors of the commits have signed the CLA. 👍


4月7日 添加了label:ascend-cla/yes
4月9日 添加了label:ci-pipeline-failed
4月9日 删除了label:ci-pipeline-failed
4月9日 添加了label:ci-pipeline-running
4月9日 删除了label:ci-pipeline-running
4月9日 添加了label:ci-pipeline-passed
ascend-robot
4月9日 评论:
4月9日 评论:
流水线 PR-pipeline_pytorch#14815 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| Build_ARM_inductor | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | ✅ | >>> |
| UT_X86_Part_02 | ✅ | >>> | |
| UT_ARM_A3_Part_01 | ✅ | >>> | |
| UT_ARM_A3_Part_02 | ✅ | >>> | |
| UT_DIST_X86_Part_01 | 🛑 | >>> | |
| UT_DIST_X86_Part_02 | 🛑 | >>> | |
| UT_DIST_X86_Part_03 | 🛑 | >>> | |
| UT_DIST_X86_Part_04 | 🛑 | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


liujunzhu
4月14日 评论:
4月14日 评论:
/approve


4月14日 添加了label:approved
4月14日 添加了label:lgtm
ascend-robot
4月14日 评论:
4月14日 评论:
4月14日 合入了pull request
【合入来源】
【修改方案】
修复
torch_npu/csrc/aten/common/from_blob.cpp中TensorMaker::computeStorageSize()计算 storage size 时对storage_offset_的处理 bug:原代码将storage_offset_(按元素数计)直接累加到字节大小上,缺少* itemsize,导致非 float32 类型或带偏移的 tensor 计算出的 storage size 偏小,from_blob 创建的 tensor storage 不足。修复后两处分支均改为storage_size += storage_offset_.value() * itemsize;。修复
torch_npu/csrc/npu/Module.cpp中_weak_ref_tensor实现:原实现通过t.data_ptr()+t.sizes()+t.strides()调用from_blob构造新 tensor,丢失了原 tensor 的storage_offset信息,且当原 tensor 是 view(带 offset 或非平凡 stride)时,新 tensor 的 storage 会被错误地按视图形状重新计算,与原 storage 不一致。修复方式:基于原 tensor 的完整storage().mutable_data()与storage().nbytes() / element_size()调用from_blob构造新 tensor(覆盖完整 storage),随后通过set_sizes_and_strides与set_storage_offset还原原 tensor 的视图信息,确保弱引用 tensor 的 storage、sizes、strides、offset 与原 tensor 完全一致。测试用例重构与新增:
test/cpp_extensions/extension.cpp中的 from_blob 相关测试(check_from_blob/check_from_blob_strides/check_from_blob_delete)迁移到独立的test/cpp_extensions/test_from_blob.cpp,按at_npu::native::from_blob接口能力分门别类组织。test/cpp_extensions/setup.py注册新的扩展模块torch_test_cpp_extension.npu_from_blob。test/cpp_extensions/test/test_cpp_extensions_aot.py新增TestFromBlob测试类,覆盖 basic / deleter / strides / storage_offset / storage_offset_2d / storage_offset_dtype / storage_offset_contiguous / non_owning / clone 等场景;test_storage_sizes增加@SupportedDevices(['Ascend910B', 'Ascend910C'])限制。test/npu/test_npu_format.py新增test_weak_ref_tensor_with_storage_offset用例,构造带非平凡 stride 与 storage_offset 的 view,验证_weak_ref_tensor返回的 tensor 在 size、stride、storage_offset、storage().nbytes() 与数值上都与原 tensor 一致。【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
test/cpp_extensions/test/test_cpp_extensions_aot.py::TestFromBlob:覆盖at_npu::native::from_blob在 basic、自定义 deleter、显式 strides、带 storage_offset、二维带 offset、不同 dtype、contiguous 标志、non-owning 语义、clone 后数据正确性等场景,验证修复后 storage 计算正确。test/npu/test_npu_format.py::TestNPUFormat::test_weak_ref_tensor_with_storage_offset:构造view_shape=[2,1,8,64]、view_strides=[1536,0,192,1]、view_offset=128的 strided view,验证_weak_ref_tensor保持 size/stride/offset/storage 字节数一致且数值相等。【CheckList】