tf_nndct.IterativePruningRunner - 3.5 English

Vitis AI User Guide (UG1414)

Document ID
UG1414
Release Date
2023-09-28
Version
3.5 English

Runner for structured pruning of the model in an iterative way. This API has the following methods:

  • __init__(model, input_specs)

    Creates a new IterativePruningRunner object.

    model
    A baseline model to prune. The model should be an instance of keras.Model.
    input_specs
    A single or a list of tf.TensorSpec is used to represent model input specifications.
  • ana(eval_fn, excludes=None, forced=False)

    Performs model analysis. The analysis result is saved in the '.vai' directory, and this cached result is used directly in subsequent calls unless forced is set to True.

    eval_fn
    Callable object that takes a keras.Model object as its first argument and returns the evaluation score.
    excludes
    A list of layer names or layer instances to be excluded from pruning.
    forced
    When set to True, model analysis is run instead of the cached analysis result.
  • prune(ratio=None, threshold=None, spec_path=None, excludes=None, mode='sparse')

    Prunes the baseline model and returns a sparse model. The degree of pruning can be specified in three ways: ratio, threshold, or pruning specification. The first method is preferred; the latter two are more suitable for experiments with manual tuning.

    ratio
    The expected percentage of FLOPs reduction of the baseline model. This is a guidance value, and the actual FLOPs reduction cannot strictly be equal to this value.
    threshold
    Relative proportion of model performance loss between the baseline and pruned models.
    spec_path
    Pruning specification path is used to prune the model.
    excludes
    A list of layer name or layer instance to be excluded from pruning.
    mode
    The mode in which the baseline model is pruned to return a sparse model.
  • get_slim_model(spec_path=None)

    Gets a slim model from a sparse model. By default, you would use the latest pruning specification to do this transformation. A specification path can be provided explicitly if the sparse model was not generated from the latest specification.

    spec_path
    The pruning specification path transforms a sparse model into a slim one.