neural_compressor.compression.pruner.pruners.base

Base pruner.

Classes

BasePruner

Pruning Pruner.

PytorchBasePruner

Pruning Pruner.

KerasBasePruner

Pruning Pruner.

Functions

register_pruner(name)

Class decorator to register a Pruner subclass to the registry.

Module Contents

neural_compressor.compression.pruner.pruners.base.register_pruner(name)[source]

Class decorator to register a Pruner subclass to the registry.

Decorator function used before a Pattern subclass. Make sure that the Pruner class decorated by this function can be registered in PRUNERS.

Parameters:
  • cls (class) – The subclass of register.

  • name – A string. Define the pruner type.

Returns:

The class of register.

Return type:

cls

class neural_compressor.compression.pruner.pruners.base.BasePruner(config, modules, framework='pytorch')[source]

Pruning Pruner.

The class which executes pruning process.

Parameters:
  • modules – A dict {“module_name”: Tensor} that stores the pruning modules’ weights.

  • config – A config dict object that contains the pruner information.

modules[source]

A dict {“module_name”: Tensor} that stores the pruning modules’ weights.

config[source]

A config dict object that contains the pruner information.

masks[source]

A dict {“module_name”: Tensor} that stores the masks for modules’ weights.

scores[source]

A dict {“module_name”: Tensor} that stores the score for modules’ weights, which are used to determine what parts to be pruned by a criterion.

pattern[source]

A Pattern object defined in ./patterns.py

scheduler[source]

A scheduler object defined in ./scheduler.py

current_sparsity_ratio[source]

A float representing the current model’s sparsity ratio; it is initialized to be zero.

global_step[source]

An integer representing the total steps the model has run.

start_step[source]

An integer representing when to trigger pruning process.

end_step[source]

An integer representing when to end pruning process.

pruning_frequency[source]

An integer representing the pruning frequency; it is valid when iterative pruning is enabled.

target_sparsity_ratio[source]

A float showing the final sparsity after pruning.

max_sparsity_ratio_per_op[source]

A float showing the maximum sparsity ratio for every module.

class neural_compressor.compression.pruner.pruners.base.PytorchBasePruner(config, modules)[source]

Pruning Pruner.

The class which executes pruning process.

Parameters:
  • modules – A dict {“module_name”: Tensor} that stores the pruning modules’ weights.

  • config – A config dict object that contains the pruner information.

modules[source]

A dict {“module_name”: Tensor} that stores the pruning modules’ weights.

config[source]

A config dict object that contains the pruner information.

masks[source]

A dict {“module_name”: Tensor} that stores the masks for modules’ weights.

scores[source]

A dict {“module_name”: Tensor} that stores the score for modules’ weights, which are used to determine what parts to be pruned by a criterion.

pattern[source]

A Pattern object defined in ./patterns.py

scheduler[source]

A scheduler object defined in ./scheduler.py

current_sparsity_ratio[source]

A float representing the current model’s sparsity ratio; it is initialized to be zero.

global_step[source]

An integer representing the total steps the model has run.

start_step[source]

An integer representing when to trigger pruning process.

end_step[source]

An integer representing when to end pruning process.

pruning_frequency[source]

An integer representing the pruning frequency; it is valid when iterative pruning is enabled.

target_sparsity_ratio[source]

A float showing the final sparsity after pruning.

max_sparsity_ratio_per_op[source]

A float showing the maximum sparsity ratio for every module.

class neural_compressor.compression.pruner.pruners.base.KerasBasePruner(config, modules)[source]

Pruning Pruner.

The class which executes pruning process.

Parameters:
  • modules – A dict {“module_name”: Tensor} that stores the pruning modules’ weights.

  • config – A config dict object that contains the pruner information.

modules[source]

A dict {“module_name”: Tensor} that stores the pruning modules’ weights.

config[source]

A config dict object that contains the pruner information.

masks[source]

A dict {“module_name”: Tensor} that stores the masks for modules’ weights.

scores[source]

A dict {“module_name”: Tensor} that stores the score for modules’ weights, which are used to determine what parts to be pruned by a criterion.

pattern[source]

A Pattern object defined in ./patterns.py

scheduler[source]

A scheduler object defined in ./scheduler.py

current_sparsity_ratio[source]

A float representing the current model’s sparsity ratio; it is initialized to be zero.

global_step[source]

An integer representing the total steps the model has run.

start_step[source]

An integer representing when to trigger pruning process.

end_step[source]

An integer representing when to end pruning process.

pruning_frequency[source]

An integer representing the pruning frequency; it is valid when iterative pruning is enabled.

target_sparsity_ratio[source]

A float showing the final sparsity after pruning.

max_sparsity_ratio_per_op[source]

A float showing the maximum sparsity ratio for every module.