已合并
bugfix: remove the decomposition of expm1 from torchbench and add it to mlir. #36487
yvjc创建于 5月22日
bugfix: remove the decomposition of expm1 from torchbench and add it to mlir. #36487
已合并
yvjc创建于 5月22日
已删除 :decomp7合入到Ascend/pytorchv2.7.1
4 个文件变更+48-24
Mbenchmarks/torchbench/npu_support.py+0-6
@@ -345,12 +345,6 @@ def _patch_model_10():
345 345 
346 DeepRecommenderTrainBenchmark.__init__ = new_init346 DeepRecommenderTrainBenchmark.__init__ = new_init
347 347 
348- def expm1(x):
349- tensor = torch.exp(x) - torch.ones_like(x)
350- return tensor
351- 
352- inductor_decomp.register_decomposition(torch.ops.aten.expm1)(expm1)
353- 
354 348 
355@register_patch("resnet50", "resnet152", "resnext50_32x4d", "densenet121")349@register_patch("resnet50", "resnet152", "resnext50_32x4d", "densenet121")
356def _patch_model_18():350def _patch_model_18():
Rtest/_inductor/test_inductor_fallback_list.pytest/_inductor/test_inductor_fallback_list_mlir.py+11-18
@@ -1,27 +1,20 @@
1-import torch
2-from torch.testing._internal.common_utils import run_tests, parametrize, instantiate_parametrized_tests
3-from testutils import TestUtils
4-from torch._inductor.utils import run_and_get_code
5-import torch_npu
6import os1import os
2+ 
3+import torch
4+from torch.testing._internal.common_utils import run_tests
5+from torch._inductor.utils import run_and_get_code
6+ 
7+from testutils import TestUtils
8+ 
9+ 
7os.environ["NPU_INDUCTOR_FALLBACK_LIST"] = "aten.div,aten.add.Tensor"10os.environ["NPU_INDUCTOR_FALLBACK_LIST"] = "aten.div,aten.add.Tensor"
8 11 
12+ 
9class TestFallback(TestUtils):13class TestFallback(TestUtils):
10 14
11 def add_op(self, x, y):15 def add_op(self, x, y):
12- return x / y16+ return x / y
13-
14- def test_add_fallback_detection(self):
15-
16- compiled_add = torch.compile(self.add_op, backend="inductor")
17-
18- x = torch.randn(4, 4, dtype=torch.float32).to("npu")
19- y = torch.randn(4, 4, dtype=torch.float32).to("npu")
20 17 
21- _ , codes = run_and_get_code(compiled_add, x, y)
22- 
23- self.assertTrue('unk_fused_div' not in codes[0])
24-
25 def test_add_fallback_detection_mlir(self):18 def test_add_fallback_detection_mlir(self):
26 19 
27 compiled_add = torch.compile(self.add_op, backend="inductor", options={"npu_backend": "mlir"})20 compiled_add = torch.compile(self.add_op, backend="inductor", options={"npu_backend": "mlir"})
@@ -35,4 +28,4 @@ class TestFallback(TestUtils):
35 28 
36 29 
37if __name__ == "__main__":30if __name__ == "__main__":
38- run_tests()31+ run_tests()
Atest/_inductor/test_inductor_fallback_list_triton.py+31-0
@@ -0,0 +1,31 @@
1+import os
2+ 
3+import torch
4+from torch.testing._internal.common_utils import run_tests
5+from torch._inductor.utils import run_and_get_code
6+ 
7+from testutils import TestUtils
8+ 
9+ 
10+os.environ["NPU_INDUCTOR_FALLBACK_LIST"] = "aten.div,aten.add.Tensor"
11+ 
12+ 
13+class TestFallback(TestUtils):
14+ 
15+ def add_op(self, x, y):
16+ return x / y
17+ 
18+ def test_add_fallback_detection(self):
19+ 
20+ compiled_add = torch.compile(self.add_op, backend="inductor")
21+ 
22+ x = torch.randn(4, 4, dtype=torch.float32).to("npu")
23+ y = torch.randn(4, 4, dtype=torch.float32).to("npu")
24+ 
25+ _ , codes = run_and_get_code(compiled_add, x, y)
26+ 
27+ self.assertTrue('unk_fused_div' not in codes[0])
28+ 
29+ 
30+if __name__ == "__main__":
31+ run_tests()
Mtorch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/npu_decomp.py+6-0
@@ -192,6 +192,12 @@ def gelu_backward(grad: Tensor, self: Tensor, approximate: str = "none"):
192 192 
193 return grad * (left_derivative + right_derivative)193 return grad * (left_derivative + right_derivative)
194 194 
195+ 
196+def expm1(x):
197+ tensor = torch.exp(x) - torch.ones_like(x)
198+ return tensor
199+ 
200+inductor_decomp.register_decomposition(torch.ops.aten.expm1)(expm1)
195inductor_decomp.register_decomposition(torch.ops.aten.convolution_backward)(npu_convolution_backward)201inductor_decomp.register_decomposition(torch.ops.aten.convolution_backward)(npu_convolution_backward)
196inductor_decomp.register_decomposition(torch.ops.aten._softmax_backward_data.default)(npu__softmax_backward_data)202inductor_decomp.register_decomposition(torch.ops.aten._softmax_backward_data.default)(npu__softmax_backward_data)
197inductor_decomp.register_decomposition(torch.ops.aten.gelu.default)(gelu)203inductor_decomp.register_decomposition(torch.ops.aten.gelu.default)(gelu)