neural_compressor.compression.pruner.patterns.base

Pruning patterns.

Classes

BasePattern

Pruning Pattern.

PytorchBasePattern

Pruning Pattern.

KerasBasePattern

Pruning Pattern.

Functions

register_pattern(name)

Class decorator used to register a Pattern subclass to the registry.

Module Contents

neural_compressor.compression.pruner.patterns.base.register_pattern(name)[source]

Class decorator used to register a Pattern subclass to the registry.

Decorator function used before a Pattern subclasses. Make sure that this Pattern class can be registered in PATTERNS.

Parameters:

name – A string defining the pattern type name to be used in a pruning process.

Returns:

The class of register.

Return type:

cls

class neural_compressor.compression.pruner.patterns.base.BasePattern(config, modules)[source]

Pruning Pattern.

It defines the basic pruning unit and how this unit will be pruned during pruning, e.g. 4x1, 2:4.

Parameters:
  • config – A config dict object that contains the pattern information.

  • modules – neural network modules to be pruned with the pattern.

pattern[source]

A config dict object that includes information of the pattern.

is_global[source]

A bool determining whether the pruning takes global pruning option. Global pruning means that pruning scores by a pruning criterion are evaluated in all layers. Local pruning, by contrast, means that pruning scores by the pruning criterion are evaluated

in every layer individually.

keep_mask_layers[source]

A dict that includes the layers whose mask will not be updated.

invalid_layers[source]

The layers whose shapes don’t fit the pattern.

modules[source]

neural network modules to be pruned with the pattern.

config[source]

A config dict object that contains all the information including the pattern’s.

max_sparsity_ratio_per_op[source]

A float representing the maximum sparsity that one layer could reach.

min_sparsity_ratio_per_op[source]

A float representing the minimum sparsity that one layer could reach.

target_sparsity[source]

A float representing the sparsity ratio of the modules after pruning.

class neural_compressor.compression.pruner.patterns.base.PytorchBasePattern(config, modules)[source]

Pruning Pattern.

It defines the basic pruning unit and how this unit will be pruned during pruning, e.g. 4x1, 2:4.

Parameters:
  • config – A config dict object that contains the pattern information.

  • modules – neural network modules to be pruned with the pattern.

pattern[source]

A config dict object that includes information of the pattern.

is_global[source]

A bool determining whether the pruning takes global pruning option. Global pruning means that pruning scores by a pruning criterion are evaluated in all layers. Local pruning, by contrast, means that pruning scores by the pruning criterion are evaluated

in every layer individually.

keep_mask_layers[source]

A dict that includes the layers whose mask will not be updated.

invalid_layers[source]

The layers whose shapes don’t fit the pattern.

modules[source]

neural network modules to be pruned with the pattern.

config[source]

A config dict object that contains all the information including the pattern’s.

max_sparsity_ratio_per_op[source]

A float representing the maximum sparsity that one layer could reach.

min_sparsity_ratio_per_op[source]

A float representing the minimum sparsity that one layer could reach.

target_sparsity[source]

A float representing the sparsity ratio of the modules after pruning.

class neural_compressor.compression.pruner.patterns.base.KerasBasePattern(config, modules)[source]

Pruning Pattern.

It defines the basic pruning unit and how this unit will be pruned during pruning, e.g. 4x1, 2:4.

Parameters:
  • config – A config dict object that contains the pattern information.

  • modules – neural network modules to be pruned with the pattern.

pattern[source]

A config dict object that includes information of the pattern.

is_global[source]

A bool determining whether the pruning takes global pruning option. Global pruning means that pruning scores by a pruning criterion are evaluated in all layers. Local pruning, by contrast, means that pruning scores by the pruning criterion are evaluated

in every layer individually.

keep_mask_layers[source]

A dict that includes the layers whose mask will not be updated.

invalid_layers[source]

The layers whose shapes don’t fit the pattern.

modules[source]

neural network modules to be pruned with the pattern.

config[source]

A config dict object that contains all the information including the pattern’s.

max_sparsity_ratio_per_op[source]

A float representing the maximum sparsity that one layer could reach.

min_sparsity_ratio_per_op[source]

A float representing the minimum sparsity that one layer could reach.

target_sparsity[source]

A float representing the sparsity ratio of the modules after pruning.