Introduction
Deep learning models are typically trained using 32-bit floating point (FP32) precision. However, deploying these models for production inference at such high precision is often computationally inefficient and unnecessarily expensive. While lower precision formats like 8-bit integers (INT8) offer the potential for significant speedups and reduced memory bandwidth, standard high-performance computing (HPC) libraries like BLAS are primarily optimized for FP32/FP64 and large, square matrices.
FBGEMM (Facebook General Matrix Multiplication) is a high-performance kernel library designed to bridge this gap. By treating quantization as a first-class citizen and employing just-in-time (JIT) code generation, FBGEMM achieves over 2x performance gains compared to traditional libraries on modern CPU architectures.
The Challenges of Quantized Inference
Standard linear algebra libraries struggle with deep learning inference due to two primary factors:
- Quantization Overhead: The process of converting data to INT8 involves calculating row/column offsets and scaling factors. If these steps are handled as separate passes, the resulting overhead can negate the performance benefits of lower precision.
- Irregular Matrix Shapes: Unlike traditional scientific computing, inference often involves "skinny" matrices (e.g., small batch sizes where $M=1$). Standard libraries are not optimized for these specific dimensions.
Methods and Architecture
FBGEMM addresses these challenges through a specialized architecture that fuses operations to minimize memory passes and maximize CPU utilization.
Key Technical Innovations
- Operation Fusion: FBGEMM's "secret sauce" is performing row-offset calculations during the data "packing" stage. Since packing is a bandwidth-bound task, the CPU's arithmetic units are often idle; FBGEMM uses this time to calculate quantization offsets at nearly zero additional cost. It also fuses post-GEMM operations like bias addition, ReLUs, and requantization directly into the main kernel.
- JIT Code Generation: Rather than relying on a static, one-size-fits-all kernel, FBGEMM generates optimized assembly code at runtime. This allows the library to provide peak performance for the specific matrix dimensions ($M, N, K$) encountered during inference.
- Outlier-Aware Quantization: To leverage the speed of 16-bit accumulation (INT16) without the risk of numerical overflow, FBGEMM splits the weight matrix into a dense part (small values) and a sparse part (outliers). The dense part is processed via fast INT16 kernels, while outliers are handled separately to maintain accuracy.
Key Results and Real-World Impact
FBGEMM has been evaluated against internal production workloads at Facebook, including the Rosetta OCR system, Neural Machine Translation (NMT), and large-scale recommendation systems.
As shown in the performance data, FBGEMM consistently outperforms FP32 baselines across a variety of matrix shapes. Key performance metrics include:
- General Performance: Achieved >2x speedup over existing production baselines on Intel Broadwell and newer CPUs.
- Rosetta (OCR): Character detection speed increased by 2.4x.
- NMT: English-to-Spanish translation models saw a 1.3x speedup.
- Recommendation Systems: Reduced DRAM bandwidth usage by 40%, enabling more efficient infrastructure scaling.
Conclusion and Future Work
FBGEMM demonstrates that significant performance gains in deep learning inference require a departure from traditional HPC library designs. By integrating quantization offsets into the packing process and utilizing JIT code generation, the library effectively eliminates the overhead of low-precision arithmetic.
Future development for FBGEMM includes expanding support for ultra-low precision (4-bit and 2-bit quantization) and further optimizing for highly sparse models. Additionally, the authors advocate for the evolution of standard HPC interfaces to better accommodate the fused "input packing + output pipeline" model that has proven so successful for FBGEMM.
Summary updated