network_editor Module — MCT Documentation: ver 1.0.0

# network_editor Module

The model can be edited by a list of EditRules to apply on nodes in a graph that represents the model during the model quantization. Each EditRule is a tuple of a filter and an action, where we apply the action on each node the filter matches

## EditRule

class model_compression_toolkit.network_editor.EditRule(filter, action)

  A tuple of a node filter and an action. The filter matches nodes in the graph which represents the model, and the action is applied on these nodes during the quantization process.

  Examples

  Create an EditRule to quantize all Conv2D wights using 9 bits:

      >>> import model_compression_toolkit as mct
      >>> from tensorflow.keras.layers import Conv2D
      >>> er_list = [EditRule(filter=mct.network_editor.NodeTypeFilter(Conv2D),
      >>> action=mct.network_editor.ChangeWeightsQuantConfigAttr(weights_n_bits=9))]

  Then the rules list can be passed to `keras_post_training_quantization()` to modify the network during the quantization process.

  Create new instance of EditRule(filter, action)

## Filters

class model_compression_toolkit.network_editor.NodeTypeFilter(node_type)

  Class NodeNameFilter to check if a node is of a specific type.

  Init a NodeTypeFilter object.

  Parameters

    node_type – Node type to check.

class model_compression_toolkit.network_editor.NodeNameFilter(node_name)

  Class NodeNameFilter to check if a node’s name has a specific value.

  Init a NodeNameFilter object.

  Parameters

    node_name – Node name to check.

class model_compression_toolkit.network_editor.NodeNameScopeFilter(node_name_scope)

  Class NodeNameFilter to check if a string is in a node’s name.

  Init a NodeNameScopeFilter object.

  Parameters

    node_name_scope – String to check if exists in node name.

## Actions

class model_compression_toolkit.network_editor.ChangeWeightsQuantConfigAttr(**kwargs)

  Class ChangeQuantConfigAttr to change attributes in a node’s weights quantization configuration.

  Init a ChangeWeightsQuantConfigAttr object.

  Parameters

    kwargs – dict of attr_name and attr_value to change in the node’s weights quantization configuration.

class model_compression_toolkit.network_editor.ChangeActivationQuantConfigAttr(**kwargs)

  Class ChangeQuantConfigAttr to change attributes in a node’s activation quantization configuration.

  Init a ChangeActivationQuantConfigAttr object.

  Parameters

    kwargs – dict of attr_name and attr_value to change in the node’s activation quantization configuration.