yamle.pruning.pruner module#

class yamle.pruning.pruner.BasePruner[source]#

Bases: ABC

This is the base class for all prune methods.

The pruner’s call method will be used to prune the model. Additionally there is a function to analyse the model and print a summary of the pruning per each named parameter.

static prune_parameter(p, mask)[source]#

This function is used to prune a parameter based on a mask.

The mask’s True values will be pruned. False values will be kept.

This function and this function only should be used to prune parameters.

Return type:

None

static recover_parameter(p)[source]#

This function is used to recover a parameter from a mask.

Return type:

None

recover(m)[source]#

This method is used to recover the model from a mask.

Return type:

None

static add_specific_args(parent_parser)[source]#

This method is used to add the pruner specific arguments to the parent parser.

Return type:

ArgumentParser

summary(module)[source]#

This method is used to print a summary of the pruning per parameter.

The pruned weights are recognised as the weights with a value of 0.

The format of the is: the first column is the name of the parameter, the second column is the total number of weights in the parameter, the third column is the number of pruned weights in the parameter, the fourth column is the percentage of pruned weights in the parameter. The last row is the total number of pruned weights in the model, the total number of weights in the model and the percentage of pruned weights. Returns the total number of pruned weights.

Return type:

int

class yamle.pruning.pruner.DummyPruner[source]#

Bases: BasePruner

This is a dummy pruner class which does not do any pruning.

summary(m)[source]#

This method is used to print a summary of the pruning per parameter.

The pruned weights are recognised as the weights with a value of 0.

The format of the is: the first column is the name of the parameter, the second column is the total number of weights in the parameter, the third column is the number of pruned weights in the parameter, the fourth column is the percentage of pruned weights in the parameter. The last row is the total number of pruned weights in the model, the total number of weights in the model and the percentage of pruned weights. Returns the total number of pruned weights.

Return type:

int