Module for compressing Convolutional Neural Networks in Aidge.
Project description
Aidge Compression Module
A module for compressing Convolutional Neural Networks (CNNs).
This module decomposes convolutional layers into multiple smaller convolution operations, reducing the total number of computations and improving inference speed.
It provides a C++/Python interface for compression.
Installation
Work in progress — PyPI packages are not yet available.
From GitLab Package Registry (recommended)
The wheels are published to the Aidge GitLab Package Registry on every push to main (pre-release .dev0) and on tag commits (stable release).
Requires a GitLab personal access token with read_api scope (set as GITLAB_TOKEN):
export GITLAB_TOKEN=<your_personal_access_token>
# Install latest stable release
pip install aidge_compression \
--index-url https://gitlab.eclipse.org/api/v4/projects/eclipse%2Faidge%2Faidge_compression/packages/pypi/simple
# Install latest pre-release (dev version)
pip install --pre aidge_compression \
--index-url https://gitlab.eclipse.org/api/v4/projects/eclipse%2Faidge%2Faidge_compression/packages/pypi/simple
# Install a specific version
pip install aidge_compression==0.0.5 \
--index-url https://gitlab.eclipse.org/api/v4/projects/eclipse%2Faidge%2Faidge_compression/packages/pypi/simple
The dependencies
aidge_coreandaidge_backend_cpuare also published to the monorepo GitLab Package Registry. Add the monorepo index as well so pip can resolve them:
pip install aidge_compression \
--index-url https://gitlab.eclipse.org/api/v4/projects/eclipse%2Faidge%2Faidge_compression/packages/pypi/simple \
--extra-index-url https://gitlab.eclipse.org/api/v4/projects/eclipse%2Faidge%2Faidge/packages/pypi/simple
From PyPI (planned)
pip install aidge_compression
From source
Requires aidge_core and aidge_backend_cpu to be installed first (from GitLab Package Registry, PyPI, or built from source):
pip install aidge_core aidge_backend_cpu
pip install .
Requirements
System
- Python >= 3.10
- C++17 compiler (GCC, Clang, MSVC)
- CMake >= 3.22
- OpenMP support
Python dependencies (installed automatically)
| Package | Version |
|---|---|
| numpy | >= 1.21.6 |
| aidge_core | any |
C++ dependencies (fetched automatically at build time)
| Library | Version | Purpose |
|---|---|---|
| Eigen | 3.4.0 | Linear algebra |
| nlohmann/json | 3.11.3 | JSON parsing |
| pybind11 | >= 3.0 | Python bindings |
Aidge ecosystem
| Package | Role |
|---|---|
| aidge_core | Core graph, operators, tensor infrastructure |
| aidge_backend_cpu | CPU backend (required for compression evaluation) |
Building from source
# With Python bindings (default)
pip install .
# C++ only, without Python
cmake -B build -DPYBIND=OFF
cmake --build build
# With tests
cmake -B build -DTEST=ON
cmake --build build
ctest --test-dir build
CMake options:
| Option | Default | Description |
|---|---|---|
PYBIND |
ON | Build Python bindings |
WERROR |
ON | Treat warnings as errors |
TEST |
OFF | Build C++ unit tests |
COVERAGE |
OFF | Enable code coverage (GCC only) |
Usage
Example usage with resnet18, where the first convolution is ignored, and manual ranks are assigned to specific layers (-1 ignores the layer, [0.,1.] represents a weakening factor):
import aidge_core
import aidge_onnx
import aidge_compression
model = aidge_onnx.load_onnx("resnet18.onnx")
ignores = {"conv1_Conv"}
ranks = {
"layer1_layer1_1_conv1_Conv": -1.,
"layer2_layer2_0_conv1_Conv": -1.,
}
aidge_compression.Compressor(ignores, ranks, 0.8).compress(model)
aidge_onnx.export_onnx(
model,
"resnet18_0.8.onnx",
inputs_dims={
list(model.get_input_nodes(aidge_core.InputCategory.Data))[0].name(): [
[1, 3, 224, 224]
]
},
outputs_dims={list(model.get_output_nodes())[0].name(): [[1, 100]]},
opset=18,
)
A more complete set of examples to use this module is provided in the examples/ folder, including a tutorial notebook.
Compression methods
This module compresses CNNs through tensor decomposition, replacing a single convolutional tensor with multiple smaller tensors, reducing computational complexity.
{width=50%}
The process starts with rank selection for each layer's decomposition:
-
Without a training dataset: The module uses VBMF to estimate the rank for each layer.
-
With a training dataset: It leverages inference on the dataset to assess the impact of decomposition on each layer.
-
With a partial dataset: The method can still use the available data, but it's preferable to ensure the dataset represents various cases the network will encounter.
Following rank selection, each layer undergoes Tucker-2 decomposition or WeightSVD:
{width=50%}
-
WeightSVD: Applied to 2D tensors, replacing a single tensor with two smaller ones.
-
Tucker-2: Applied to 4D tensors, replacing a 4D tensor with two 2D tensors and a smaller 4D tensor.
TODO list
- Tucker-2 implementation.
- VBMF rank automatic selection.
- Weight SVD for linear tensors.
- Validation dataset aided rank selection.
- CP decomposition
- Automatic hybrid selection between CP / Tucker
- Robust network decomposition
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aidge_compression-0.0.5.dev0-cp313-cp313-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: aidge_compression-0.0.5.dev0-cp313-cp313-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 831.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1d3195ca82f2bbee36a0f80899770631253f9c055e9ffbe5ab3fdac8cf700d8
|
|
| MD5 |
7d4e690640a33d700895622fa98b6e1d
|
|
| BLAKE2b-256 |
8498bef465851e46226661ac4521370a6cce1a84a20b0bcfb8be5df299fb3900
|
File details
Details for the file aidge_compression-0.0.5.dev0-cp312-cp312-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: aidge_compression-0.0.5.dev0-cp312-cp312-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 831.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a6223f0f4c9fb8edccbbbd4668fe9e59271e5b31bc52bf3d59ac11276526864
|
|
| MD5 |
47d6aa9e26e55b08a86739eb9e3dea17
|
|
| BLAKE2b-256 |
1874bcdc9324e5eae2b20059c2ca6c05008d57dcf34c6fdb1f337c5a7517890a
|
File details
Details for the file aidge_compression-0.0.5.dev0-cp311-cp311-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: aidge_compression-0.0.5.dev0-cp311-cp311-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 825.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5156505d32f5e2ee1d55b63c29e51ebf9c520dd2357277b5d9e33588f61fdaa3
|
|
| MD5 |
5fe0a3b4cc5f0303654a1d2d4b4d0db4
|
|
| BLAKE2b-256 |
067a479463b0ff14fbda5045fc3a671cafb5d25528c6750547a6c06bb99da9b5
|
File details
Details for the file aidge_compression-0.0.5.dev0-cp310-cp310-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: aidge_compression-0.0.5.dev0-cp310-cp310-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 820.6 kB
- Tags: CPython 3.10, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43baa9e33bc6c37c981a212620b2ed8185ae49c709108ee7e20b59c7cc61780b
|
|
| MD5 |
f86b7e59e49b8e5099b3c1930275bbb9
|
|
| BLAKE2b-256 |
6d32c9f06d0a2bde1b9accb00c98b39606571e6af3f1674607f0ab635cc77944
|