Skip to content

Commit

Permalink
Adaptive Compression Training Loop documentation tweaks and improveme…
Browse files Browse the repository at this point in the history
…nt (openvinotoolkit#1413)

### Changes

- Tweaked parameters description according to recent changes to ACTL
- Added an example plot reflecting model compression progress by ACTL
  • Loading branch information
nikita-savelyevv committed Dec 16, 2022
1 parent a28de18 commit 8b53a8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Adaptive Compression Level training loop is the meta-algorithm that performs sea
The compression pipeline can consist of several compression algorithms (Algorithms Mixing), however, **performing a compression level search is supported only for a single compression algorithm with an adaptive compression level**. They could be **Magnitude Sparsity** and **Filter Pruning**. In the other words, the compression schemes like **Quantization** + **Filter Pruning** or **Quantization** + **Sparsity** are supported, while **Filter Pruning** + **Sparsity** is not, because **Filter Pruning** and **Sparsity** both are algorithms with adaptive compression level.

The exact compression algorithm for which the compression level search will be applied is determined in "compression" config section. The parameters to be set by the user in this config section are:
1) `maximal_relative_accuracy_degradation` or `maximal_absolute_accuracy_degradation` - the maximal allowed accuracy metric drop relative to the original model metrics (in percent) or the maximal allowed absolute accuracy metric drop (in original metrics value),
2) `initial_training_phase_epochs` - the number of epochs to train the model with the compression schedule specified in the `"params"` section of `"compression"` algorithm.

3) `patience_epochs` - the number of epochs to train the model for a compression rate level set by the search algorithm before switching to another compression rate value.
4) `minimal_compression_rate_step` (Optional; default=0.025) - The minimal compression rate change step value after which the training loop is terminated.
5) `initial_compression_rate_step` (Optional; default=0.1) - Initial value for the compression rate increase/decrease training phase of the compression training loop.
6) `compression_rate_step_reduction_factor` (Optional; default=0.5) - Factor used to reduce the compression rate change step in the adaptive compression training loop.
7) `maximal_total_epochs` (Optional; default=1e4) - The number of training epochs, if the fine-tuning epoch reaches this number, the loop finishes the fine-tuning and return the model with thi highest compression rate and the least accuracy drop.
1) `maximal_relative_accuracy_degradation` or `maximal_absolute_accuracy_degradation` (Optional; default `maximal_relative_accuracy_degradation=1.0`) - the maximal allowed accuracy metric drop relative to the original model metrics (in percent) or the maximal allowed absolute accuracy metric drop (in original metrics value),
2) `initial_training_phase_epochs` (Optional; default=5) - number of epochs to train the model with the compression schedule specified in the `"params"` section of `"compression"` algorithm.
3) `patience_epochs` (Optional; default=3) - number of epochs to train the model for a compression rate level set by the search algorithm before switching to another compression rate value.
4) `minimal_compression_rate_step` (Optional; default=0.025) - the minimal compression rate change step value after which the training loop is terminated.
5) `initial_compression_rate_step` (Optional; default=0.1) - initial value for the compression rate increase/decrease training phase of the compression training loop.
6) `compression_rate_step_reduction_factor` (Optional; default=0.5) - factor used to reduce the compression rate change step in the adaptive compression training loop.
7) `lr_reduction_factor` (Optional; default=0.5) - factor used to reduce the base value of the learning rate scheduler after compression rate step is reduced.
8) `maximal_total_epochs` (Optional; default=10000) - number of training epochs, if the fine-tuning epoch reaches this number, the loop finishes the fine-tuning and return the model with thi highest compression rate and the least accuracy drop.


To launch the adaptive compression training loop, the user should define several functions related to model training, validation and optimizer creation (see [the usage documentation](../Usage.md#accuracy-aware-model-training) for more details) and pass them to the run method of an `AdaptiveCompressionTrainingLoop` instance.
Expand All @@ -24,12 +24,13 @@ Below is an example of a filter pruning configuration with added `"accuracy_awar
"accuracy_aware_training": {
"mode": "adaptive_compression_level",
"params": {
"maximal_relative_accuracy_degradation": 1.0,
"initial_training_phase_epochs": 100,
"patience_epochs": 30,
"maximal_relative_accuracy_degradation": 1.0, // Optional
"initial_training_phase_epochs": 100, // Optional
"patience_epochs": 30, // Optional
"minimal_compression_rate_step": 0.025, // Optional
"initial_compression_rate_step": 0.1, // Optional
"compression_rate_step_reduction_factor": 0.5, // Optional
"lr_reduction_factor": 0.5, // Optional
"maximal_total_epochs": 10000 // Optional
}
},
Expand All @@ -53,7 +54,7 @@ Below is an example of a filter pruning configuration with added `"accuracy_awar

The first step is **Initial Training Phase** - It corresponds to the amount of epochs that the model is going to be trained for with the initial compression rate level/schedule set by the user in the standard NNCF manner (the initial pruning rate schedule above is an exponential schedule with the target pruning rate of 0.1).

The second one is **Finding the optimal compression rate**, where the next compression rate value is determined by the search algorithm and the model is fine-tuned for `"patience_epochs"` number of epochs. The process is continued until the search algorithm terminates. The returned model is the model with the highest compression rate encountered, which satisfies the accuracy drop criterion - the accuracy drop of the compressed model should not be more than `"maximal_relative_accuracy_degradation`" or "`maximal_absolute_accuracy_degradation`".
The second one is **Finding the optimal compression rate**, where the next compression rate value is determined by the search algorithm and the model is fine-tuned for a maximum of `"patience_epochs"` number of epochs. Fine-tuning may end earlier, if the accuracy criteria has been reached. The process is continued until the search algorithm terminates. The returned model is the model with the highest compression rate encountered, which satisfies the accuracy drop criterion - the accuracy drop of the compressed model should not be more than `"maximal_relative_accuracy_degradation`" or "`maximal_absolute_accuracy_degradation`".

## Compression rate search algorithm

Expand All @@ -64,3 +65,6 @@ The step value is decreased by the `"compression_rate_step_reduction_factor"` va
That is, if a too big of an increase in compression rate resulted in the accuracy metrics below the user-defined criterion, the compression rate is reduced by a lower step in an attempt to restore the accuracy and vice versa, if the decrease was sufficient to satisfy the accuracy criterion, the compression rate is increased by a lower step to check if this higher compression rate could also result in tolerable accuracy values.
This sequential search is limited by the minimal granularity of the steps given by `"minimal_compression_rate_step"`.

## Example
An example of how model is compressed using Adaptive Compression Training Loop is given on the figure below.
![Example](actl_progress_plot.png)
3 changes: 3 additions & 0 deletions docs/accuracy_aware_model_training/actl_progress_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8b53a8b

Please sign in to comment.