mindspore.graph.register_custom_pass
- mindspore.graph.register_custom_pass(pass_name, plugin_so_path, device='all', pass_type=CustomPassType.PATTERN)[source]
Register a custom pass to modify graph structure for default
"ms_backend"backend.Note
Windows and MacOS systems are not supported yet. The user must guarantee the validity and legality of the custom pass plugin file.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters:
pass_name (str) – Name of the pass expected to be provided by the plugin.
plugin_so_path (str) – Absolute path to the plugin shared library (.so file).
device (str, optional) – Target device for the pass. Supported values:
"cpu","gpu","ascend", or"all". Default:"all".pass_type (CustomPassType, optional) –
Type of the custom pass. Default:
CustomPassType.PATTERN. It can beCustomPassType.PATTERN,CustomPassType.FULL_GRAPH.CustomPassType.PATTERN: rewrites the graph structure based on a user-defined pattern to match, such as replacing an Add operator and a Neg operator with a Sub operator. This is applied in the backend optimization process.CustomPassType.FULL_GRAPH: rewrites the graph based on the information of the entire graph. This is applied in the frontend optimization process.
- Returns:
bool. Returns
Trueif the custom pass is registered successfully, otherwise returnsFalse.- Raises:
TypeError – If pass_type is not of type
mindspore.graph.CustomPassType.
Examples
>>> import mindspore.graph as graph >>> # Register a custom optimization pass >>> success = graph.register_custom_pass( ... pass_name="my_fusion_pass", ... plugin_so_path="/path/to/my_plugin.so", ... device="ascend" ... ) >>> print(f"Registration successful: {success}")