nncf.torch.sparsity.base_algo#

Base classes for NNCF PyTorch sparsity algorithm builder and controller objects.

Classes#

BaseSparsityAlgoController

Base class for sparsity algorithm controllers in PT.

class nncf.torch.sparsity.base_algo.BaseSparsityAlgoController(target_model, sparsified_module_info)[source]#

Bases: nncf.torch.compression_method_api.PTCompressionAlgorithmController, nncf.common.sparsity.controller.SparsityController

Base class for sparsity algorithm controllers in PT.

Parameters:
  • target_model (nncf.torch.nncf_network.NNCFNetwork) –

  • sparsified_module_info (List[SparseModuleInfo]) –

property current_sparsity_level: float[source]#

Returns the current sparsity level of the underlying model.

Return type:

float

property loss: nncf.api.compression.CompressionLoss[source]#

The compression loss for this particular algorithm combination.

Return type:

nncf.api.compression.CompressionLoss

property scheduler: nncf.common.sparsity.schedulers.SparsityScheduler[source]#

The compression scheduler for this particular algorithm combination.

Return type:

nncf.common.sparsity.schedulers.SparsityScheduler

disable_scheduler()[source]#

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

compression_stage()[source]#

Returns the compression stage. Should be used on saving best checkpoints to distinguish between uncompressed, partially compressed, and fully compressed models.

Returns:

The compression stage of the target model.

Return type:

nncf.api.compression.CompressionStage

strip_model(model, do_copy=False)[source]#

Strips auxiliary layers that were used for the model compression, as it’s only needed for training. The method is used before exporting the model in the target format.

Parameters:
  • model (nncf.torch.nncf_network.NNCFNetwork) – The compressed model.

  • do_copy (bool) – Modify copy of the model, defaults to False.

Returns:

The stripped model.

Return type:

nncf.torch.nncf_network.NNCFNetwork