Imports custom operations from a specified module within a package and adds them to a global namespace. Args: package (str): The name of the package containing the module. module_name (str): The name of the module within the package. global_ns (dict): The global nam
(package, module_name, global_ns)
| 22 | |
| 23 | |
| 24 | def import_custom_ops(package, module_name, global_ns): |
| 25 | """ |
| 26 | Imports custom operations from a specified module within a package and adds them to a global namespace. |
| 27 | |
| 28 | Args: |
| 29 | package (str): The name of the package containing the module. |
| 30 | module_name (str): The name of the module within the package. |
| 31 | global_ns (dict): The global namespace to add the imported functions to. |
| 32 | """ |
| 33 | try: |
| 34 | module = importlib.import_module(module_name, package=package) |
| 35 | functions = inspect.getmembers(module) |
| 36 | for func_name, func in functions: |
| 37 | if func_name.startswith("__") or func_name == "_C_ops": |
| 38 | continue |
| 39 | logger.debug(f"Import {func_name} from {package}") |
| 40 | try: |
| 41 | global_ns[func_name] = func |
| 42 | except Exception as e: |
| 43 | logger.warning(f"Failed to import op {func_name}: {e}") |
| 44 | |
| 45 | except Exception as e: |
| 46 | logger.warning(f"Ops of {package} import failed, it may be not compiled. {e}") |
| 47 | |
| 48 | preprocess_static_op(global_ns) |
| 49 | |
| 50 | |
| 51 | def rename_imported_op(old_name, new_name, global_ns): |
no test coverage detected