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

[!TIP] Use Get-Help setup.ps1 (Windows) or ./setup.sh -h (Unix) for full documentation.

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/

[!TIP] Create a CMakeUserPresets.json to define your own local build configurations.

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)

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.10.0.post3-cp312-cp312-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.12Windows x86-64

aidge_quantization-0.10.0.post3-cp312-cp312-manylinux_2_28_x86_64.whl (59.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

aidge_quantization-0.10.0.post3-cp311-cp311-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.11Windows x86-64

aidge_quantization-0.10.0.post3-cp311-cp311-manylinux_2_28_x86_64.whl (59.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

aidge_quantization-0.10.0.post3-cp310-cp310-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.10Windows x86-64

aidge_quantization-0.10.0.post3-cp310-cp310-manylinux_2_28_x86_64.whl (59.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

Details for the file aidge_quantization-0.10.0.post3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.10.0.post3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c09556847ee43cce179d107a9dc10158600e275172debffe67efecbf54213279
MD5 738bd0e60a44216b80ea3330f3d59358
BLAKE2b-256 52f8c830dacacd701b211c19b70daa9f6dddd2d2c61d931c185b0295cfbac779

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.10.0.post3-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.10.0.post3-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 92f7d37e375d01cd9960ef37a6d9da0fadaa701f72a4f5669dabd137f414f800
MD5 c584438d1316f1112fe2df672906a59e
BLAKE2b-256 3f077e09186f2967297f263b2dc2db2cf7fdb5c0db5ce1f5191d4e9d954a974b

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.10.0.post3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.10.0.post3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f49984dfe4ba983e3deedb4cd7e602c75e0ca5123f9a15b33cb0362b15daecdd
MD5 f2c594ab3c58c78e85955f75cdbf089b
BLAKE2b-256 a16a87f4477c53276fbcad8a4ba3e7ae38568c852c3d04cb135b33e9f7472ec1

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.10.0.post3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.10.0.post3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e9a71ce292d3d79b68e7a7cde307b9751278dfdc80b0e63a736495cf5ae020a4
MD5 a2cff8e6cb704b99faef36e7d33e8e05
BLAKE2b-256 096286e0b2332a3a207533084c98988bdfeca0c48bb3e3a87bb62dbb8b5aab4d

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.10.0.post3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.10.0.post3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fe4e059c1173b6dff0c85740e6d12929794046167bcc64470a80ab777a4035cd
MD5 62011a43516226917856d6636aadf31a
BLAKE2b-256 ea3af8bec7409aeee03354cb8722b46e58d1018ff6fd7fc5cdbe1777280445e0

See more details on using hashes here.

File details

Details for the file aidge_quantization-0.10.0.post3-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aidge_quantization-0.10.0.post3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 04d06c7330cf00c04baeee7a7f180dc1ff98a12b6c85c1a5c17e9561b9ac2d27
MD5 3b41e8eacae40352d49a8484d1792786
BLAKE2b-256 6cfd8e69d90bc257b6cb7287909bd9907fe60ccbe7f81ccb5abfc1145314bb09

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.10.0.post3 This release

6 files

0.10.0.post2

6 files

0.10.0

6 files

0.9.1.post2

3 files

0.9.0.post3

6 files

0.9.0.post2

6 files

0.9.0

6 files

0.5.0

4 files

0.4.2

4 files

0.4.1

4 files

0.4.0

4 files

0.3.1

6 files

Supported by

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