Skip to the content.

Data Generation Library for Model Compression Toolkit (MCT)

The Data Generation Library for the Model Compression Toolkit (MCT) is a powerful Python package designed to facilitate the generation of synthetic data. This library leverages the statistics stored in the model’s batch normalization (BatchNorm) layers to create synthetic data that faithfully represent the model’s training data characteristics. This generated data is valuable for various compression tasks where representative data of the model’s training set is needed, such as quantization and pruning.

Key Features

Installation

To install the package, you can use pip and install the latest stable release of the Model Compression Toolkit:

pip install model-compression-toolkit

Usage

PyTorch

Explore a Jupyter Notebook example showcasing data generation with ResNet18, including visualizations, and a practical example of Post Training Quantization:

Below, you will find a straightforward usage example:

import model_compression_toolkit as mct

# Set the configuration parameters for data generation
data_gen_config = mct.data_generation.get_pytorch_data_generation_config(
    n_iter=500,                               # Number of iterations
    data_gen_batch_size=32,                   # Batch size for data generation
    extra_pixels=32,                          # image manipulation when generating data                                                     
    # ... (other configuration parameters)
)

# Call the data generation function to generate images
generated_images = mct.data_generation.pytorch_data_generation_experimental(
    model=my_model,                          # PyTorch model to generate data for
    n_images=1024,                           # Number of images to generate
    output_image_size=224,                   # Size of the output images
    data_generation_config=data_gen_config   # Configuration for data generation
)

Keras

import model_compression_toolkit as mct

# Set the configuration parameters for data generation
data_gen_config = mct.data_generation.get_keras_data_generation_config(
    n_iter=500,  # Number of iterations
    data_gen_batch_size=32,  # Batch size for data generation
    extra_pixels=32,  # image manipulation when generating data                                                     
    # ... (other configuration parameters)
)

# Call the data generation function to generate images
generated_images = mct.data_generation.keras_data_generation_experimental(
    model=my_model,  # PyTorch model to generate data for
    n_images=1024,  # Number of images to generate
    output_image_size=224,  # Size of the output images
    data_generation_config=data_gen_config  # Configuration for data generation
)

Configuration Parameters

The get_pytorch_data_generation_config() and get_keras_data_generation_config() functions allow you to customize various configuration parameters for data generation. Here are the essential parameters that can be tailored to your specific needs:

Results Using Generated Data

PyTorch

Experimental setup

Quantization Algorithms

Four quantization algorithms were utilized to evaluate the generated data:

All setups were tested with symmetric weights and uniform activation quantizers.

To ensure reliable results, all experiments were averaged over 5 different random seeds (0-4).

Data Generations Parameters

The evaluation was performed on the following neural network models:

The quantization algorithms were tested using three different data types as input: real data, random noise, and generated data. The generated data was produced using the default data generation configuration with 500 iterations (better results may be achieved with a larger iteration budget).

Please note that the choice of quantization algorithms and data generation parameters can have a significant impact on the results. The experimental setup provides a foundation for comparing the performance of different models and quantization techniques using the generated data.

Model (float) Resnet18 (69.86) Resnet18 (69.86) Resnet18 (69.86) Resnet18 (69.86) Mobilenet v2 (71.89) Mobilenet v2 (71.89) Mobilenet v2 (71.89) Mobilenet v2 (71.89) Yolo-v8-n (37.26) Yolo-v8-n (37.26) Yolo-v8-n (37.26)
Data type (rows) \ Quantization algorithm (columns) PTQ W8A8 MP compression x 8 PTQ LUT W4A8 GPTQ W4A8 PTQ W8A8 MP compression x 8 PTQ LUT W4A8 GPTQ W4A8 PTQ W8A8 PTQ LUT W4A8 GPTQ W4A8
Real Data 69.49 58.48 66.24 69.30 71.168 64.52 64.4 70.6 36.23 29.79 25.82
Random Noise 8.3 43.58 12.6 11.13 7.9 30.02 7.14 11.30 27.45 4.15 2.68
Image Generation 69.51 58.57 65.70 69.07 70.155 62.82 62.49 69.59 35.12 27.77 25.02

Keras

Experimental setup

Quantization Algorithms

Post Training Quantization (PTQ) algorithm was utilized to evaluate the generated data:

All experiments were tested with symmetric weights and Power-Of-Two activation quantizers.

To ensure reliable results, all experiments were averaged over 5 different random seeds (0-4).

Data Generations Parameters

The evaluation was performed on the following neural network models:

The quantization algorithms were tested using three different data types as input: real data, random noise, and generated data. The generated data was produced using the default data generation configuration with 500 iterations (better results may be achieved with a larger iteration budget).

Model (float) Mobilenet (70.558) Mobilenetv2 (71.812)
Data type (rows) \ Quantization algorithm (columns) PTQ W8A8 PTQ W8A8
Real Data 70.427 71.599
Random Noise 58.938 70.932
Image Generation 70.39 71.574