neural_compressor.experimental.pytorch_pruner.patterns

Pattern module.

Module Contents

Classes

Pattern

Pruning Pattern.

PatternNxM

Pruning Pattern.

PatternNInM

Pruning Pattern.

Functions

register_pattern(name)

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

get_pattern(config)

Get registered pattern class.

neural_compressor.experimental.pytorch_pruner.patterns.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:
  • cls (class) – The class of register.

  • name – A string. Define the pattern type which will be included in a pruning process.

Returns:

The class of register.

Return type:

cls

neural_compressor.experimental.pytorch_pruner.patterns.get_pattern(config)[source]

Get registered pattern class.

Get a Pattern object from PATTERNS.

Parameters:

config – A config dict object. Contains the pattern information.

Returns:

A Pattern object.

Raises:

AssertionError – Currently only support patterns which have been registered in PATTERNS.

class neural_compressor.experimental.pytorch_pruner.patterns.Pattern(config)[source]

Pruning Pattern.

Every Pruner object will contain a Pattern object. It defines the basic pruning unit and how this unit will be pruned during pruning.

Parameters:

config – A config dict object. Contains the pattern information.

pattern[source]

A config dict object. The pattern related part in args config.

is_global[source]

A bool. Whether the pruning take global pruning option. Global pruning means that all pruning layers are gathered to calculate pruning criteria. Local pruning, on the contrast, means that pruning layers are to calculate criteria individually.

class neural_compressor.experimental.pytorch_pruner.patterns.PatternNxM(config)[source]

Pruning Pattern.

A Pattern class derived from Pattern. In this pattern, the weights in a NxM block will be pruned or kept during one pruning step.

Parameters:

config – A config dict object. Contains the pattern information.

block_size[source]

A list of two Integers. The height and width of the block. Please be aware that the vertical direction of a Linear layer’s weight in PyTorch refer to output channel. Because PyTorch’s tensor matmul has a hidden transpose operation.

class neural_compressor.experimental.pytorch_pruner.patterns.PatternNInM(config)[source]

Pruning Pattern.

A Pattern class derived from Pattern. In this pattern, N out of every M continuous weights will be pruned. For more info of this pattern, please refer to https://github.com/intel/neural-compressor/blob/master/docs/pruning.md

Parameters:

config – A config dict object. Contains the pattern information.

N[source]

The number of elements to be prune in a weight sequence.

M[source]

The size of the weight sequence.