已合并
Revert "fix: fix aclnn npu_format_cast to respect allow_internal_format=False" #39259
wangzili121创建于 6月25日
Revert "fix: fix aclnn npu_format_cast to respect allow_internal_format=False" #39259
已合并
共 2 个文件变更+9-26
| @@ -171,19 +171,15 @@ class ProcessGroupHCCLTest(TestCase): | |||
| 171 | 171 | ||
| 172 | class ComputeBucketAssignmentTest(TestCase): | 172 | class ComputeBucketAssignmentTest(TestCase): |
| 173 | def test_single_limit_single_dtype(self): | 173 | def test_single_limit_single_dtype(self): |
| 174 | - torch_npu.npu.config.allow_internal_format = True | 174 | + tensors = [ |
| 175 | - try: | 175 | + torch_npu.npu_format_cast(torch.empty([100, 1], dtype=torch.float).npu(), Format.NZ), |
| 176 | - tensors = [ | 176 | + torch.empty([200], dtype=torch.float).npu(), |
| 177 | - torch_npu.npu_format_cast(torch.empty([100, 1], dtype=torch.float).npu(), Format.NZ), | 177 | + torch.empty([100], dtype=torch.float).npu(), |
| 178 | - torch.empty([200], dtype=torch.float).npu(), | 178 | + torch.empty([50], dtype=torch.float).npu(), |
| 179 | - torch.empty([100], dtype=torch.float).npu(), | 179 | + ] |
| 180 | - torch.empty([50], dtype=torch.float).npu(), | 180 | + result = dist._compute_bucket_assignment_by_size(tensors, [1792 * 4 + 1]) |
| 181 | - ] | 181 | + expec_result = ([[0, 1, 2, 3]], [7169]) |
| 182 | - result = dist._compute_bucket_assignment_by_size(tensors, [1792 * 4 + 1]) | 182 | + self.assertEqual(expec_result, result) |
| 183 | - expec_result = ([[0, 1, 2, 3]], [7169]) | ||
| 184 | - self.assertEqual(expec_result, result) | ||
| 185 | - finally: | ||
| 186 | - torch_npu.npu.config.allow_internal_format = False | ||
| 187 | 183 | ||
| 188 | def test_single_limit_multi_dtype(self): | 184 | def test_single_limit_multi_dtype(self): |
| 189 | tensors = [ | 185 | tensors = [ |
| @@ -8,7 +8,6 @@ | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | - | ||
| 12 | 11 | ||
| 13 | 12 | ||
| 14 | 13 | ||
| @@ -62,21 +61,9 @@ static bool ShouldFallbackNzToNd(const at::Tensor& self, int64_t acl_format) | |||
| 62 | return false; | 61 | return false; |
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | -static int64_t MaybeDowngradeInternalFormat(int64_t acl_format) | ||
| 66 | -{ | ||
| 67 | - if (env::CheckForbidInternalFormat() && | ||
| 68 | - !FormatHelper::IsBaseFormatType(static_cast<aclFormat>(acl_format))) { | ||
| 69 | - TORCH_WARN_ONCE("Cannot create tensor with internal format while allow_internal_format=False, " | ||
| 70 | - "tensor will be created with base format."); | ||
| 71 | - return static_cast<int64_t>(FormatHelper::GetBaseFormat(static_cast<aclFormat>(acl_format))); | ||
| 72 | - } | ||
| 73 | - return acl_format; | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | std::tuple<bool, int64_t, c10::SmallVector<int64_t, SIZE>> MaybeUseAclnnNpuFormatCast(const at::Tensor& src, | 64 | std::tuple<bool, int64_t, c10::SmallVector<int64_t, SIZE>> MaybeUseAclnnNpuFormatCast(const at::Tensor& src, |
| 77 | int64_t acl_format, c10::optional<int64_t> customize_dtype, c10::optional<int64_t> input_dtype) | 65 | int64_t acl_format, c10::optional<int64_t> customize_dtype, c10::optional<int64_t> input_dtype) |
| 78 | { | 66 | { |
| 79 | - acl_format = MaybeDowngradeInternalFormat(acl_format); | ||
| 80 | const static auto GetFormatFuncAddr = GetOpApiFuncAddr("aclnnNpuFormatCastCalculateSizeAndFormat"); | 67 | const static auto GetFormatFuncAddr = GetOpApiFuncAddr("aclnnNpuFormatCastCalculateSizeAndFormat"); |
| 81 | const static auto FormatCastFuncAddr = GetOpApiFuncAddr("aclnnNpuFormatCast"); | 68 | const static auto FormatCastFuncAddr = GetOpApiFuncAddr("aclnnNpuFormatCast"); |
| 82 | 69 | ||
🟠 High Priority
问题
本 PR 删除了
MaybeDowngradeInternalFormat函数及其在MaybeUseAclnnNpuFormatCast中的调用。该函数是 ACLNN 格式转换路径中唯一 执行allow_internal_format=False检查的守卫。证据链
删除的函数 (
MaybeDowngradeInternalFormat) 在allow_internal_format=False时,将内部格式(如 NZ、NC1HWC0 等)降级为基础格式(ND),从而阻止内部格式张量的创建。ACLNN 路径绕过 TensorFactories 的检查:ACLNN 路径通过
format_cast_impl_out_npu_aclnn→create_tensor_with_format_and_shape直接分配存储并设置格式描述符,完全绕过TensorFactories::unsafe_empty_with_format中的CheckForbidInternalFormat()检查(该检查仍在 line 421)。旧 aclop 回退路径仍保留检查:
npu_format_cast_impl→ApplyTensorWithFormat→unsafe_empty_with_format→CheckForbidInternalFormat,但 ACLNN 路径不再受保护。ACLNN-only 设备上彻底失效:在
c10_npu::IsAclnnOnly()的设备上,没有 aclop 回退路径,allow_internal_format=False设置对格式转换完全无效。影响
建议:恢复
MaybeDowngradeInternalFormat函数及其在MaybeUseAclnnNpuFormatCast中的调用,或者作为替代方案,在create_tensor_with_format_and_shape中添加等价的CheckForbidInternalFormat()检查,确保 ACLNN 路径与 aclop 路径行为一致。推荐恢复原修复:在MaybeUseAclnnNpuFormatCast入口处对acl_format调用MaybeDowngradeInternalFormat。