已合并
fix_registrations #37836
cuiduo创建于 6月8日
fix_registrations #37836
已合并
cuiduo创建于 6月8日
4 个文件变更+4-11
Mtest/_inductor/test_multi_backend_compile.py+2-2
@@ -24,8 +24,8 @@ class TestMultiBackendMixedCompile(TestCase):
24 24 
25 a = torch.randn(2, 2, dtype=dtype, device="npu")25 a = torch.randn(2, 2, dtype=dtype, device="npu")
26 b = torch.randn(2, 2, dtype=dtype, device="npu")26 b = torch.randn(2, 2, dtype=dtype, device="npu")
27- x = torch.randn(3, 4, dtype=dtype, device="npu")27+ x = torch.randn(3, 3, dtype=dtype, device="npu")
28- y = torch.randn(3, 4, dtype=dtype, device="npu")28+ y = torch.randn(3, 3, dtype=dtype, device="npu")
29 29 
30 sub_out, sub_codes = run_and_get_code(op_sub, a, b)30 sub_out, sub_codes = run_and_get_code(op_sub, a, b)
31 self.assertEqual(a - b, sub_out, atol=1e-3, rtol=1e-3)31 self.assertEqual(a - b, sub_out, atol=1e-3, rtol=1e-3)
Mtorch_npu/_inductor/__init__.py+0-6
@@ -293,12 +293,6 @@ def _load_triton_backend():
293 add_additional_op()293 add_additional_op()
294 torch._inductor.config.comprehensive_padding = False294 torch._inductor.config.comprehensive_padding = False
295 295 
296- compile_threads = int(
297- os.environ.get("TORCHINDUCTOR_COMPILE_THREADS") or "1"
298- )
299- os.environ["TORCHINDUCTOR_COMPILE_THREADS"] = str(compile_threads)
300- torch._inductor.config.compile_threads = compile_threads
301- 
302 _fasta_autotune = os.environ.get("FASTAUTOTUNE", "0") == "1"296 _fasta_autotune = os.environ.get("FASTAUTOTUNE", "0") == "1"
303 _fasta_autotune_method = os.getenv("AUTOTUNE_METHOD", "Expert")297 _fasta_autotune_method = os.getenv("AUTOTUNE_METHOD", "Expert")
304 if _fasta_autotune:298 if _fasta_autotune:
Mtorch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/wrapper.py+0-2
@@ -66,8 +66,6 @@ class NpuMlirWrapperCodeGen(PythonWrapperCodegen):
66 import torch_npu66 import torch_npu
67 import math67 import math
68 import random68 import random
69- import os
70- os.environ["TORCHINDUCTOR_NPU_BACKEND"] = 'mlir'
gys
gysgys6月8日
已过期

问题: 这条环境变量的移除理由是什么?是后端选择逻辑已经在其他地方(如 config 或 entry point)正确设置了吗?如果是,应该在 commit message 中说明为什么现在可以安全删除。

改进建议: 补充 commit message: "This env var was a stale hardcode; backend selection is now handled by XXX at YYY."

为什么这样改进: 环境变量的设置/删除都可能影响下游行为——读者需要知道"为什么以前需要, 为什么现在不需要了"。

likedislike
cuiduo
cuiduo
6月9日 评论:
71 import tempfile69 import tempfile
72 from math import inf, nan70 from math import inf, nan
73 from torch._inductor.hooks import run_intermediate_hooks71 from torch._inductor.hooks import run_intermediate_hooks
Mtorch_npu/_inductor/decomposition.py+2-1
@@ -10,11 +10,12 @@ from torch._decomp import remove_decompositions
10from torch._prims_common.wrappers import out_wrapper10from torch._prims_common.wrappers import out_wrapper
11import torch.nn.functional as F11import torch.nn.functional as F
12from .ascend_npu_ir.ascend_npu_ir import config as anir_config12from .ascend_npu_ir.ascend_npu_ir import config as anir_config
13- 13+from .ascend_npu_ir.ascend_npu_ir.npu.utils import run_once
14 14 
15aten = torch.ops.aten15aten = torch.ops.aten
16npu = torch.ops.npu16npu = torch.ops.npu
17 17 
18+@run_once
18def _register_shared_decompositions():19def _register_shared_decompositions():
gys
gysgys6月8日

此条代码评论区间+1819

改进建议: 添加注释: "# Ensure decompositions are registered only once, even if this module is reloaded or imported multiple times."

为什么这样改进: @run_once 不是标准库装饰器,是项目内部的工具。解释为什么这个函数 需要它(import 多次会导致注册冲突?还是性能优化?),帮助维护者判断 其他类似函数是否也需要。

likedislike
cuiduo
cuiduo
6月9日 评论:
19 @register_decomposition([aten.expm1])20 @register_decomposition([aten.expm1])
20 def expm1(x):21 def expm1(x):