Metadata-Version: 2.5
Name: colibry-npu
Version: 0.2.1
Summary: Colibry NPU compiler
Project-URL: Homepage, https://ai.asygn.com
Project-URL: Issues, https://gitlab.eclipse.org/eclipse/aidge/aidge_export_colibry/-/issues
License: Copyright (c) 2020 - 2026 Asygn SAS
        
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without modification,
        are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form, except as embedded into a Asygn SAS
           integrated circuit in a product or a software update for such product, must
           reproduce the above copyright notice, this list of conditions and the 
           following disclaimer in the documentation and/or other materials provided
           with the distribution.
        
        3. Neither the name of Asygn SAS nor the names of its contributors may be used
           to endorse or promote products derived from this software without specific
           prior written permission.
        
        4. This software, with or without modification, must only be used with a Asygn
           SAS integrated circuit.
        
        5. Any software provided in binary form under this license must not be reverse
           engineered, decompiled, modified and/or disassembled.
        
        THIS SOFTWARE IS PROVIDED BY ASYGN SAS "AS IS" AND ANY EXPRESS
        OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL ASYGN SAS OR CONTRIBUTORS BE
        LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
        GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
        OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Keywords: Asygn,Colibry,ColibryNPU,NNPA,NPU
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Hardware
Requires-Python: >=3.12
Requires-Dist: crcmod>=1.7
Requires-Dist: datasets>=4.7.0
Requires-Dist: matplotlib>=3.9.4
Requires-Dist: numpy>2.2
Requires-Dist: onnx-graphsurgeon>=0.5.8
Requires-Dist: onnx2tf==1.6
Requires-Dist: onnx>=1.21.0
Requires-Dist: pandas>=2.3.3
Requires-Dist: pillow>=13.0.0
Requires-Dist: tensorflow-model-optimization==0.8.1
Requires-Dist: tensorflow>=2.18.1
Requires-Dist: tf-keras>=2.16; python_version == '3.12'
Requires-Dist: tflite>=2.18.0
Requires-Dist: torch<2.12.0
Requires-Dist: torchao>=0.18.0
Description-Content-Type: text/markdown

# Colibry NPU Compiler

**`colibry-npu`** provides quantization and compilation tools for deploying neural networks on the **Asygn Colibry NPU**. The `nnpa-compiler` converts compatible models into `.nnpa` bitstreams containing the network configuration and weights.

## Installation

Requires **Python >= 3.12**.

```sh
pip install colibry-npu
# or
uv add colibry-npu
```

For standalone CLI usage:

```sh
uv tool install --python 3.12 colibry-npu
# or, without installing:
uvx --python 3.12 --from colibry-npu nnpa-compiler --help
```

## Supported formats

| Framework / format | Input | Support |
|--------------------|-------|---------|
| TensorFlow / Keras | Keras model | Model compilation and PTQ/QAT |
| TFLite | `.tflite` | Model compilation and PTQ |
| ONNX | `.onnx` | Model compilation and PTQ |
| PyTorch | `.pt2` (`ExportedProgram`) | Model compilation and PTQ/QAT |

Models must use operators and quantization schemes compatible with the Colibry NPU.

### TensorFlow compatibility

Compatible TensorFlow versions by Python version (TensorFlow is installed automatically):

| Python Version | Compatible TensorFlow Versions |
|----------------|--------------------------------|
| `3.9` to `3.11` | Unsupported |
| `3.12` | `>= 2.20.0` and `< 2.22.0` |
| `3.13` | `>= 2.20.0` and `< 2.22.0` |
| `3.14` | `>= 2.22.0rc0` (beta) |
| `3.15` | Not supported yet |

### Quantization

The package includes format-specific quantization utilities:

| Module | Quantization support |
|--------|----------------------|
| `custom_quantization_tf` | Quantization-aware training (QAT) for Keras models, with custom layer quantization configurations. |
| `custom_quantization_tflite` | Post-training quantization (PTQ) to TFLite using representative `.npz` calibration data; supports full-integer conversion and optional evaluation. |
| `custom_quantization_onnx` | Static ONNX quantization with ONNX Runtime, using a calibration dataset and QDQ representation by default. |
| `custom_quantization_torch` | PTQ and QAT with a Colibry-specific TorchAO quantizer, targeting hardware-compatible quantization. Export the resulting model as a `.pt2` `ExportedProgram` for compilation. |

Quantization does not guarantee that every model is compilable: operators and tensor configurations must also be supported by the NPU backend.

## Compiler usage

Compile a model by passing its path:

```sh
nnpa-compiler model_directory/  # TensorFlow/Keras
nnpa-compiler model.onnx        # ONNX
nnpa-compiler model.tflite      # TFLite
nnpa-compiler model.pt2         # PyTorch
```

For TensorFlow/Keras or PyTorch, Post-Training Quantization (PTQ) can be applied to a **floating-point model** using representative calibration data. The compiler then generates the corresponding **`.nnpa` bitstream**.

```sh
nnpa-compiler model_directory/ --apply_ptq --calibration-npz calibration.npz   # TensorFlow/Keras (FP32 → NNPA)
nnpa-compiler model.pt2 --apply_ptq --calibration-npz calibration.npz          # PyTorch (FP32 → NNPA)
```

For all compiler options:

```sh
nnpa-compiler --help
```

### Python usage

```python
from colibry_npu.nnpa_compiler import nnpa_compiler

nnpa_compiler.main("model.pt2") # Direct compilation (e.g. a quantized PyTorch ExportedProgram)
```