已合并
add_npu_backend_init_log #39403
cuiduo创建于 6月26日
add_npu_backend_init_log #39403
已合并
共 2 个文件变更+7-3
| @@ -1,7 +1,6 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | from torch.testing._internal.common_utils import run_tests, parametrize, instantiate_parametrized_tests | 2 | from torch.testing._internal.common_utils import run_tests, parametrize, instantiate_parametrized_tests |
| 3 | from testutils import TestUtils | 3 | from testutils import TestUtils |
| 4 | -import torch_npu | ||
| 5 | 4 | ||
| 6 | 5 | ||
| 7 | class TestSumAdd(TestUtils): | 6 | class TestSumAdd(TestUtils): |
| @@ -1,6 +1,7 @@ | |||
| 1 | import inspect | 1 | import inspect |
| 2 | import os | 2 | import os |
| 3 | import sys | 3 | import sys |
| 4 | +import logging | ||
| 4 | from typing import Any, Optional, TYPE_CHECKING | 5 | from typing import Any, Optional, TYPE_CHECKING |
| 5 | import importlib | 6 | import importlib |
| 6 | 7 | ||
| @@ -28,7 +29,7 @@ if TYPE_CHECKING: | |||
| 28 | from torch._dynamo.symbolic_convert import InstructionTranslator | 29 | from torch._dynamo.symbolic_convert import InstructionTranslator |
| 29 | 30 | ||
| 30 | use_jit_script = False | 31 | use_jit_script = False |
| 31 | - | 32 | +log = logging.getLogger(__name__) |
| 32 | 33 | ||
| 33 | class NPUTorchCtxManagerClassVariable(TorchCtxManagerClassVariable): | 34 | class NPUTorchCtxManagerClassVariable(TorchCtxManagerClassVariable): |
| 34 | def call_function(self, tx, args, kwargs): | 35 | def call_function(self, tx, args, kwargs): |
| @@ -227,10 +228,14 @@ def patch_inductor_wrapper(): | |||
| 227 | else: | 228 | else: |
| 228 | src_init(self, mode, options, dynamic) | 229 | src_init(self, mode, options, dynamic) |
| 229 | backend = _resolve_npu_backend_from_wrapper(self) | 230 | backend = _resolve_npu_backend_from_wrapper(self) |
| 230 | - if backend == "mlir" or backend == "dvm": | 231 | + if backend=="mlir": |
| 231 | with _NpuBackendScope(backend): | 232 | with _NpuBackendScope(backend): |
| 233 | + log.info("Running MLIR backend") | ||
| 232 | device_id = torch_npu.npu.current_device() | 234 | device_id = torch_npu.npu.current_device() |
| 233 | torch_npu._C._recovery_all_npu_stream(device_id) | 235 | torch_npu._C._recovery_all_npu_stream(device_id) |
| 236 | + if backend=="dvm": | ||
| 237 | + with _NpuBackendScope(backend): | ||
| 238 | + log.info("Running dvm backend") | ||
🟠 High Priority 原始代码中 建议:在 dvm 分支中补回 ![]() ![]() | |||
| 234 | 239 | ||
| 235 | _TorchCompileInductorWrapper.__call__ = new_call | 240 | _TorchCompileInductorWrapper.__call__ = new_call |
| 236 | _TorchCompileInductorWrapper.__init__ = new_init | 241 | _TorchCompileInductorWrapper.__init__ = new_init |


🔴 Critical
文件
torch_npu/utils/_dynamo.py中未定义log变量——没有import logging,也没有log = logging.getLogger(...)或从其他模块导入。第232行和第237行的log.info(...)调用将在运行时触发NameError: name 'log' is not defined,导致整个new_init函数崩溃,inductor wrapper 初始化失败。建议:在文件顶部添加
import logging,并在模块级别创建 logger:log = logging.getLogger(__name__),或者使用torch._logging.getArtifactLogger(与_graph_tree.py中的模式一致)。