BiQGEMM: matrix multiplication with lookup table for binary-coding-based quantized DNNs

Yongkweon Jeon, Baeseong Park, Se Jung Kwon, Byeongwook Kim, Jeongin Yun, Dongsoo Lee

TL;DR

BiQGEMM is a novel matrix multiplication algorithm designed to accelerate quantized Deep Neural Networks (DNNs) on standard CPUs and GPUs. By replacing redundant arithmetic operations with fast lookup tables (LUTs), it bypasses the "bit-unpacking" overhead that usually slows down low-precision models, achieving significant speedups in memory-bound tasks like Natural Language Processing (NLP).

What Problem Does This Paper Address?

As deep learning models grow in size, quantization—reducing the number of bits used to represent weights—has become a go-to technique for compression. However, there is a major "hardware-software gap." Modern CPUs and GPUs are optimized for 32-bit or 16-bit data. When you use 2-bit or 3-bit weights, these processors often waste memory bandwidth or require expensive "unpacking" steps to turn those bits back into numbers they can calculate with.

Furthermore, matrix multiplication (GEMM) is the primary bottleneck in DNN inference. In many real-time applications (like voice assistants or translation), we process small batches of data. In these "few-batch" scenarios, the system is often "memory-bound," meaning the processor spends more time waiting for weights to arrive from memory than actually calculating. The authors sought a way to make quantization actually faster on commodity hardware, not just smaller.

Methods

The authors introduce BiQGEMM (Binary-coding-based Quantized GEMM). The core idea is to exploit the limited "computation space" created by quantization.

  1. Binary-Coding Quantization: Instead of standard uniform quantization, weights are represented as a sum of binary matrices (containing only -1 and 1) multiplied by scaling factors.
  2. The LUT Strategy: If you take a small chunk of an input vector (say, 4 or 8 elements, called a LUT-unit $\mu$), and multiply it by a corresponding chunk of binary weights, there are only $2^\mu$ possible results.
  3. On-the-fly Table Building: BiQGEMM pre-computes these $2^\mu$ possible outcomes for each chunk of the input vector and stores them in a Lookup Table. They use a clever Dynamic Programming approach to build these tables extremely efficiently ($O(2^\mu)$ time).
  4. Retrieval instead of Arithmetic: During the actual matrix multiplication, the algorithm doesn't perform standard multiply-accumulate operations. Instead, it uses the bit-packed weights directly as indices to pull the pre-computed results from the LUT.
  5. LUT-Stationary Tiling: To ensure this works well on real hardware, they implemented a tiling strategy that keeps the lookup tables in fast on-chip memory (SRAM or Cache) as long as possible.

Datasets

The researchers evaluated BiQGEMM primarily on NLP tasks, which rely heavily on large matrix multiplications in Transformer and LSTM architectures.

  • Transformer Model: Evaluated on the WMT13 English-to-German translation dataset to verify that binary-coding quantization maintains high accuracy (BLEU scores).
  • Performance Benchmarking: They used synthetic matrices of various sizes (1K to 8K) to measure raw speedups across different hardware:
  • Mobile: ARM Cortex-A76 (using SIMD instructions).
  • PC: Intel i7-7700 (using MKL and Eigen as baselines).
  • GPGPU: NVIDIA Tesla V100 (comparing against cuBLAS and XNOR-Net).

Key Insights and Ideas

  • Redundancy is an Opportunity: In quantized space, the same dot products are calculated over and over. BiQGEMM turns this redundancy into a performance win via memoization.
  • Eliminating the "Unpacking Tax": Traditional quantized kernels must "unpack" bits into registers before calculating. BiQGEMM uses the packed bits as the address for the lookup, effectively making the "unpacking" and "calculation" happen in a single memory access.
  • The "Sweet Spot": The algorithm is most effective when the output dimension ($m$) is large and the batch size ($b$) is small. This perfectly matches the requirements of many edge-AI and real-time inference scenarios.
  • Software-Only Acceleration: Unlike many quantization papers that require custom FPGA or ASIC designs, BiQGEMM is a software-level innovation that works on the processors already in our phones and laptops.

Key Results

  • Speedups: On mobile CPUs, BiQGEMM (1-3 bits) consistently outperformed full-precision Eigen and optimized INT8 libraries (like QNNPACK). For 1-bit weights, it achieved nearly 10x speedup over Eigen.
  • GPU Performance: On the Tesla V100, BiQGEMM was up to 30x faster than standard GPU kernels for large matrices at small batch sizes.
  • Accuracy Preservation: Using 3-bit quantization, the Transformer model achieved a BLEU score of 25.5, very close to the 32-bit baseline of 25.8, while being significantly faster.
  • Efficiency: The Dynamic Programming method for building LUTs was shown to be $\mu$ times faster than a naive matrix-multiplication approach to filling the tables.

Limitations and Future Work

  • Batch Size Scaling: As the batch size increases, the relative overhead of building the LUTs grows, and standard GEMM (which reuses weights more effectively) starts to catch up. BiQGEMM is less ideal for high-throughput, large-batch server workloads.
  • CNN Compatibility: While great for NLP, standard Convolutional Neural Networks (CNNs) often have smaller output dimensions per layer, which may not provide enough "lookup reuse" to justify the LUT construction cost.
  • Hardware Locality: Current CPUs/GPUs aren't perfectly designed for the non-sequential memory access patterns of LUT lookups. The authors suggest that future hardware with specialized cache designs for LUTs could unlock even more performance.

Summary updated

BibTeX
@inproceedings{jeon2020biqgemm,
  author = {Yongkweon Jeon and Baeseong Park and Se Jung Kwon and Byeongwook Kim and Jeongin Yun and Dongsoo Lee},
  title = {{BiQGEMM: matrix multiplication with lookup table for binary-coding-based quantized DNNs}},
  booktitle = {SC},
  year = {2020},
  url = {https://openreview.net/forum?id=uqRlAcWY4sH},
}

Loading related content...

Figure