已合并
fix_registrations #37836
cuiduo创建于 6月8日
fix_registrations #37836
已合并
共 4 个文件变更+4-11
| @@ -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) |
| @@ -293,12 +293,6 @@ def _load_triton_backend(): | |||
| 293 | add_additional_op() | 293 | add_additional_op() |
| 294 | torch._inductor.config.comprehensive_padding = False | 294 | 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: |
| @@ -66,8 +66,6 @@ class NpuMlirWrapperCodeGen(PythonWrapperCodegen): | |||
| 66 | import torch_npu | 66 | import torch_npu |
| 67 | import math | 67 | import math |
| 68 | import random | 68 | import random |
| 69 | - import os | ||
| 70 | - os.environ["TORCHINDUCTOR_NPU_BACKEND"] = 'mlir' | ||
| 71 | import tempfile | 69 | import tempfile |
| 72 | from math import inf, nan | 70 | from math import inf, nan |
| 73 | from torch._inductor.hooks import run_intermediate_hooks | 71 | from torch._inductor.hooks import run_intermediate_hooks |
| @@ -10,11 +10,12 @@ from torch._decomp import remove_decompositions | |||
| 10 | from torch._prims_common.wrappers import out_wrapper | 10 | from torch._prims_common.wrappers import out_wrapper |
| 11 | import torch.nn.functional as F | 11 | import torch.nn.functional as F |
| 12 | from .ascend_npu_ir.ascend_npu_ir import config as anir_config | 12 | from .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 | ||
| 15 | aten = torch.ops.aten | 15 | aten = torch.ops.aten |
| 16 | npu = torch.ops.npu | 16 | npu = torch.ops.npu |
| 17 | 17 | ||
| 18 | + | ||
| 18 | def _register_shared_decompositions(): | 19 | def _register_shared_decompositions(): |
改进建议: 添加注释: "# Ensure decompositions are registered only once, even if this module is reloaded or imported multiple times." 为什么这样改进: @run_once 不是标准库装饰器,是项目内部的工具。解释为什么这个函数 需要它(import 多次会导致注册冲突?还是性能优化?),帮助维护者判断 其他类似函数是否也需要。 ![]() ![]() | |||
| 19 | 20 | ||
| 20 | def expm1(x): | 21 | def expm1(x): |


问题: 这条环境变量的移除理由是什么?是后端选择逻辑已经在其他地方(如 config 或 entry point)正确设置了吗?如果是,应该在 commit message 中说明为什么现在可以安全删除。
改进建议: 补充 commit message: "This env var was a stale hardcode; backend selection is now handled by XXX at YYY."
为什么这样改进: 环境变量的设置/删除都可能影响下游行为——读者需要知道"为什么以前需要, 为什么现在不需要了"。