Introduction
Neural network compression is a critical step for deploying state-of-the-art models on resource-constrained edge devices. However, the field is currently dominated by "ad-hoc" solutions—specialized scripts or libraries designed for a single compression technique (e.g., pruning) on a specific architecture. This lack of a unified framework makes it difficult for practitioners to experiment with hybrid compression schemes, such as applying 8-bit quantization to some layers while pruning others.
To address this, we introduce a modular Python/PyTorch framework based on the Learning-Compression (LC) algorithm. This framework provides a principled approach to model compression by decoupling task-specific learning from technique-specific compression.
The LC Algorithm: Decoupling Learning and Compression
The core of the framework is the LC algorithm, which treats compression as a constrained optimization problem. It alternates between two generic, independent steps:
- The L (Learning) Step: This step minimizes the original loss function plus a quadratic penalty term that keeps weights close to a compressed target. It is essentially standard model training (e.g., using SGD) and is entirely independent of the specific compression method used.
- The C (Compression) Step: This step finds the best compressed representation of the current weights (e.g., via k-means for quantization or SVD for low-rank decomposition) in an $\ell_2$ sense. This step is independent of the dataset and the specific task.
By alternating these steps and gradually increasing the penalty parameter, the model "learns" to be compressible without suffering the significant accuracy drops often seen in simple "compress-then-retrain" heuristics.
Framework Design and Modularity
The framework's design emphasizes modularity and "per-layer granularity." Users can define a compression schedule via a simple dictionary, specifying different compression schemes for different layers. For example, one could quantize the first layer, prune the second, and apply low-rank decomposition to the third—all within a single optimization run. This flexibility allows for rapid prototyping of complex, hybrid compression strategies that were previously cumbersome to implement.
Experimental Results
We evaluated the framework on standard benchmarks, including MNIST and CIFAR-10, using architectures like VGG16 and various ResNets.
- Quantization: In experiments with VGG16 on CIFAR-10, the LC approach significantly outperformed standard "quantize then retrain" heuristics. It maintained lower test error even at very small codebook sizes (e.g., $K=2$ or $4$).
- Pruning: For ResNet architectures, the framework's $\ell_0$-constrained pruning achieved superior accuracy-to-sparsity ratios compared to traditional magnitude-based pruning methods.
The framework also supports automatic rank selection for low-rank compression, allowing it to learn the optimal rank for each layer to balance the trade-off between computational efficiency (FLOPs) and model error.
Conclusion
The LC framework offers a unified, extensible, and theoretically grounded approach to neural network compression. By decoupling the learning and compression steps, it enables researchers and engineers to easily explore a vast space of compression schemes. Future work includes expanding the library of supported compression types and extending support to more diverse architectures like Transformers and RNNs.
The source code is available as an open-source project on GitHub.
Summary updated