wuyouqi1
38c1f4290f
fix: downgrade internal-format targets to base format on the aclnn path when ALLOW_INTERNAL_FORMAT=disable [master]
Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com>
# message auto-generated for no-merge-commit merge:
!45500 merge fix/aclnn-format-cast-forbid-internal-format-master into master
fix: downgrade internal-format targets to base format on the aclnn path when ALLOW_INTERNAL_FORMAT=disable [master]
Created-by: wuyouqi1
Commit-by: wuyouqi1
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/4389
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
allow_internal_format=False 时,npu_format_cast 走 aclnn 路径(7302fba05 引入)未检查该开关:目标为内部格式(FRACTAL_NZ/NC1HWC0/FRACTAL_Z)时直接创建私有格式 tensor,绕过了 aclop 分配层守卫(TensorFactories.cpp unsafe_empty_with_format),与 aclop 路径行为不一致,导致 test_allow_internal_format_false_with_npu_format_cast 类用例失败。
修复:在 MaybeUseAclnnNpuFormatCast 的 IsAclnnFormatCastSupported 分支入口增加降级守卫——allow_internal_format=False 且目标为非 base 格式时,将目标降级为 GetBaseFormat 并 TORCH_WARN_ONCE,与 aclop 路径行为对齐。
关键设计:cast_into_existing 豁免——目标格式等于 src tensor 自身格式时不降级(tensor 重载 npu_format_cast_(self, Tensor src) 中该值恒为 True,属预期:该重载语义为将 src 数据写入已存在 tensor,目标格式是既成事实;若降级会破坏 nz_dst.copy_(nd_src) 后 dst 保持 NZ 布局的既有行为)。int 重载经 same-format 早退后该值恒为 False,守卫正常生效。950 的 IsAclnnOnly 分支不经此守卫,不受影响。
注:此前 !39022 曾在 MaybeUseAclnnNpuFormatCast 入口无条件降级(无 cast_into_existing 豁免),因破坏既有行为被 !39259 回退。本 MR 为带豁免的修正版,同步自 v2.7.1 MR !45183。
# 【资料变更】
op-plugin 仓 MR !5771(allow_internal_format 影响范围说明)
# 【接口变更】
不涉及
# 【功能验证】
UT:test/custom_ops/test_npu_format_cast.py TestNpuFormatCastForbidInternalFormat(降级 4 组格式断言 + base 目标不受影响 + 开关开启对照 + copy_ 保持已存在 NZ tensor 格式)
See merge request: Ascend/pytorch!45500
2026-08-29 11:57:14 +08:00
..
2025-03-20 07:08:57 +00:00
2023-11-07 07:24:39 +00:00
2026-05-18 15:08:46 +08:00
2026-06-08 19:54:52 +08:00
2026-05-19 17:10:06 +08:00
2025-01-27 03:20:33 +00:00
2026-05-21 16:41:18 +08:00
2023-11-07 07:24:39 +00:00
2026-05-21 16:41:18 +08:00
2023-11-07 07:24:39 +00:00
2023-11-23 06:50:03 +00:00
2025-04-22 07:36:21 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2026-05-18 15:08:46 +08:00
2026-06-22 16:47:27 +08:00
2026-06-22 16:47:27 +08:00
2024-12-13 02:48:31 +00:00
2026-05-18 15:08:46 +08:00
2026-04-13 15:16:48 +08:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2026-05-21 16:41:18 +08:00
2026-08-29 11:57:14 +08:00
2024-01-15 13:03:18 +00:00
2024-01-15 13:03:18 +00:00
2023-11-07 07:24:39 +00:00
2026-05-18 15:08:46 +08:00
2026-07-30 20:12:08 +08:00
2025-04-22 07:36:21 +00:00
2023-11-23 08:43:29 +00:00
2026-06-22 16:47:27 +08:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2026-06-08 16:14:33 +08:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2026-05-18 15:08:46 +08:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2024-01-25 12:11:49 +00:00
2024-01-25 12:11:49 +00:00
2023-11-23 06:50:03 +00:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2026-05-18 15:08:46 +08:00
2023-11-23 06:50:03 +00:00
2025-04-22 07:36:21 +00:00
2026-05-21 16:41:18 +08:00
2026-06-22 16:47:27 +08:00
2023-11-07 07:24:39 +00:00
2023-11-07 07:24:39 +00:00
2025-01-26 09:55:07 +00:00
2026-05-21 16:41:18 +08:00
2026-05-18 15:08:46 +08:00
2023-11-07 07:24:39 +00:00