Simplify
Simplification of pruned models for accelerated inference.
Fully supports torchvision classification models up to version 0.11.
Installation
Simplify can be installed using pip:
pip3 install torch-simplify
or if you want to run the latest version of the code, you can install from git:
git clone https://github.com/EIDOSlab/simplify
cd simplify
pip3 install -r requirements.txt
Usage
Main function
For most scenarios the main simplify function will suffice. This function returns the simplified model.
Arguments
The expected arguments are:
model (torch.nn.Module): Module to be simplified i.e. the PyTorch's model.x (torch.Tensor): zero-tensor of shape[1, C, N, M], same as the model usual input.bn_folding (List): List of tuple (nn.Conv2d,nn.BatchNorm2d) to be fused. If None it tries to evaluate them given the model. DefaultNone.fuse_bn (bool): If True, fuse the conv-bn tuple.pinned_out (List): List ofnn.Moduleswhich output needs to remain of the original shape (e.g. layers related to a residual connection with a sum operation).
Minimal working example
import torch
from torchvision import models
from simplify import simplify
model = models.resnet18()
# Apply some pruning strategy or load a pruned checkpoint
dummy_input = torch.zeros(1, 3, 224, 224) # Tensor shape is that of a standard input for the given model
simplified_model = simplify(model, dummy_input)
Submodules
The simplify function is composed of three different submodules: fuse, propagate and remove. Each module can be
used independently as needed.
fuse
Fuses adjacent Conv (or Linear) and BatchNorm layers.
propagate
Propagates non-zero bias of pruned neurons to remaining neurons of the next layers.
remove
Removes zeroed neurons from the architecture.
Citing
If you use this software for research or application purposes, please use the following citation:
@article{bragagnolo2021simplify,
title = {Simplify: A Python library for optimizing pruned neural networks},
journal = {SoftwareX},
volume = {17},
pages = {100907},
year = {2022},
issn = {2352-7110},
doi = {https://doi.org/10.1016/j.softx.2021.100907},
url = {https://www.sciencedirect.com/science/article/pii/S2352711021001576},
author = {Andrea Bragagnolo and Carlo Alberto Barbano},
}
Metadata
Release files for torch-simplify 1.1.4
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 |
|---|---|---|---|---|
| torch-simplify-1.1.4.tar.gz | 12.9 kB | Without provenance | Details for torch-simplify-1.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torch_simplify-1.1.4-py3-none-any.whl | Python 3 | none | any | Details for torch_simplify-1.1.4-py3-none-any.whl |
Total release size: 29.4 kB
Release files / torch-simplify-1.1.4.tar.gz
| Download URL | torch-simplify-1.1.4.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
945a2448b79dd90f8d9d671028a235fa73be71e573f993e9bfe454ddf307a7cc
|
|
BLAKE2b-256 checksum How to use checksums |
a54feb5e00a46092152bd7b68cf210aa714108ffa3d563b8145e14967da3894b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / torch_simplify-1.1.4-py3-none-any.whl
| Download URL | torch_simplify-1.1.4-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f7dc4efccacba0b0a67ba791424f49a9e09269cf54216b1a27b0767b79968135
|
|
BLAKE2b-256 checksum How to use checksums |
352dec9d2cdea80d60c0dfda6a5c64abf924f3cb75625f7d02dcf6629f66d744
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for torch-simplify 1.1.4
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.