ShrinkAI
ShrinkAI is a package for reducing neural networks size, making them ideal to run on small devices such as smartphones or robots, and for speeding up inference, particularly interesting for edge AI. This package includes, among other things, numerous distillation and compression techniques, all wrapped in an API that is easy to use for users familiar with PyTorch.
Installation
ShrinkAI is on pypi and can be installed with the following command:
pip install shrinkai
The package is compatible with Python 3.11+, and depends on torch, torchvision, rich, tqdm, and psutil. Exporting to ONNX additionally requires the export extra:
pip install shrinkai[export]
Quick Start
Distilling a smaller student model from a larger teacher only takes a Distiller and a loss:
from shrinkai.distillation import Distiller
from shrinkai.distillation.losses import HintonLoss
# teacher, student: your PyTorch models. train_loader: your DataLoader.
distiller = Distiller(
teacher=teacher,
student=student,
criterion=HintonLoss(),
optimizer="adamw",
)
distiller.fit(train_dataloader=train_loader, epochs=10)
distiller.save_student("student.pt")
shrinkai also covers pruning, quantization, benchmarking, and exporting the trained model for deployment (ONNX, TorchScript). See the full documentation for the complete quick start, tutorials, and API reference.
Architecture
There is no flat top-level API: everything is imported from its submodule, e.g. from shrinkai.distillation import Distiller.
| Module | What it provides |
|---|---|
shrinkai.distillation |
Distiller (facade), DistillationEngine, training callbacks, and a library of losses under shrinkai.distillation.losses |
shrinkai.adapters |
FeatureExtractor (hook-based intermediate activations) and dimension-matching projectors |
shrinkai.analysis |
Representation alignment metrics between teacher and student (CKA, RSA, Spatial Attention) |
shrinkai.compression |
Pruner / ChannelPruner (mask-based and physical pruning) and Quantizer (PTQ/QAT) |
shrinkai.profiler |
Profiler, count_flops, latency and memory measurement |
shrinkai.export |
export_onnx, export_torchscript for deployment outside PyTorch |
Examples
The docs/tutorials/ folder has six runnable notebooks, from a basic distillation walkthrough to full deployment:
| # | Notebook | Covers |
|---|---|---|
| 01 | Distillation on CIFAR10 | HintonLoss, FeatureLoss, combining losses |
| 02 | Distillation on SST-2 | Adapting HuggingFace models, AttentionMapLoss |
| 03 | LLM text generation | ReverseKLLoss, mismatched tokenizers, sequence-level KD |
| 04 | Compression | Pruner, ChannelPruner, Quantizer |
| 05 | Full training control | Custom losses, callbacks, AMP, checkpointing, custom engines |
| 06 | Exporting for deployment | export_onnx, export_torchscript |
Contact & Contributing
You can report an issue directly on GitHub. Bug reports, feature requests, and questions are all welcome.
Contributions are welcome too, whether it's a bug fix, a new feature, or a documentation improvement:
- Open an issue first for anything non-trivial, to discuss the approach before you start.
- Fork the repository and work on a dedicated branch.
- Add or update tests for any behavior change (run
uv run pytestlocally before opening a PR). - Keep the code clean:
uv run ruff checkanduv run ruff format. - Open a pull request against
main, CI runs the test suite, coverage, and lint checks automatically.
Citation
If you use ShrinkAI in your work and think it was helpful, please cite it as:
@software{shrinkai2026,
author = {Elouan Marsot},
title = {ShrinkAI},
url = {https://github.com/elouanzer/shrinkai},
license = {MIT},
version = {0.1.0}
}
License
Metadata
Release files for shrinkai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shrinkai-0.1.0.tar.gz | 46.0 kB | With provenance | Details for shrinkai-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shrinkai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for shrinkai-0.1.0-py3-none-any.whl |
Total release size: 108.0 kB
Release files / shrinkai-0.1.0.tar.gz
| Download URL | shrinkai-0.1.0.tar.gz |
|---|---|
| Size | 46.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfcf28320520242819d650949acd62d2d2264d20f6d56c4f0df4878d9c99995a
|
|
BLAKE2b-256 checksum How to use checksums |
e9fde3dbcd55e633e5b4afaf62317c0dfe948e8982ab4dbd655a9fa69c681fb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logRelease files / shrinkai-0.1.0-py3-none-any.whl
| Download URL | shrinkai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 62.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
acab908ff816f4bbe1f753bfab05ff3b7b84b0a8a7e4fae20a29407f241edb14
|
|
BLAKE2b-256 checksum How to use checksums |
e7832cb1c077d3d91aae731f1f376010dfb2d504ea3ad27edb058c7602899949
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logSecurity for shrinkai 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for shrinkai-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.