Skip to main content

Aidge logo

EPL 2.0 Examples PyPi Examples Documentation Status GitLab Contributors Open GitLab Issues Closed GitLab Issues

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.

Prerequisite:

  • aidge_core
  • aidge_backend_cpu
  • aidge_onnx
  • [OPTIONAL] aidge_backend_cuda
pip install aidge-quantization
pip install aidge-quantization[cuda]

🛠 Build from Source

Prerequisite (in addition to previous one):

1. Python or C++ installation using setup scripts

Environment C++ Development Python Development
Windows .\setup.ps1 -Modules quantization -Tests -CppOnly .\setup.ps1 -Modules quantization -Tests
Unix ./setup.sh -m quantization --tests --cpp-only ./setup.sh -m quantization --tests

2. Python Installation using pip

Run these commands from the aidge_quantization/ directory:

# Standard install
pip install . -v

# Install with testing dependencies
pip install .[test] -v && pytest

# Install with cuda dependencies
pip install .[cuda] -v

Editable Install (Experimental)

Use this for real-time development without re-installing.

pip install --no-build-isolation -ve . --config-settings=editable.rebuild=true -Cbuild-dir=build

3. C++ Installation (CMake)

A CMakePresets.json is provided for standard configurations.

# Configure, Build, and Install
cmake --preset clang-debug
cmake --build --preset clang-debug
cmake --install

# Run C++ Tests
ctest --test-dir build/

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)

Metadata

Release files for aidge-quantization 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for aidge-quantization 0.10.1
File
aidge_quantization-0.10.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
aidge_quantization-0.10.1-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
aidge_quantization-0.10.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
aidge_quantization-0.10.1-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
aidge_quantization-0.10.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
aidge_quantization-0.10.1-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
aidge_quantization-0.10.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
aidge_quantization-0.10.1-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details

Total release size: 258.0 MB

Release files / aidge_quantization-0.10.1-cp313-cp313-win_amd64.whl

Download URL aidge_quantization-0.10.1-cp313-cp313-win_amd64.whl
Size 5.3 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
f422e82e7da77c67e02d76afb8434e22759361b91ddf67d0955a99903d30dbe9
BLAKE2b-256 checksum
How to use checksums
f52e80de8521cca6190b269169e4e09a12e1d6994335b22d9ef90d2181b5bc9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / aidge_quantization-0.10.1-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL aidge_quantization-0.10.1-cp313-cp313-manylinux_2_28_x86_64.whl
Size 59.2 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b8cc386d676d047bb4dda6333888a4517eff0ed9dfd0a7ef038f43385f250369
BLAKE2b-256 checksum
How to use checksums
4c5dcf0c0486b0b372cc95341bace89fb35a24b6d0d2808fb80201e16607358e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / aidge_quantization-0.10.1-cp312-cp312-win_amd64.whl

Download URL aidge_quantization-0.10.1-cp312-cp312-win_amd64.whl
Size 5.3 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
cb5048f332436342781b18d8d208fb9f8c059903c5d9496626b549a12808c36e
BLAKE2b-256 checksum
How to use checksums
61c7df609f28ea8d059e14933c741e6c313134ac8810ce7cee4665244c733332
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / aidge_quantization-0.10.1-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL aidge_quantization-0.10.1-cp312-cp312-manylinux_2_28_x86_64.whl
Size 59.2 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e66ca1d2281bf338eadb3922d8db5102d83d966215fdc7a81a8a8b224994b652
BLAKE2b-256 checksum
How to use checksums
b115808515f2fa9f8249ae66eaa957d2bdaff6d11db35e4380be02c793af62cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / aidge_quantization-0.10.1-cp311-cp311-win_amd64.whl

Download URL aidge_quantization-0.10.1-cp311-cp311-win_amd64.whl
Size 5.3 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ebde83f6ecf608be7c70a7ec5861734fcbda8646a663bc9c1509d63a10f7d64c
BLAKE2b-256 checksum
How to use checksums
4052e75a068b4a393a534cd38961a5d8aafc99eb8daaee58eccf0127374c8529
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / aidge_quantization-0.10.1-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL aidge_quantization-0.10.1-cp311-cp311-manylinux_2_28_x86_64.whl
Size 59.2 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ba53dcf7d8b2c29426f48c6a58b4cb68dc63c85a860052086ef3117294a15b36
BLAKE2b-256 checksum
How to use checksums
3db1843dafa83a3c6a9d1849c8b94eeebd47ce464b710370cc950d0fdfa004f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / aidge_quantization-0.10.1-cp310-cp310-win_amd64.whl

Download URL aidge_quantization-0.10.1-cp310-cp310-win_amd64.whl
Size 5.3 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
8d002c0494911a5a3d176fefdd1daa2cd8593c9ac81e7ad3456edbe010c24644
BLAKE2b-256 checksum
How to use checksums
d77dfe11c057af064fe54e27c36de155a32b265898e9816639b1fe5e894e73a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / aidge_quantization-0.10.1-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL aidge_quantization-0.10.1-cp310-cp310-manylinux_2_28_x86_64.whl
Size 59.2 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
95bee295a488c4fca4402366582b784f15523a30b060cffc3fdce0eed7484159
BLAKE2b-256 checksum
How to use checksums
c4b6fe54ea1d42a1aab29271085de24f531735bee888b9db79ba091d8a1c971c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.10.1 This release

8 release files

0.10.0

6 release files

0.9.0

6 release files

0.5.0

4 release files

0.4.2

4 release files

0.4.1

4 release files

0.4.0

4 release files

0.3.1

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page