An Embarrassingly Simple Approach to Training Ternary Weight Networks

Xiang Deng, Zhongfei Zhang

Abstract

Deep Neural Networks (DNNs) are increasingly deployed on resource-constrained edge devices, necessitating efficient model compression. Ternary Weight Networks (TWNs), which utilize weights of $\{-1, 0, +1\}$, provide a compelling balance between the efficiency of binary networks and the accuracy of full-precision models. However, training TWNs often involves non-differentiable operations and lacks a mechanism for explicit sparsity control. This paper introduces the Sparsity-Control Approach (SCA), a method that employs a Weight Discretization Regularizer (WDR) and tanh parameterization to simplify training. SCA allows developers to tune model sparsity via a single parameter while maintaining high accuracy across various benchmarks, including ImageNet.

Introduction

The deployment of DNNs on "edge" devices like smartphones and IoT sensors is hindered by their high power and memory requirements. While binary weights (0 or 1) offer extreme compression, Ternary Weight Networks (TWNs) using $\{-1, 0, +1\}$ are often preferred because the zero weights act as a natural form of pruning, preserving more representational power.

A primary challenge in training discrete-weight networks is the non-differentiability of the quantization function, which typically requires the "Straight-Through Estimator" (STE) hack. Furthermore, existing methods often lack a direct way to control the sparsity (the ratio of zero weights), which is critical for optimizing hardware performance.

Comparison of SCA with existing ternary weight regularizers.

The proposed Sparsity-Control Approach (SCA) addresses these issues by providing a differentiable training framework that inherently supports sparsity adjustment.

The Sparsity-Control Approach

SCA relies on two key components to bypass traditional training difficulties:

  1. Tanh Parameterization: Instead of optimizing weights $W$ directly, the authors parameterize them as $W = \tanh(\Theta)$. The $\tanh$ function naturally bounds values between -1 and 1 and is fully differentiable, eliminating the need for gradient estimators like STE.
  2. Weight Discretization Regularizer (WDR): A custom penalty term is added to the loss function: $$R(W) = (\alpha - W^2)W^2$$ This regularizer creates a "W-shaped" energy landscape. By adjusting the parameter $\alpha$, the depth and width of the minima at -1, 0, and 1 are altered. A larger $\alpha$ increases the influence of the zero-state "valley," thereby increasing model sparsity.

Implementation and Code Reuse

One of the most practical advantages of SCA is its simplicity. Because it only requires a $\tanh$ wrapper and an additional loss term, it can be easily integrated into existing deep learning pipelines.

Implementation of SCA (b) compared to standard training (a), highlighting high code-reuse.

As shown in the code comparison, converting a standard convolutional layer to an SCA-enabled ternary layer involves minimal modifications, ensuring a high code-reuse rate for engineers.

Experimental Evaluation

The authors evaluated SCA on several standard benchmarks, including MNIST, CIFAR-10/100, and ImageNet (ILSVRC2012).

  • Accuracy: On MNIST and CIFAR-10, SCA achieved accuracies (99.56% and 93.41%, respectively) that were nearly identical to full-precision models. On the large-scale ImageNet dataset using ResNet-18, SCA reached a Top-1 accuracy of 67.9%, outperforming other state-of-the-art ternary methods.
  • Sparsity Control: The "sparsity knob" ($\alpha$) proved highly effective. On MNIST, the model maintained 99.49% accuracy even at 99.63% sparsity. For VGG-S on CIFAR-10, sparsity could be varied from nearly 0% to 97% simply by tuning $\alpha$.
  • Hardware Efficiency: By constraining weights to exactly $\{-1, 0, 1\}$, SCA enables inference using only additions and subtractions, completely eliminating the need for costly multiplication operations in hardware.

Conclusion

The Sparsity-Control Approach (SCA) offers a remarkably simple yet powerful framework for training ternary weight networks. By combining tanh parameterization with a tunable discretization regularizer, SCA provides a differentiable path to high-performance, ultra-sparse models. Future work may involve extending this approach to activation quantization to further enhance hardware efficiency on edge devices.

Summary updated

BibTeX
@article{deng2020embarrassingly,
  author = {Xiang Deng and Zhongfei Zhang},
  title = {{An Embarrassingly Simple Approach to Training Ternary Weight Networks}},
  journal = {Neural Networks},
  year = {2020},
}
Figure