Skip to main content

Quantization algorithms to compress aidge networks.

Project description

Aidge Quantization Module

You can find in this folder the library that implements the quantization algorithms. For the moment only Post Training Quantization (PTQ) is available. Its implementation does support multiple branch architectures.

[TOC]

Installation

Dependencies

  • GCC
  • Make/Ninja
  • CMake
  • Python (optional, if you have no intend to use this library in python with pybind)

Aidge dependencies

  • aidge_core The requirements for installing the library are the followings:

    • GCC, Make and CMake for the compilation pipeline
    • The AIDGE modules aidge_core, aidge_onnx and aidge_backend_cpu
    • Python (> 3.7) if you intend to use the pybind wrapper

Configuration of environment variables

Variable Default value Description
AIDGE_INSTALL Path to the installation folder of Aidge, must be the same used for all aidge dependencies
AIDGE_C_COMPILER gcc C Compiler to use
AIDGE_CXX_COMPILER g++ CXX Compiler to use
AIDGE_BUILD_TYPE Release Can either be Release or Debug
AIDGE_ASAN OFF Compile with ASAN for debug
AIDGE_WITH_CUDA ON Compile CUDA kernel for quantization, requires nvcc and aidge_bakcend_cuda
AIDGE_CMAKE_ARCH "" Append architecture-specific arguments if provided
AIDGE_BUILD_GEN "" To specify a CMake generator (for example Ninja)

Pip installation

pip install . -v

TIPS : Use environment variables to change compilation options :

  • AIDGE_INSTALL : to set the installation folder. Defaults to /usr/local/lib. :warning: This path must be identical to aidge_core install path.
  • AIDGE_BUILD_TYPE : to set the compilation mode to Debug or Release
  • AIDGE_WITH_CUDA : if your computer hasn't graphical card, don't forget to set if OFF
  • AIDGE_BUILD_GEN : to set the build backend with

User guide

In order to perform a quantization, you will need an AIDGE model (that can be loaded from an ONNX). Then, you will have to provide a calibration dataset consisting of AIDGE tensors (that can be loaded from some numpy arrays). And finally, you will have to specify the quantization number of bits.

Performing the PTQ on your model will then be a one liner:

aidge_quantization.quantize_network(aidge_model, nb_of_bits, calibration_set)

Technical insights

The PTQ algorithm consists of 3 main steps:

- Normalization of the parameters, so that each node set of weights fits in the [-1:1] range.
- Normalization of the activations, so that each node output value fits in the [-1:1] range.
- Quantization of the scaling nodes previously inserted

To achieve those steps, one must propagate the scaling factors inside the network. One should also balance the different branches when they are merging. A particular care is needed for the biases rescaling at each step.

Doing quantization step by step

It is possible to perform the PTQ step by step, thanks to the exposed functions of the API. In that case, here is the standard pipeline:

- Prepare the network for the PTQ (remove the flatten nodes, fuse the BatchNorms ...)
- Insert the scaling nodes that will allow the model calibration
- Perform the Cross Layer Equalization if possible
- Perform the parameter normalization
- Compute the node output ranges over an input calibration dataset
- Adjust the output ranges using a specified error metric (MSE, KL, ...)
- Perform the activation normalization
- Quantize the normalized network
- Convert the scaling factors to bit-shifting operations if needed

Further work

  • add Quantization Aware Training (QAT)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

aidge_quantization-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

aidge_quantization-0.5.0-cp312-cp312-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

aidge_quantization-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

aidge_quantization-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

Details for the file aidge_quantization-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a51b498144413f654d81a15e612341a9260956df90ce8386343daf0726f101e
MD5 08ff5c8a95b38efbdfb8ff493afc75e2
BLAKE2b-256 60ac0aa455792512ec36e80e67cad8a6e15a762b018db96e180fad1577b3b66c

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.5.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.5.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5e9635714b6fcc3ff2faaae9b70632874d2f6743e2b1a864df57ce56bf2cda1f
MD5 c22087aa1e0d39d1c7fbd3489ae2237b
BLAKE2b-256 43fdd018d7f096b43bc90d99135db8d909163789c90e5bfc5ffd3091470d434e

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e7939eb37e55451a5169f1568778b80facab15c19c6a3216e1c1df4520ffd8fb
MD5 ab3a070f028480179b5993906e5617c9
BLAKE2b-256 dbc9cb03a9daef2c8907dd030589e3bcb3e2ed3a0b672c602b17384ad4481733

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.5.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a9e5f4372fbd85e46778e2fea94906ce40da97f3540889bae68fc41260e94cd
MD5 467d23965d9f402c80272b53875709a7
BLAKE2b-256 fce77ceb568ffe777f06e66a233f0e0be6b6d325ebe71e14bc4f083ec2270a1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page