nncf.common.compression#

Classes#

BaseCompressionAlgorithmController

Contains the implementation of the basic functionality of the compression controller.

class nncf.common.compression.BaseCompressionAlgorithmController(target_model)[source]#

Bases: nncf.api.compression.CompressionAlgorithmController, abc.ABC

Contains the implementation of the basic functionality of the compression controller.

Parameters:

target_model (TModel) –

property name[source]#

Name of the compression algorithm that is being controlled. Should be unique to identify the controller and its state among other controllers and their states.

property compression_rate: float[source]#

Returns a float compression rate value ranging from 0 to 1 (e.g. the sparsity level, or the ratio of filters pruned).

Return type:

float

property maximal_compression_rate: float[source]#

Returns the maximal model compression rate supported by the compression controller.

Return type:

float

export_model(save_path, save_format=None, input_names=None, output_names=None, model_args=None)[source]#

Exports the compressed model to the specified format for deployment.

Makes method-specific preparations of the model, (e.g. removing auxiliary layers that were used for the model compression), then exports the model to the specified path.

Parameters:
  • save_path (str) – The path where the model will be saved.

  • save_format (Optional[str]) – Saving format. The default format will be used if save_format is not specified.

  • input_names (Optional[List[str]]) – Names to be assigned to the input tensors of the model.

  • output_names (Optional[List[str]]) – Names to be assigned to the output tensors of the model.

  • model_args (Optional[Tuple[Any, Ellipsis]]) –

    Tuple of additional positional and keyword arguments which are required for the model’s forward during export. Should be specified in the following format:

    • (a, b, {‘x’: None, ‘y’: y}) for positional and keyword arguments.

    • (a, b, {}) for positional arguments only.

    • ({‘x’: None, ‘y’: y},) for keyword arguments only.

Return type:

None

disable_scheduler()[source]#

Disables current compression scheduler during training by changing it to a dummy one that does not change the compression rate.

Return type:

None

set_builder_state_with_name(name, builder_state)[source]#

Sets state of the builder and the corresponding algorithm name. Should be called by the builder to set its state and registered algorithm key.

Parameters:
  • name (str) – algorithm name, the string that was used to register the builder

  • builder_state (Dict) – state of the builder

load_state(state)[source]#

Loads the compression controller state from the map of algorithm name to the dictionary with state attributes.

Parameters:

state (Dict[str, Dict[str, Any]]) – map of the algorithm name to the dictionary with the corresponding state attributes.

Return type:

None

get_state()[source]#

Returns compression controller state, which is the map of the algorithm name to the dictionary with the corresponding state attributes.

Returns:

The compression controller state.

Return type:

Dict[str, Dict[str, Any]]

get_compression_state()[source]#

Returns compression state - builder and controller state. This state should be used to resume compression via compression_state argument of create_compressed_model method.

Returns:

The compression state.

Return type:

Dict[str, Any]