Model Compression#

User can compress the model parameters using the following lossy compression techniques:

Installation#

User can install the compressors by running the following command:

appfl-install-compressor

Note

SZx is not open source so we omit its installation here. Please install it manually by contacting the author.

Configuration#

User can create a compressor instance by providing a Config object and setting necessary parameters. The following example shows how to create a SZ2 compressor instance:

from appfl.config import Config
from appfl.compressor import Compressor

# set the configuration
config = Config()
config.enable_compression = True
config.lossy_compressor = "SZ2"         # ["SZ2", "SZ3", "ZFP", "SZx"]
config.lossless_compressor = "blosc"    # ["blosc", "zstd", "gzip", "zlib", "lzma"]
config.error_bounding_mode = "REL"      # ["ABS", "REL"]
config.error_bound = 1e-3

# create the compressor instance
compressor = Compressor(config)

Usage#

User can compress the model parameters by calling the compress_model method of the Compressor instance. To decompress the model parameters, use can call the decompress_model method by providing the compressed model parameters and a model instance (as a reference to the model architecture).

# create a CNN model
cnn = CNN(num_channel=3, num_classes=10, nun_pixel=32)

# compress the model parameters
compressed_model, lossy_elements = compressor.compress_model(cnn.state_dict())

# decompress the model parameters
decompressed_model = compressor.decompress_model(compressed_model, model)

Note

The CNN model used in the above example is defined as follows: