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_backend_cuda
  • aidge_onnx
pip install aidge-learning

🛠 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

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

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

File metadata

File hashes

Hashes for aidge_quantization-0.10.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b47b7f55050ea0690bca25ef502b95a233d37d4433af954bfd8535a2b390a8e3
MD5 fd62d65075bac1a921f49d93c8438a24
BLAKE2b-256 edef05be49af7d2631b0cef25eefbcde0a41987ce471a29c71dbd77ce1a29b08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aidge_quantization-0.10.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6112ab90a245a3fe4f2ae58c5f5342687c968960780a1763cbf9a8f926fab4d8
MD5 d684b2e5fbb3e39e209d8bcff2a2f480
BLAKE2b-256 e38c5221291e54f4f4df00b616aa64d02fd4348bfb16bb5034af423d2101c417

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aidge_quantization-0.10.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 df5c5627b3379bcbabb872f1a88fa72797221471406e1a59cf4f05482993876d
MD5 b4e3e2d4d72f2c0e3f6eb4eb98e1f399
BLAKE2b-256 690c6e0f1b6dc560fd6b41b45ef6ad47f4b26cf59f4ab30cabf986b030a63ce3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aidge_quantization-0.10.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f29f86096b0a0889a1bc37ed06fbf020f0272e374ed5d4c034cfdb1143cd5f54
MD5 7a8fcf7e701bd5102cca6eb0326ceb95
BLAKE2b-256 cc6516bd337f3bc5b1f17666092cb43a1c3b627c4d6f7e2e2f3f89f699acfd03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aidge_quantization-0.10.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c70f8d4bf48bde4745888b2aefd1991de9458602b4c934ca9b39f94de26ac69d
MD5 4867ed10c8f3de7d02bb5d9f30cd9c67
BLAKE2b-256 469afbf0bcb986115d440fac96212c31b9ce43a0bfbc3bb046c4f2e62b53807e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aidge_quantization-0.10.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e7390909b593a58ea0711de8fe81f0b7431ffd8a6392bd6a9f377bc1ae07ff9a
MD5 3c0fe0ce862f913e61f8d0d619c66006
BLAKE2b-256 35e21665131ca7d2edf69d27a99a074a64052acec40bda8fa0cacbcdeb68075b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.10.0.post3

6 files

0.10.0.post2

6 files

This release

0.10.0 This release

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