Merged
torch cann_ops_nn export #7941
丛吉钰Add on Jul 25
torch cann_ops_nn export #7941
Merged
丛吉钰Add on Jul 25
Total: 1 files changed+22-1
@@ -15,7 +15,28 @@ logger = logging.getLogger(__name__)
15try:15try:
16 import torch # noqa: F40116 import torch # noqa: F401
17 import torch_npu # noqa: F40117 import torch_npu # noqa: F401
18- from .ops import * # noqa: F40318+ from . import ops # noqa: F401
19except ImportError as e:19except ImportError as e:
20 logger.error(f"导入cann_ops_nn失败: {e},请检查torch/torch_npu是否已安装")20 logger.error(f"导入cann_ops_nn失败: {e},请检查torch/torch_npu是否已安装")
21 raise21 raise
22+ 
23+_op_namespace = torch.ops.cann_ops_nn
24+ 
25+for _name in dir(ops):
26+ if _name.startswith("_") or hasattr(_op_namespace, _name):
27+ continue
28+ globals()[_name] = getattr(ops, _name)
29+del _name
30+ 
31+ 
32+def __getattr__(name):
33+ if hasattr(_op_namespace, name):
34+ handle = getattr(_op_namespace, name)
35+ globals()[name] = handle
36+ return handle
37+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
38+ 
39+ 
40+def __dir__():
41+ _seen = set(globals()) | set(dir(_op_namespace)) | set(dir(ops))
42+ return sorted(_seen)