MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / import_custom_ops

Function import_custom_ops

fastdeploy/import_ops.py:24–48  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

22
23
24def 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
51def rename_imported_op(old_name, new_name, global_ns):

Callers 7

__init__.pyFile · 0.90
__init__.pyFile · 0.90
__init__.pyFile · 0.90
__init__.pyFile · 0.90
__init__.pyFile · 0.90
__init__.pyFile · 0.90
__init__.pyFile · 0.90

Calls 2

preprocess_static_opFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected