Skip to main content

train neural networks with joint quantization and pruning on both weights and activations using any pytorch modules

Project description

QSPARSE

License: MIT

QSPARSE provides the open source implementation of the quantization and pruning methods proposed in Training Deep Neural Networks with Joint Quantization and Pruning of Weights and Activations. This library was developed to support and demonstrate strong performance among various experiments mentioned in our paper, including image classification, object detection, super resolution, and generative adversarial networks.

Full Precision Joint Quantization 8bit and Pruning 50%
import torch.nn as nn

net = nn.Sequential(
    nn.Conv2d(3, 32, 5),
    nn.ReLU(),
    nn.ConvTranspose2d(32, 3, 5, stride=2),
)
import torch.nn as nn
from qsparse import prune, quantize

net = nn.Sequential(
    quantize(bits=8),  # input quantization
    quantize(prune(nn.Conv2d(3, 32, 5), 0.5), 8),  # weight pruning+quantization
    prune(sparsity=0.5),  # activation pruning
    quantize(bits=8),  # activation quantization
    nn.ReLU(),
    quantize(prune(nn.ConvTranspose2d(32, 3, 5, stride=2), 0.5), 8),
    quantize(bits=8),
)

It can be seen from the above snippet that our library provides a much simpler and more flexible software interface comparing to existing solutions, e.g. torch.nn.qat. More specifically, our library is layer-agnostic and can work with any PyTorch module as long as their parameters can be accessed from their weight attribute, as is standard practice.

Installation

QSPARSE can be installed from PyPI:

pip install qsparse

Usage

Documentation can be accessed from Read the Docs.

Examples of applying QSPARSE to different tasks are provided at qsparse-examples.

Contribute

The development environment can be setup as (Python >= 3.6 is required):

git clone https://github.com/mlzxy/qsparse
cd qsparse
make dependency
pre-commit install

Feel free to raise an issue if you have any questions.

Citing

If you find this open source release useful, please reference in your paper:

Zhang, X., Colbert, I., Kreutz-Delgado, K., & Das, S. (2021). Training Deep Neural Networks with Joint Quantization and Pruning of Weights and Activations. arXiv preprint arXiv:2110.08271.

@article{zhang2021training,
  title={Training Deep Neural Networks with Joint Quantization and Pruning of Weights and Activations},
  author={Zhang, Xinyu and Colbert, Ian and Kreutz-Delgado, Ken and Das, Srinjoy},
  journal={arXiv preprint arXiv:2110.08271},
  year={2021}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qsparse-1.2.3.tar.gz (71.9 kB view details)

Uploaded Source

File details

Details for the file qsparse-1.2.3.tar.gz.

File metadata

  • Download URL: qsparse-1.2.3.tar.gz
  • Upload date:
  • Size: 71.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for qsparse-1.2.3.tar.gz
Algorithm Hash digest
SHA256 3b9d6b9646d9c423e9cc1774bcaffec2be007e7057e110869ec27a6763f59a57
MD5 a94f3a53dd08794194a3dc209488b65d
BLAKE2b-256 e27367827f1a2729aedfe03e1f65f6ed6affbc12e15e375af07b17bcbd1cee7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page