Commits/
mock torch when compile pypto kernel
Co-authored-by: poorwill<wangbing110@huawei.com> # message auto-generated for no-merge-commit merge: !9115 merge master into master mock torch when compile pypto kernel Created-by: wangbing110 Commit-by: poorwill Merged-by: cann-robot Description: mock torch when compile pypto kernel See merge request: cann/ops-transformer!9115
2 file(s) changed+15-3
Mcmake/scripts/pypto_codegen.py+9-0
@@ -24,6 +24,14 @@ import os
24import shutil24import shutil
25import sys25import sys
26from pathlib import Path26from pathlib import Path
27+from unittest.mock import MagicMock
28+ 
29+ 
30+def _install_build_only_torch_stub():
31+ """Stub runtime-only dependencies that binary codegen does not use."""
32+ sys.modules["torch"] = MagicMock(name="torch")
33+ sys.modules["torch_npu"] = MagicMock(name="torch_npu")
34+ 
27 35 
28# soc (ASCEND_COMPUTE_UNIT, lowercased) -> pypto arch token used by PYPTO_JIT_ARCH.36# soc (ASCEND_COMPUTE_UNIT, lowercased) -> pypto arch token used by PYPTO_JIT_ARCH.
29_ARCH_MAP = {37_ARCH_MAP = {
@@ -36,6 +44,7 @@ _ARCH_MAP = {
36def _load_kernels(py_file: Path):44def _load_kernels(py_file: Path):
37 """Import the kernel module and return all @pl.jit kernel objects defined in it."""45 """Import the kernel module and return all @pl.jit kernel objects defined in it."""
38 sys.path.insert(0, str(py_file.parent))46 sys.path.insert(0, str(py_file.parent))
47+ _install_build_only_torch_stub()
39 48 
40 import pypto_pro.runtime.opc.pypto_compile as pto_compile49 import pypto_pro.runtime.opc.pypto_compile as pto_compile
41 from pypto_pro.runtime.jit import _TileJitKernel50 from pypto_pro.runtime.jit import _TileJitKernel
Mcmake/scripts/util/ascendc_impl_build.py+6-3

Comments