From 748e67ddab3ac69b64ec8a8da3ad7353bb367d4a Mon Sep 17 00:00:00 2001 From: d00482426 Date: Tue, 29 Jul 2025 19:10:38 +0800 Subject: [PATCH 1/3] fix(inductor):non-reduction axis cannot be tilling axis when reduction axis>=2 --- torch_npu/_inductor/codegen/split_tiling.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_npu/_inductor/codegen/split_tiling.py b/torch_npu/_inductor/codegen/split_tiling.py index 782cc9f745..9b94ce3c5c 100644 --- a/torch_npu/_inductor/codegen/split_tiling.py +++ b/torch_npu/_inductor/codegen/split_tiling.py @@ -141,6 +141,8 @@ class SplitTiling: def select_tiling(low_dim=True, reduction=True): for axis in reversed(self.kernel.sorted_axis): + if meet_stop_condition(): + break if low_dim and axis.sorted_order in self.kernel.low_dims and axis not in self.kernel.tiling_axis: axis.is_tiling_axis = True self.kernel.tiling_axis.append(axis) -- Gitee From 1f9297d5505e911406e95ebe3dbcb87e34e79649 Mon Sep 17 00:00:00 2001 From: d00482426 Date: Tue, 29 Jul 2025 21:31:19 +0800 Subject: [PATCH 2/3] fix(inductor):non-reduction axis cannot be tilling axis when reduction axis>=2 --- test/_inductor/test_expanded_reduction.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/_inductor/test_expanded_reduction.py diff --git a/test/_inductor/test_expanded_reduction.py b/test/_inductor/test_expanded_reduction.py new file mode 100644 index 0000000000..55e3f6a375 --- /dev/null +++ b/test/_inductor/test_expanded_reduction.py @@ -0,0 +1,27 @@ +import torch +from torch.testing._internal.common_utils import run_tests, parametrize, instantiate_parametrized_tests +from testutils import TestUtils +import torch_npu + + +class TestExpandedReduction(TestUtils): + def op_calc(self, first_element, second_element): + x = first_element * second_element + return x.sum((0, 1)) + + @parametrize('shape_x', [(2, 197, 256)]) + @parametrize('shape_y', [(2, 1, 256)]) + @parametrize('dtype', ['float16']) + def test_expanded_reduction_cases(self, shape_x, shape_y, dtype): + first_element = self._generate_tensor(shape_x, dtype) + second_element = self._generate_tensor(shape_y, dtype) + std_result = self.op_calc(first_element, second_element) + + compiled_op_calc = torch.compile(self.op_calc, backend="inductor") + inductor_result = compiled_op_calc(first_element, second_element) + self.assertEqual(std_result, inductor_result, atol=1e-5, rtol=1e-5) + +instantiate_parametrized_tests(TestAbs) + +if __name__ == "__main__": + run_tests() -- Gitee From aeea5f9e4ecc0e14ee1e7c769700f69676267707 Mon Sep 17 00:00:00 2001 From: d00482426 Date: Tue, 29 Jul 2025 23:55:57 +0800 Subject: [PATCH 3/3] fix(inductor):non-reduction axis cannot be tilling axis when reduction axis>=2 --- test/_inductor/test_expanded_reduction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/_inductor/test_expanded_reduction.py b/test/_inductor/test_expanded_reduction.py index 55e3f6a375..40e0363916 100644 --- a/test/_inductor/test_expanded_reduction.py +++ b/test/_inductor/test_expanded_reduction.py @@ -21,7 +21,7 @@ class TestExpandedReduction(TestUtils): inductor_result = compiled_op_calc(first_element, second_element) self.assertEqual(std_result, inductor_result, atol=1e-5, rtol=1e-5) -instantiate_parametrized_tests(TestAbs) +instantiate_parametrized_tests(TestExpandedReduction) if __name__ == "__main__": run_tests() -- Gitee