Catalog PyPI
PACKAGE EXPLORERView in registry

aidge-compression

PyPI

Module for compressing Convolutional Neural Networks in Aidge.

Versions collected1
Direct dependencies4From release 0.0.5.dev0
Last observed21 Oct, 10:28 UTC

README

Version 0.0.5.dev0 documentation

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.

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_core and aidge_backend_cpu are 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)

PackageVersion
numpy>= 1.21.6
aidge_coreany

C++ dependencies (fetched automatically at build time)

LibraryVersionPurpose
Eigen3.4.0Linear algebra
nlohmann/json3.11.3JSON parsing
pybind11>= 3.0Python bindings

Aidge ecosystem

PackageRole
aidge_coreCore graph, operators, tensor infrastructure
aidge_backend_cpuCPU 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:

OptionDefaultDescription
PYBINDONBuild Python bindings
WERRORONTreat warnings as errors
TESTOFFBuild C++ unit tests
COVERAGEOFFEnable 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.

Module internal pipeline{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:

Tucker2 decomposition.{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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.0.5.dev01 Jul 20264

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 10:28 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:7ae36d48eb26cb344cb9b5843fa70aca30ffa5ea2d01219573ba41fa95a6a1dd