Simultaneously Optimizing Weight and Quantizer of Ternary Neural Network Using Truncated Gaussian Approximation

Zhezhi He, Deliang Fan

Abstract

Ternary Neural Networks (TNNs) offer significant computational and memory efficiency by restricting weights to $\{-1, 0, +1\}$. However, finding optimal quantization thresholds typically requires manual tuning or fixed heuristics, often leading to accuracy degradation. This paper proposes a novel training framework that treats quantization thresholds as learnable parameters. By modeling weight distributions as truncated Gaussians, we derive a differentiable closed-form expression for the quantizer. Combined with a "gradient correctness" adjustment for the Straight-Through Estimator (STE), our method allows simultaneous optimization of weights and thresholds via back-propagation. Experiments on ImageNet demonstrate that our fully ternarized models achieve state-of-the-art performance, significantly narrowing the gap with full-precision counterparts.

Introduction

Deep Neural Networks (DNNs) are notoriously resource-hungry, making them difficult to deploy on mobile or edge devices. Weight ternarization—restricting weights to just three values: $\{-1, 0, +1\}$—is a powerful compression technique. It reduces model size by 16x and replaces expensive floating-point multiplications with simple additions and subtractions.

However, most existing methods use fixed or manually tuned thresholds to decide which weights become -1, 0, or +1. This "one-size-fits-all" approach often leads to significant accuracy drops because the quantizer isn't tailored to the specific features the network is trying to learn. The challenge is that the quantization function is non-differentiable (a staircase function), making it hard to optimize the thresholds using standard gradient-based training.

Methods

The authors propose two key innovations to make TNNs fully trainable:

1. Truncated Gaussian Approximation

Based on the observation that weights in a trained layer typically follow a bell-shaped Gaussian distribution, the authors model the weights as a Gaussian distribution truncated by the quantization thresholds.

Weight distributions across various layers of a ResNet-18 model, supporting the Gaussian distribution assumption.

They derive a closed-form mathematical expression for the layer-wise scaling factor ($S_l$) as a function of the threshold ($\delta_l$). Because this expression is differentiable, the threshold $\delta_l$ can be updated via back-propagation alongside the weights. This allows the network to dynamically adjust its "sparsity" (how many weights are set to zero) for each layer to minimize accuracy loss.

2. STE with Gradient Correctness

The Straight-Through Estimator (STE) is a common trick used to "skip" non-differentiable functions during the backward pass. Standard STE simply passes the gradient through unchanged (gradient = 1). The authors argue this is too coarse. They introduce "gradient correctness," which scales the gradient by the inverse of the learned scaling factor ($1/S_l$), leading to faster convergence and better final accuracy. Adjusting the gradient to account for the quantizer's scale significantly stabilizes training.

Optimization Strategy

The training process alternates between two phases to ensure stable convergence: one step updates the thresholds while holding weights steady, and the next step updates the weights using the newly optimized thresholds.

The alternating training process: (a) updating thresholds $\delta$ while holding weights $\omega$ constant, and (b) updating weights $\omega$ using optimized thresholds.

Experimental Evaluation

The researchers evaluated their method on two standard computer vision benchmarks: CIFAR-10 (using ResNet-20) and ImageNet (using ResNet-18, ResNet-34, and ResNet-50).

Key Results

The proposed method achieves state-of-the-art results for ternary networks, nearly closing the gap with full-precision models:

  • Minimal Accuracy Loss: On ImageNet, the ternarized ResNet-18/34/50 models showed only a ~3.9% / 2.52% / 2.16% drop in accuracy compared to their full-precision (32-bit) counterparts.
  • Full Ternarization: Unlike many previous works that keep the first and last layers in full precision, this method successfully ternarizes all layers, which is critical for actual hardware acceleration.
  • Efficiency: The models achieve a 16x compression ratio for weights and enable the elimination of most floating-point multiplications during inference.

Conclusion and Future Work

By treating the quantizer as a trainable parameter and leveraging the statistical properties of weight distributions, this work provides a robust framework for TNN optimization. However, some limitations remain. The Gaussian assumption may not hold for all architectures or specialized loss functions. Furthermore, while this paper focuses on weight ternarization, achieving maximum hardware speedup will require extending this method to activations. Future work should also demonstrate the model running on specialized low-power hardware (like FPGAs or ASICs) to validate real-world latency benefits.

Summary updated

BibTeX
@inproceedings{he2019simultaneously,
  author = {Zhezhi He and Deliang Fan},
  title = {{Simultaneously Optimizing Weight and Quantizer of Ternary Neural Network Using Truncated Gaussian Approximation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2019},
  doi = {10.1109/cvpr.2019.01170},
}
Figure