[Paper Review] DKM: Differentiable K-Means Clustering Layer for Neural Network Compression
This paper proposes DKM, a differentiable k-means clustering layer that enables end-to-end training with joint optimization of neural network weights and clustering centroids, achieving state-of-the-art model compression with minimal accuracy loss. By reformulating k-means as a differentiable attention mechanism, DKM enables high-precision, low-bit quantization—delivering 22.4x compression for MobileNet-v1 with 63.9% top-1 ImageNet accuracy and 11.8x for DistilBERT with only 1.1% accuracy drop on GLUE benchmarks.
Deep neural network (DNN) model compression for efficient on-device inference is becoming increasingly important to reduce memory requirements and keep user data on-device. To this end, we propose a novel differentiable k-means clustering layer (DKM) and its application to train-time weight clustering-based DNN model compression. DKM casts k-means clustering as an attention problem and enables joint optimization of the DNN parameters and clustering centroids. Unlike prior works that rely on additional regularizers and parameters, DKM-based compression keeps the original loss function and model architecture fixed. We evaluated DKM-based compression on various DNN models for computer vision and natural language processing (NLP) tasks. Our results demonstrate that DKM delivers superior compression and accuracy trade-off on ImageNet1k and GLUE benchmarks. For example, DKM-based compression can offer 74.5% top-1 ImageNet1k accuracy on ResNet50 DNN model with 3.3MB model size (29.4x model compression factor). For MobileNet-v1, which is a challenging DNN to compress, DKM delivers 63.9% top-1 ImageNet1k accuracy with 0.72 MB model size (22.4x model compression factor). This result is 6.8% higher top-1accuracy and 33% relatively smaller model size than the current state-of-the-art DNN compression algorithms. Additionally, DKM enables compression of DistilBERT model by 11.8x with minimal (1.1%) accuracy loss on GLUE NLP benchmarks.
Motivation & Objective
- Address the challenge of compressing already-compact deep neural networks like MobileNet, which lack significant weight redundancy.
- Overcome the non-differentiability of k-means clustering in backpropagation, which limits joint optimization of network weights and cluster centroids.
- Enable task-aware clustering during training without modifying the original loss function or model architecture.
- Achieve superior compression-accuracy trade-offs in both computer vision and NLP models through differentiable clustering.
- Provide a plug-and-play, parameter-free layer that supports multi-dimensional k-means clustering for efficient weight sharing.
Proposed method
- Propose DKM as a differentiable k-means clustering layer that replaces discrete cluster assignment with a differentiable attention mechanism.
- Formulate k-means clustering as a soft assignment problem using a dot-product attention mechanism between input weights and learnable cluster centroids.
- Use temperature-controlled softmax to control the sharpness of cluster assignments, enabling gradient flow during backpropagation.
- Apply DKM as a lightweight, parameter-free layer inserted into neural networks to enable joint optimization of network weights and cluster centroids.
- Snap predictions to the nearest centroid during inference while retaining gradient updates during training via the differentiable attention mechanism.
- Integrate DKM into existing DNNs without architectural changes, preserving the original loss function and training pipeline.
Experimental results
Research questions
- RQ1Can k-means clustering be made differentiable to enable end-to-end training with deep neural networks?
- RQ2Does differentiable k-means clustering lead to better compression-accuracy trade-offs compared to standard k-means or prior differentiable approaches?
- RQ3Can DKM effectively compress highly parameter-efficient models like MobileNet-v1, which are traditionally hard to compress?
- RQ4How does DKM perform on NLP models such as DistilBERT, especially under low-precision quantization?
- RQ5Can DKM achieve fine-grained control over compression ratios across different layers (e.g., embedding vs. transformer layers) without accuracy degradation?
Key findings
- DKM achieved 74.5% top-1 accuracy on ImageNet1k using ResNet50 with only 3.3MB model size, representing a 29.4x compression factor.
- For MobileNet-v1, DKM delivered 63.9% top-1 accuracy with 0.72MB model size (22.4x compression), outperforming state-of-the-art methods by 6.8% in accuracy and 33% in model size reduction.
- On DistilBERT, DKM compressed the model by 11.8x with only 1.1% accuracy loss on GLUE benchmarks, outperforming GOBO in both compression and accuracy.
- DKM-based compression showed a 0.2% to 1.7% accuracy drop between training and inference due to the gap between differentiable training and discrete inference, which was minimal and manageable.
- The 4/4 bit configuration (4 bits for transformer layers, 4 bits for embeddings) outperformed 1-bit and 2-bit configurations across all BERT variants, especially on hard-to-compress models like MobileBERT.
- DKM enabled smooth convergence and gradual weight clustering during training, with no need for custom training loops or additional regularization.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.