ibenedek
← All posts

RESEARCH NOTEBOOK

LUMMU: Block-Permutation Weight Quantization

Method and first results on MNIST (draft)

Summary

LUMMU is an experimental method of weight quantization where sub-blocks of the weight matrix are constrained to be a permutation of a shared reference value set. Only the permutation is stored. In 2×2 blocks, there are 24 permutations, meaning 5 bits are required to store each block. Therefore, 1.25 bits are required per weight. We evaluated standard codebook quantization methods against LUMMU on a tiny MNIST network. Within this experiment, LUMMU did not outperform the comparable methods; the 2×2 version of LUMMU, on average, was 0.8 percentage points worse than ternary quantization after quantization-aware training. The 3×3 variant (about 2.13 bits per weight) improves on 2×2 but is still about 0.4 percentage points worse than the 2-bit codebooks. Note, these are early results on a single layer of a very small model.

Method

W is an m x n weight matrix which we block into non-overlapping bh x bw blocks (2 x 2 blocks in the basic case). One reference vector r = (r1, …, rk) with k = bh x bw is defined for the entire matrix.

During quantization, weights in each block are ranked in increasing order. r1 replaces the smallest weight, r2 replaces the next, and so on. A block can be represented as a permutation of the reference vector. As squared error increases with rank mismatches (by the Rearrangement Inequality), this ranking and assignment strategy is optimal.

Reference values: To minimize squared error for a given rank assignment, the reference value for each position would be the mean over all blocks of values in that rank position. This value is then rounded to FP16.

Storage: Each block requires ⌈log2(k!)⌉ bits: 5 bits for a 2x2 block (1.25 bits/weight; 1.15 in terms of information theory), 19 bits for 3x3 (2.1 bits/weight), plus k values of FP16 per matrix.

Training: Quantization Aware Training (QAT) uses straight through estimation. That is, projection of weights is done in the forward pass while the identity mapping is used in the backward pass. The reference vector is kept constant during QAT. If a matrix cannot be perfectly blocked (e.g., 784 x 128 blocked in 3 x 3 blocks), it is first zero padded, then blocked, projected, and lastly, the zero padding is removed. Reference vectors are computed over whole blocks only.

Experimental setup

  • Dataset and network: MNIST, Flatten -> Dense (128, ReLU) -> Dropout (0.2) -> Dense (10). Only the hidden kernel (784×128) is quantized. The output layer and biases are left in FP32.

  • Protocol: Train an FP32 baseline for 5 epochs (Adam, lr 1e-3, batch 32, 10% validation split). Fine-tune all quantized models for 10 epochs starting from the baseline weights (lr 3e-4). Fine-tune the FP32 control for 10 epochs as well.

  • Baselines (fixed codebook with nearest level rounding): ternary (TWN), uniform 2-bit (scale optimized by MSE), k-means 2-bit.

  • Statistics: mean and standard deviation of accuracy on 10,000 MNIST test images over 5 seeds. Due to issues with the GPU plugin for Adam optimizer in our setup, all training runs were completed on CPU. GPU baseline achieved roughly 91% accuracy.

  • PTQ denotes accuracy right after quantization without fine tuning; QAT denotes accuracy after 10 fine tuning epochs with the quantized weights.

Results

Five seeds, test accuracy in %:

Method Bits/weight PTQ QAT Gap to FP32 control (pp)
FP32 control 32 98.10 ± 0.03
LUMMU 3×3 2.13 83.11 ± 3.57 97.48 ± 0.10 0.62 ± 0.09
K-means 2-bit 2.0 96.44 ± 0.26 97.89 ± 0.10 0.21 ± 0.11
Uniform 2-bit 2.0 94.80 ± 0.37 97.82 ± 0.06 0.28 ± 0.05
Ternary 1.58 91.62 ± 0.82 97.67 ± 0.06 0.43 ± 0.06
LUMMU 2×2 1.25 66.95 ± 10.36 96.86 ± 0.04 1.24 ± 0.04

LUMMU 3×3 uses 19 bits per block, which is approximately 2.13 bits per weight with the padded blocks on the edges, slightly more than the 2-bit baselines.

Discussion

  1. QAT is able to recover a large portion of the quantization error. LUMMU 2×2 averages 67% accuracy after quantization, with high variation across seeds. However, accuracy is restored to 96.9% after fine-tuning. Only the hidden weights of the network are quantized; the output weights and biases can adjust during fine tuning to compensate for quantization errors.

  2. Accuracy scores achieved using LUMMU 2x2 are lower than those achieved using baseline quantization methods. Across various seeds, the QAT accuracy scores achieved using LUMMU 2x2 are relatively stable, ±0.04, but on average 0.8 percentage points worse than those achieved using ternary quantization, and about 1 percentage point worse than those achieved using the 2-bit quantizers. This lack of variation in scores likely suggests a limitation in representation with the 2x2 block size, as opposed to issues with gradient descent based optimization.

  3. Using larger blocks improves performance. Increasing the block size from 2x2 to 3x3 improves the mean QAT accuracy from 96.86% to 97.48% (+0.62 pp) and the PTQ accuracy from 67% to 83%. However, LUMMU 3x3 needs about 2.13 bits per weight, more than the 2-bit baselines, and is still about 0.34 pp below uniform 2-bit, 0.41 pp below k-means 2-bit and 0.19 pp below ternary (1.58 bits). These differences are larger than the seed-to-seed spread (±0.06-0.10).

  4. Differences of the three codebook methods (0.07-0.2 pp) are within the uncertainty from different seeds, thus no method should be considered better than the others.

Limitations

  • This study is limited to single hidden layer network on MNIST. MNIST is small and highly redundant; with larger and more complex networks on other datasets results can be very different.

  • The actual size reduction achieved in this study was zero since packed weight format was not implemented and during execution the quantized weights were in FP32 format. Also, multiplying weights during quantization increases addition and decoding costs.

  • Assumptions are made that fixed-length codes are used, if ternary weights were represented using variable-length codes most likely some of them would be zero, altering the results.

  • The 3x3 variant needs zero padding of the 784 x 128 matrix (about 2.7% of the blocks are edge blocks); we did not measure the effect of the padding.

  • We don’t have a 1-bit baseline yet, so 1.25-bit results can’t be evaluated against a competitor.

  • We haven’t done a literature review. Other works including k-means and codebook weight sharing like ‘Deep Compression’, vector and product quantization, and ternary/binary networks, are already published. Whether block-permutation weight quantization is one of them is unknown to us.

Next steps

Evaluate 2x3 and 2x4 blocks across 5 seeds; add a 1-bit baseline and a ternary baseline with entropy coding; use Fashion-MNIST and CIFAR-10; quantize all layers; use packed format; and review the literature for similar methods to block-permutation and codebook quantization.