musco-ai / musco-pytorch

MUSCO: MUlti-Stage COmpression of neural networks
BSD 3-Clause "New" or "Revised" License
71 stars 16 forks source link
cp-decomposition deep-neural-networks low-rank model-acceleration model-compression network-acceleration network-compression pytorch tensor-decomposition truncated-svd tucker vbmf

MUSCO: MUlti-Stage COmpression of neural networks

This repository contains supplementary code for the paper Automated Multi-Stage Compression of Neural Networks. It demonstrates how a neural network with convolutional and fully connected layers can be compressed using iterative tensor decomposition of weight tensors.

Requirements

numpy
scipy
scikit-tensor-py3
absl-py
flopco-pytorch
tensorly==0.4.5
pytorch

Installation

pip install musco-pytorch

Quick Start

from torchvision.models import resnet50
from flopco import FlopCo
from musco.pytorch import CompressorVBMF, CompressorPR, CompressorManual

model = resnet50(pretrained = True)
model_stats = FlopCo(model, device = device)

compressor = CompressorVBMF(model,
                            model_stats,
                            ft_every=5, 
                            nglobal_compress_iters=2)
while not compressor.done:
    # Compress layers
    compressor.compression_step()

    # Fine-tune compressed model.

compressed_model = compressor.compressed_model

# Compressor decomposes 5 layers on each iteration.
# Compressed model is saved at compressor.compressed_model.
# You have to fine-tune model after each iteration to restore accuracy.

Please, find more examples in musco/pytorch/examples folder

Compress the model

You can compress the model using diffrenet strategies depending on rank selection method.

Citing

If you used our research, we kindly ask you to cite the corresponding paper.

@inproceedings{gusak2019automated,
  title={Automated Multi-Stage Compression of Neural Networks},
  author={Gusak, Julia and Kholiavchenko, Maksym and Ponomarev, Evgeny and Markeeva, Larisa and Blagoveschensky, Philip and Cichocki, Andrzej and Oseledets, Ivan},
  booktitle={Proceedings of the IEEE International Conference on Computer Vision Workshops},
  pages={0--0},
  year={2019}
}

License

Project is distributed under Apache License 2.0.