summaries: The paper proposes using a sinusoidal regularizer for neural network quantization. The regularizer “WaveQ” (sin^2) pushes floating-point parameters towards quantized values. Because the period of the function is highly related to the required bit-width, it can be used to determine the bit-width while keeping good characteristics - continuous and trainable. The authors provide experiments on both CNN and Transformers. The proposed method is widely adaptable and easy-to-use with quite promising results. This paper proposed a regularization term to control the bit-width and encourage the DNN weights moving to the quantization intervals. The key in such regularization is the Sinusoidal function, where the penalty is maximized in the middle of quantization levels and minimized at the quantization points. The sinusoidal period is regarded as the continuous representation of the bit-width. When training quantized neural networks, one typically first fixes the desired bitwidth $b$ (of weights and activations). While training, one maintains and updates full-bitwidth weights during backprop and "cheats" by using $b$-quantized versions of these full-precision weights during forward propagation. The quantization scheme used may vary.
abstractText: Deep quantization of neural networks below eight bits can lead to superlinear benefits in storage and compute efficiency. However, homogeneously quantizing all the layers to the same level does not account for the distinction of the layers and their individual properties. Heterogeneous assignment of bitwidths to the layers is attractive but opens an exponentially large non-contiguous hyperparameter space (Available Bitwidths ). Thus, finding the bitwidth while also quantizing the network to those levels becomes a major challenge. This paper addresses this challenge through a sinusoidal regularization mechanism, dubbed WaveQ. Adding our parametrized sinusoidal regularizer enables WaveQ to not only find the quantized weights, but also learn the bitwidth of the layers by making the period of the sinusoidal regularizer a trainable parameter. In addition, the sinusoidal regularizer itself is designed to align its minima on the quantization levels. With these two innovations, during training, stochastic gradient descent uses the form of the sinusoidal regularizer and its minima to push the weights to the quantization levels while it is also learning the period which will determine the bitwidth of each layer separately. As such WaveQ is a gradient-based mechanism that jointly learns the quantized weights as well as the heterogeneous bitwidths. We show that WaveQ balances compute efficiency and accuracy, and provides a heterogeneous bitwidth assignment for quantization of a large variety of deep networks (AlexNet, CIFAR10, MobileNet, ResNet-18, ResNet-20, SVHN, and VGG-11) that virtually preserves the accuracy. WaveQ is versatile and can also be used with predetermined bitwidths by fixing the period of the sinusoidal regularizer. In this case, WaveQ, on average, improves the accuracy of quantized training algorithms (DoReFa and WRPN) by∼ 4.8%, and outperforms multiple state-of-the-art techniques. Finally, WaveQ is applicable to quantizing transformers and yields significant benefits.
authors.name: SINUSOIDAL REGU
references.authors: Jan M. Köhler Anke Schmeink Tim Genewein
references.title: Variational network quantization
references.venue: In 6th ICLR,
references.authors: Dan Alistarh Demjan Grubic Jungshian Li Ryota Tomioka Milan Vojnovic
references.title: Qsgd: Communication-optimal stochastic gradient descent, with applications to training neural networks. 2016
references.authors: Yu Bai Yu-Xiang Wang Edo Liberty
references.title: Proxquant: Quantized neural networks via proximal operators
references.venue: In 7th International Conference on Learning Representations,
references.authors: Yoshua Bengio Nicholas Léonard Aaron C. Courville
references.title: Estimating or propagating gradients through stochastic neurons for conditional computation
references.venue: CoRR, abs/1308.3432,
references.authors: Jungwook Choi Zhuo Wang Swagath Venkataramani Pierce I-Jen Chuang Vijayalakshmi Srinivasan Kailash Gopalakrishnan
references.title: Pact: Parameterized clipping activation for quantized neural networks
references.venue: CoRR, abs/1805.06085,
references.authors: Yoojin Choi Mostafa El-Khamy Jungwon Lee
references.title: Learning low precision deep neural networks through regularization
references.venue: CoRR, abs/1809.00095,
references.authors: Anna Choromanska Mikael Henaff Michael Mathieu Gérard Ben Arous Yann LeCun
references.title: The Loss Surfaces of Multilayer Networks
references.venue: In Artificial Intelligence and Statistics,
references.authors: Ahmed T. Elthakeb Prannoy Pilligundla Fatemehsadat Mireshghallah Amir Yazdanbakhsh Hadi Esmaeilzadeh
references.title: ReLeQ: A reinforcement learning approach for deep quantization of neural networks
references.venue: Advances in Neural Information Processing Systems (NeurIPS) Workshop on Machine Learning for Systems,
references.authors: Steven K. Esser Jeffrey L. McKinstry Deepika Bablani Rathinakumar Appuswamy Dharmendra S. Modha
references.title: Learned step size quantization
references.venue: 8th ICLR,
references.authors: Ruihao Gong Xianglong Liu Shenghu Jiang Tianxiang Li Peng Hu Jiazhen Lin Fengwei Yu Junjie Yan
references.title: Differentiable soft quantization: Bridging full-precision and low-bit neural networks
references.venue: URL http://arxiv.org/abs/1908.05033
references.authors: Lu Hou James T. Kwok
references.title: Loss-aware weight quantization of deep networks
references.venue: In 6th ICLR,
references.authors: Lu Hou Quanming Yao James T. Kwok
references.title: Loss-aware binarization of deep networks
references.venue: In 5th ICLR,
references.authors: Itay Hubara Matthieu Courbariaux Daniel Soudry Ran El-Yaniv Yoshua Bengio
references.title: Quantized Neural Networks: Training Neural Networks with Low Precision Weights and Activations
references.venue: J. Mach. Learn. Res.,
references.authors: Patrick Judd Jorge Albericio Tayler H. Hetherington Tor M. Aamodt Andreas Moshovos
references.title: Stripes: Bit-serial deep neural network computing
references.venue: Annual IEEE/ACM International Symposium on Microarchitecture, MICRO 2016,
references.authors: Patrick Judd Jorge Albericio Tayler H. Hetherington Tor M. Aamodt Andreas Moshovos
references.title: Stripes: Bit-serial deep neural network computing
references.venue: 49th MICRO,
references.authors: Raghuraman Krishnamoorthi
references.title: Quantizing deep convolutional networks for efficient inference: A whitepaper, 2018
references.authors: Anders Krogh John A. Hertz
references.title: A simple weight decay can improve generalization
references.venue: In Proceedings of the 4th International Conference on Neural Information Processing Systems,
references.authors: Hao Li Zheng Xu Gavin Taylor Christoph Studer Tom Goldstein
references.title: Visualizing the Loss Landscape of Neural Nets
references.venue: In NIPS,
references.authors: Asit K. Mishra Eriko Nurvitadhi Jeffrey J. Cook Debbie Marr
references.title: WRPN: Wide ReducedPrecision Networks
references.venue: In ICLR,
references.authors: Abdelrahman Mohamed Dmytro Okhonko Luke Zettlemoyer
references.title: Transformers with convolutional context for asr, 2019
references.authors: Maxim Naumov Utku Diril Jongsoo Park Benjamin Ray Jedrzej Jablonski Andrew Tulloch
references.title: On periodic functions as regularizers for quantization of neural networks
references.venue: CoRR, abs/1811.09862,
references.authors: Hieu Duy Nguyen Anastasios Alexandridis Athanasios Mouchtaris
references.title: Quantization aware training with absolute-cosine regularization for automatic speech recognition
references.venue: 21st Annual Conference of the International Speech Communication Association, Virtual Event, Shanghai,
references.authors: Myle Ott Sergey Edunov David Grangier Michael Auli
references.title: Scaling neural machine translation
references.venue: Proceedings of the Third Conference on Machine Translation: Research Papers,
references.authors: Myle Ott Sergey Edunov Alexei Baevski Angela Fan Sam Gross Nathan Ng David Grangier Michael Auli
references.title: fairseq: A fast, extensible toolkit for sequence modeling
references.venue: In Proceedings of NAACL-HLT 2019: Demonstrations,
references.authors: Gabriele Prato Ella Charlaix Mehdi Rezagholizadeh
references.title: Fully quantized transformer for improved
references.venue: translation. ArXiv,
references.authors: David E. Rumelhart Geoffrey E. Hinton Ronald J. Williams
references.title: Learning internal representations by error propagation
references.authors: Hardik Sharma Jongse Park Naveen Suda Liangzhen Lai Benson Chau Vikas Chandra Hadi Esmaeilzadeh
references.title: Bit fusion: Bit-level dynamically composable architecture for accelerating deep neural network
references.authors: Peter Shaw Jakob Uszkoreit Ashish Vaswani
references.title: Self-attention with relative position representations
references.venue: In NAACL-HLT,
references.authors: Frederick Tung Greg Mori
references.title: CLIP-Q: deep network compression learning by in-parallel pruningquantization
references.venue: IEEE Conference on Computer Vision and Pattern Recognition,
references.authors: Stefan Uhlich Lukas Mauch Kazuki Yoshiyama Fabien Cardinaux Javier Alonso Garcı́a Stephen Tiedemann Thomas Kemp Akira Nakamura
references.title: Mixed precision dnns: All you need is a good parametrization
references.venue: URL http://arxiv.org/abs/1905.11452
references.authors: Ashish Vaswani Noam Shazeer Niki Parmar Jakob Uszkoreit Llion Jones Aidan N. Gomez Lukasz Kaiser Illia Polosukhin
references.title: Attention is all you need, 2017
references.authors: Kuan Wang Zhijian Liu Yujun Lin Ji Lin Song Han
references.title: HAQ: Hardware-Aware Automated Quantization
references.venue: arXiv preprint arXiv:1811.08886,
references.authors: Haichuan Yang Shupeng Gui Yuhao Zhu Ji Liu
references.title: Automatic neural network compression by sparsity-quantization joint learning: A constrained optimization-based approach
references.venue: IEEE/CVF Conference on Computer Vision and Pattern Recognition,
references.authors: Shaokai Ye Tianyun Zhang Kaiqi Zhang Jiayu Li Jiaming Xie Yun Liang Sijia Liu Xue Lin Yuankai Wang
references.title: A unified framework of dnn weight pruning and weight clustering/quantization using admm
references.authors: Dongqing Zhang Jiaolong Yang Dongqiangzi Ye Gang Hua
references.title: Lq-nets: Learned quantization for highly accurate and compact deep neural networks
references.venue: In ECCV,
references.authors: Shuchang Zhou Zekun Ni Xinyu Zhou He Wen Yuxin Wu Yuheng Zou
references.title: DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients
references.authors: Chenzhuo Zhu Song Han Huizi Mao William J. Dally
references.title: Trained Ternary Quantization
references.venue: In ICLR,
references.authors: Neta Zmora Guy Jacob Gal Novik
references.title: Neural network distiller
sections.heading: 1 INTRODUCTION
sections.text: Quantization, in general, and deep quantization (below eight bits) (Krishnamoorthi, 2018), in particular, aims to not only reduce the compute requirements of DNNs but also reduce their memory footprint (Zhou et al., 2016; Judd et al., 2016b; Hubara et al., 2017; Mishra et al., 2018; Sharma et al., 2018). Nevertheless, without specialized training algorithms, quantization can diminish the accuracy. As such, the practical utility of quantization hinges upon addressing two fundamental challenges: (1) discovering the appropriate bitwidth of quantization for each layer while considering the accuracy; and (2) learning weights in the quantized domain for a given set of bitwidths.
  This paper formulates both of these challenges as a gradient-based joint optimization problem by introducing an additional novel sinusoidal regularization term in the training loss, called WaveQ. The following two main insights drive this work. (1) Sinusoidal functions (sin2) have inherent periodic minima and by adjusting the period, the minima can be positioned on quantization levels corresponding to a bitwidth at per-layer granularity. (2) As such, sinusoidal period becomes a direct and continuous representation of the bitwidth. Therefore, WaveQ incorporates this continuous variable (i.e., period) as a differentiable part of the training loss in the form of a regularizer. Hence, WaveQ is a differentiable regularization mechanism, it piggy backs on the stochastic gradient descent that trains the neural network to also learn the bitwidth (the period). Simultaneously this parametric sinusoidal regularizer pushes the weights to the quantization levels (sin2 minima).
  By adding our parametric sinusoidal regularizer to the original training objective function, our method automatically yields the bitwidths for each layer along with nearly quantized weights for
  those bitwidths. In fact, the original optimization procedure itself is harnessed for this purpose, which is enabled by the differentiability of the sinusoidal regularization term. As such, quantized training algorithms (Zhou et al., 2016; Mishra et al., 2018) that still use some form of backpropagation (Rumelhart et al., 1986) can effectively utilize the proposed mechanism by modifying their loss. Moreover, the proposed technique is flexible as it enables heterogeneous quantization across the layers. The WaveQ regularization can also be applied for training a model from scratch, or for fine-tuning a pretrained model. In contrast to the prior inspiring works (Uhlich et al., 2019; Esser et al., 2019), WaveQ is the only technique that casts finding the bitwidths and the corresponding quantized weights as a simultaneous gradient-based optimization through sinusoidal regularization during the training process. We also prove a theoretical result to provide an insight on why the proposed approach leads to solutions preserving the original accuracy during quantization. We evaluate WaveQ using different bitwidth assignments across different DNNs (AlexNet, CIFAR-10, MobileNet, ResNet-18, ResNet20, SVHN, and VGG-11). To show the versatility of WaveQ, it is used with two different quantized training algorithms, DoReFa (Zhou et al., 2016) and WRPN (Mishra et al., 2018). Over all the bitwidth assignments, the proposed regularization, on average, improves the top-1 accuracy of DoReFa by 4.8%. The reduction in the bitwidth, on average, leads to 77.5% reduction in the energy consumed during the execution of these networks. Finally, we apply WaveQ to Transformer DNNs citeppby augmenting their loss with WaveQ parametric sinusiodal regularization. In this case, the conventional stochastic gradient descent plus WaveQ regularization is used to quantize the big Transformer model from (Ott et al., 2018) for machine translation on the IWSLT14 German-English dataset (IWS). For 5, 6, and 7-bit quantization, training with WaveQ yields 0.46, 0.14, 0.04 improved BiLingual Evaluation Understudy (BLEU) score, respectively. As a point of reference, the original big Transformer model from (Ott et al., 2018) improves the BLEU by only 0.1 over the state-of-the-art. Code available at https://github.com/waveq-reg/waveq
sections.heading: 2 JOINT LEARNING OF LAYER BITWIDTHS AND QUANTIZED PARAMETERS
sections.text: Our proposed method WaveQ exploits weight regularization in order to automatically quantize a neural network while training. To that end, Section 2.1 describes the role of regularization in neural networks and then Section 2.2 explains WaveQ in more details.
sections.heading: 2.1 PRELIMINARIES
sections.text: Quantizer. We discuss how quantization of weight works. Consider a floating-point variable wf to be mapped into a quantized domain using (b + 1) bits. Let Q be a set of (2k + 1) quantized values, where k = 2b − 1. Considering linear quantization, Q can be represented as{ −1,−k−1k , ...,− 1 k , 0, 1 k , ..., k−1 k , 1 } , where 1k is the size of the quantization bin. Now, wf can be mapped to the b-bit quantization Zhou et al. (2016) space as follows.
  wqo = 2× quantizeb (
  tanh(wf )
  2max(|tanh(Wf )|) +
  1
  2
  ) − 1 (2.1)
  In Equation 2.1, quantizeb(x) = 1 2b−1 round((2 b−1)x), wf is a scalar, Wf is a vector, and wqo is a scalar in the range [−1, 1]. Then, a scaling factor c is determined per layer to map the final quantized weight wq into the range [−c,+c]. As such, wq takes the form cwqo, where c > 0, and wqo ∈ Q.
  Soft constraints through regularization and the loss landscape of neural networks. Neural networks’ loss landscapes are known to be highly non-convex and it has been empirically verified that loss surfaces for large networks have many local minima that essentially provide equivalent test errors Choromanska et al. (2015); Li et al. (2018). This opens up the possibility of adding soft constrains as extra custom objectives during the training process, in addition to the original objective (i.e., to minimize the accuracy loss). The added constraint could be with the purpose of increasing gener-
  alization or imposing some preference on the weights values.
  Regularization in action. Regularization effectively constrains weight parameters by adding a corresponding term (regularizer) to the objective loss function. A classical example is Weight Decay Krogh & Hertz (1991) that aims to reduce the network complexity by limiting the growth of the weights. This soft constraint is realized by adding a term, proportional to the L2 norm of the weights to the objective function as the regularizer that penalizes large weight values. WaveQ, on the other hand, uses regularization to push the weights to the quantization levels. For the sake of simplicity and clarity, Figure 1(a) and (b) illustrate a geometrical sketch for a hypothetical loss surface (original objective function to be minimized) and an extra regularization term in 2-D weight space, respectively. For weight decay regularization (Figure 1 (a)), the faded circle shows that as we get closer to the origin, the regularization loss is minimized. The point wopt is the optimum just for the loss function alone and the overall optimum solution is achieved by striking a balance between the original loss term and the regularization loss term. Similarly, Figure 1(b) shows a representation of the proposed periodic regularization for a fixed bitwidth β. A periodic pattern of minima pockets are seen surrounding the original optimum point. The objective of the optimization problem is to find the best solution that is the closest to one of those minima pockets where weight values are nearly matching the desired quantization levels, hence the name quantization-friendly. 2.2 WAVEQ REGULARIZATION The proposed regularizer is formulated in Equation (2.2) where the first term pushes the weights to the quantization levels and the second correlated term aims to reduce the bitwidth of each individual layer heterogeneously.
  R(w;β) = λw ∑ i ∑ j
  sin2 ( πwij(2 βi − 1) )
  2βi︸ ︷︷ ︸ Weights quantization regularization
  + λβ ∑ i
  βi︸ ︷︷ ︸ Bitwidth regularization
  (2.2)
  In Equation (2.2), λw is the weights quantization regularization strength which governs how strongly weight quantization errors are penalized, and λβ is the bitwidth regularization strength. The parameter βi is proportional to the quantization bitwidth which is elaborated later in this section. Figure 2 (a) shows a 3-D visualization of our regularizer, R. Figure 2 (b), (c) show a 2-D profile w.r.t weights (w), while (d) shows a 2-D profile w.r.t the bitwidth (β). Periodic sinusoidal regularization. As shown in Equation equation 2.2, the first regularization term is based on a periodic function (sinusoidal) that adds a smooth and differentiable term to the original objective, Figure 2(b). The periodic regularizer induces a periodic pattern of minima that correspond to the desired quantization levels. Such correspondence is achieved by matching the period to the quantization step (1/(2βi − 1)) based on a particular number of bits (βi) for a given layer i. Learning the sinusoidal period. The parameter βi in (Equation 2.2) controls the period of the sinusoidal regularizer. Thereby βi is directly proportional to the actual quantization bitwidth (bi) of layer i as follows: bi = dβie, and αi = 2bi/2βi (2.3) In Equation (B.2) where αi ∈ R+ is a scaling factor. Note that bi ∈ Z is the only discrete parameter, while βi ∈ R+ is a continuous real valued variable, and d∗e. is the ceiling operator. While the first term in Equation equation 2.2 is only responsible for promoting quantized weights, the second term (λβ ∑ i βi) aims to reduce the number of bits for each layer i individually while the
  overall loss is aiming to maximize accuracy. As such, this term is a soft constraint that yields heterogeneous bitwidths for different layers. The main insight here is that βi, which also controls the period of the sinusoidal term, is a continuous valued parameter by definition. As such, βi acts as an ideal optimization objective constraint and a proxy to minimize the actual quantization bitwidth bi. Therefore, WaveQ avoids the issues of gradient-based optimization for discrete valued parameters. Furthermore, the benefit of learning the sinusoidal period is two-fold. First, it provides a smooth differentiable objective for finding minimal bitwidths. Second, simultaneously learning the scaling factor (αi) associated with the found bitwidth.
  Leveraging the sinusoidal properties, WaveQ learns the following two quantization parameters simultaneously: (1) a per-layer quantization bitwidth (bi) along with (2) a scaling factor (αi) through learning the period of the sinusoidal function. Additionally, by exploiting the periodicity, differentiability, and the local convexity profile in sinusoidal functions, WaveQ automatically propels network weights towards values that are inherently closer to quantization levels according to the jointly learned quantizer’s parameters bi, αi as follows.
  Mapping this to the quantizer’s design, for (b+ 1) bits quantization, k = 2b − 1, and c = α. These learned parameters (b, α), as explained above, can be mapped to the quantizer parameters explained in Equation equation 2.1. For (b+1) bits quantization (the extra bit is the sign bit):
  k = 2b − 1, and c = α = 2b/2β (2.4)
  Bounding the gradients. The denominator in the first term of Equation equation 2.2
  ( ∑ i ∑ j sin2(πwij(2βi−1)) 2βi
  ) is used to control the range derivatives of the proposed regularization term with respect to β. This denominator is chosen to limit vanishing and exploding gradients during training. To this end, we compared three variants of equation equation 2.2 with different normalization defined, for k = 0, 1, and 2, as:
  Rk(w; β) = λw ∑ i ∑ j
  sin2 ( πwij(2 βi − 1) )
  2kβi + λβ ∑ i βi
  (2.5)
  Figure 3 (a), (b), (c) provide a visualization on how each of the proposed scaled variants affect the first and second derivatives. For Rk=0 and Rk=2, there are regions of vanishing or exploding gradients. Only the regularization Rk=1 (the proposed one) is free of such issues.
  Setting the regularization strengths. The convergence behavior depends on the setting of the regularization strengths λw and λβ . Our proposed objective seeks to learn multiple quantization parameterization in conjunction. As such, the learning process can be portrayed as three phases (Figure 2(e)). In Phase ( 1 ), the learning process optimizes for the original task loss E0. Initially, the small λw and λβ values allow the gradient descent to explore the optimization surface freely. As the training process moves forward, we transition to phase ( 2 ) where the larger λw and λβ gradually engage both the weights quantization regularization and the bitwidth regularization, respectively. Note that, for this to work, the strength of the weights quantization regularization λw should be higher than the strength of the bitwidth regularization λβ such that a bitwidth per layer could be properly evaluated and eventually learned during this phase. After the bitwidth regularizer converges to a bitwidth for each layer, we transition to phase ( 3 ), where we fix the learned bitwidths and gradually decay λβ while we keep λw high. The criterion for choosing λw and λβ is to balance the magnitude of regularization loss to be smaller than the magnitude of accuracy loss. The mathematical formula used to generate λw and λβ profiles can be found in the supplementary material. (Figure 8).
sections.heading: 3 THEORETICAL ANALYSIS
sections.text: The results of this section are motivated as follows. Intuitively, we would like to show that the global minima of E = E0 + R are very close to the minima of E0 that minimizes R. In other words, we expect to extract among the original solutions, the ones that are most prone to be quantized. To establish such result, we will not consider the minima of E = E0 + R, but the sequence Sn of minima of En = E0+ δnR defined for any sequence δn of real positive numbers. The next theorem shows that our intuition holds true, at least asymptotically with n provided δn → 0. Theorem 1. Let E0, R : Rn → [0,∞) be continuous and assume that the set SE0 of the global minima of E0 is non-empty and compact. As SE0 is compact, we can also define SE0,R ⊆ SE0 as the set of minima of E0 which minimizes R. Let δn be a sequence of real positive numbers, define En = E0+δnR and the sequence Sn = SEn of the global minima of En. Then, the following holds true:
  1. If δn → 0 and Sn → S∗, then S∗ ⊆ SE0,R,
  2. If δn → 0 then there is a subsequence δnk → 0 and a non-empty set S∗ ⊆ SE0,R so that Snk → S∗,
  where the convergence of sets, denoted by Sn → S∗, is defined as the convergence to 0 of their Haussdorff distance, i.e., lim
  n→∞ dH(Sn, S∗) = 0.
  Proof. For the first statement, assume that Sn → S∗. We wish to show that S∗ ⊆ SE0,R. Assume that xn is a sequence of global minima of F + δnG converging to x∗. It suffices to show that x∗ ∈ SE0,R. First let us observe that x∗ ∈ SE0 . Indeed, let
  λ = inf x∈Rn E0(x)
  and assume that x ∈ SE0 . Then, λ ≤ E0(xn) ≤ (E0 + δnR)(xn) ≤ (E0 + δnR)(x) = λ+ δnR(x)︸ ︷︷ ︸
  →λ
  .
  Thus, since E0 is continuous and xn → x∗ we have that E0(x∗) = λ which implies x∗ ∈ SE0 . Next, define
  µ = inf x∈SE0 R(x).
  Let x̂ ∈ SE0,R so that R(x̂) = µ. Now observe that, by the minimality of xn we have that λ+ δnµ = (E0 + δnR)(x̂) ≥ (E0 + δnR)(xn) ≥ λ+ δnR(xn)
  Thus, R(xn) ≤ µ for all n. Since R is continuous and xn → x∗ we have that R(x∗) ≤ µ which implies that R(x∗) = µ since x∗ ∈ SE0 . Thus, x∗ ∈ SE0,R. The second statement follows from the standard theory of Hausdorff distance on compact metric spaces and the first statement. Theorem 1 implies that by decreasing the strength of R, one recovers the subset of the original solutions that achives the smallest quantization loss. In practice, we are not interested in global minima, and we should not decrease much the strength of R. In our context, Theorem 1 should then be understood as a proof of concept on why the proposed approach leads the expected result. Experiments carried out in the next section will support this claim. Additionally, note that while the theorem is stated in terms of a limit as the regularization parameter vanishes, the proof in fact gives a corresponding stability result. Namely, if the regularization parameter is sufficiently small relative to the main loss then the minimizers will be “almost” quantized. For the interested reader, we provide a more detailed version of the above analysis in the supplementary material.
sections.heading: 4 EXPERIMENTAL RESULTS
sections.text: To demonstrate the effectiveness of WaveQ, we evaluated it on several deep neural networks with different Image Classification datasets (CIFAR10, SVHN, and ImageNet), and one Transformerbased network, which is the big Transformer model from(Ott et al., 2018) on the IWSLT14 GermanEnglish dataset (IWS). We provide results for two different types of quantization. First, we show quantization results for learned heterogeneous bitwidths using WaveQ and we provide different analyses to asses the quality of these learned bitwidth assignments. Second, we further provide results assuming a preset homogeneous bitwidth assignment as a special setting of WaveQ. This is, in some cases, a practical assumption that might stem from particular hardware requirements or constraints. Table 1 provides a summary of the evaluated networks and datasets for both learned heterogeneous bitwidths, and the special case of training preset homogeneous bitwidth assignments. We compare our proposed WaveQ method with PACT (Choi et al., 2018a), LQ-Nets (Zhang et al., 2018),
  W32/A32 Full Precision Homogenous 57.1 80.2 70.1 89.5 71.8 90.3
  DSQ (Gong et al., 2019), and DoReFa, which are current state-of-the-art methods that show results with homogeneous 3-, and 4-bit weight/activation quantization for various networks (AlexNet, ResNet-18, and MobileNet).
  Experimental setup. We implemented WaveQ on top of DoReFa inside Distiller (Zmora et al., 2018), an open source framework for quantization by Intel that implements various quantization techniques. The reported accuracies for DoReFa and WRPN are with the built-in implementations in Distiller, which may not exactly match the accuracies reported in their respective papers. However, an independent implementation from a major company provides an unbiased foundation for comparison. We quantize all convolution and fully connected layers, except for the first and last layers which use 8-bits. This assumption is commensurate with the previous techniques.
sections.heading: 4.1 LEARNED HETEROGENEOUS BITWIDTHS
sections.text: As for quantizing both weights and activations, Table 1 shows that incorporating WaveQ into the quantized training process yields best accuracy results outperforming PACT, LQ-Net, DSQ, and DoReFa with significant margins. Furthermore, it can be seen that the learned heterogeneous bitwidths yield better accuracy as compared to the preset 4-bit homogeneous assignments, with
  lower, on average, bitwidth (3.85, 3.57, and 3.95 bits for AlexNet, ResNet-18, and MobileNet, respectively). Figure 4(a),(b) (bottom bar graphs) show the learned heterogeneous weight bitwidths over layers for AlexNet and ResNet-18, respectively. As seen, WaveQ parametric regularization yields a spectrum of varying bitwidth assignments to the layers which vary from 2 bits to 8 bits with an irregular pattern. These results demonstrate that the proposed regularization, WaveQ, automatically distinguishes different layers and their varying importance with respect to accuracy while learning their respective bitwidths. To assess the quality of these bitwidths assignments, we conduct a sensitivity analysis on the relatively big networks (see next subsection). Benefits of heterogeneous quantization. Figure 4(a),(b) (top graphs) show various comparisons and sensitivity results for learned heterogeneous bitwidth assignments for bigger networks (AlexNet and ResNet-18). It is infeasible to enumerate these networks’ respective quantization spaces. Compared to 4-bit homogeneous quantization, learned heterogeneous assignments achieve better accuracy with lower, on average, bitwidth 3.85 bits for AlexNet and 3.57 bits for ResNet-18. This demonstrates that a homogeneous (uniform) assignment of the bits is not always the desired choice to minimize accuracy loss. Furthermore, Figure 4 also shows that decrementing the learned bitwidth for any single layer at a time results in 0.44% and 0.24% average reduction in accuracy for AlexNet and ResNet-18, respectively. The dotted blue line with markers shows how differently decrementing the bitwidth of various individual layers affect the accuracy. This trend further demonstrates the effectiveness of learning with WaveQ to find the lowest bitwidth that maximizes the accuracy. Energy savings. To demonstrate the energy savings of the solutions found by WaveQ, we evaluate it on Stripes (Judd et al., 2016a), a custom accelerator designed for DNNs, which exploits bit-serial computation to support flexible bitwidths for DNN operations. As shown in Table 1, the reduction in the bitwidth, on average, leads to 77.5% reduction in the energy consumed during the execution of these networks.
sections.heading: 4.2 PRESET HOMOGENOUS BITWIDTH QUANTIZATION
sections.text: We also consider a preset homogeneous bitwidth quantization which can also be supported by WaveQ under special settings where we fix β (to a preset bitwidth). Hence, only the first regularization term is engaged for propelling the weights to the quantization levels.
  Table 2 shows accuracies of different networks (SimpleNet-5, ResNet-20, VGG-11, and SVHN-8) using plain WRPN, plain DoReFa and DoReFa + WaveQ for 3, 4, and 5 bitwdiths. As depicted, the results concretely show the effect of incorporating WaveQ into existing quantized training techniques and how it outperforms the previously reported accuracies. Weight distributions during training. Figure 5 shows the evolution of weights distributions over fine-tuning epochs for different layers of CIFAR10, SVHN, AlexNet, and ResNet18 networks. The high-precision weights form clusters and gradually converge around the quantization centroids as regularization loss is minimized along with the main accuracy loss. 4.3 WAVEQ FOR TRANSFORMER
  QUANTIZATION Table 3: Performance of WaveQ
  for quantizing Transformers.
  Bitwidth
  BLEU score
  Unregularized Training
  (without WaveQ)
  Regularized Training
  (with WaveQ)
  Full precision 34.93
  7-bit 34.79 34.83 (0.04 )
  6-bit 34.39 34.53 (0.14 )
  5-bit 32.74 33.20 (0.46 ) Transformers (encoder-decoder architectures) have been shown to achieve best results for NLP tasks including machine translation (Vaswani et al., 2017) and automatic speech recognition (Mohamed et al., 2019). A Transformer layer relies on a key-value self-attention mechanism for learning relationships between distant concepts, rather than relying on recurrent connections and memory cells. Herein, we extend the application of WaveQ regularization to improve the accuracy of deeply
  quantized (below 8 bits) Transformer models. We run our experiments on IWSLT 2014 GermanEnglish (DE-EN) dataset. We use the Transformer model implemented in the fairseq-py toolkit (Ott et al., 2019). All experiments are based on the big transformer model with 6 blocks in the encoder and decoder networks. Table 3 shows the effect of applying WaveQ regularization into the training process for 5, 6, and 7-bit quantization on the final accuracy (BLEU score). WaveQ consistently improves the BLEU score of quantized models at various quantization bitwidths (7-5 bits). Moreover, higher improvements are obtained at lower bitwidths.
  5 DISCUSSION
  We conduct an experiment that uses WaveQ for training from scratch. For the sake of clarity, we are considering in this experiment the case of preset bitwidth assignments (i.e., λβ = 0). Figure 6-Row(I)-Col(I) shows weight trajectories without WaveQ as a point of reference. Row(II)-Col(I) shows the weight trajectories when WaveQ is used with a constant λw.
  As the Figure illustrates, using a constant λw results in the weights being stuck in a region close to their initialization, (i.e., quantization objective dominates the accuracy objective). However, if we dynamically change the λw following the exponential curve in Figure 6- Row(III)-Col(I)) during the from-scratch training, the weights no longer get stuck. Instead,
  the weights traverse the space (i.e., jump from wave to wave) as illustrated in Figure 6-Cols(II) and (III) for CIFAR and SVHN, respectively. In these two columns, Rows (I), (II), (III), correspond to quantization with 3, 4, 5 bits, respectively. citepInitially, the smaller λw values allow the gradient descent to explore the optimization surface freely, as the training process moves forward, the larger λw gradually engages the sinusoidal regularizer, and eventually pushes the weights close to the quantization levels. Further convergence analysis is provided in the supplementary material.
  Next, we provide results comparing two profiles of the regularization strength (λw). Profile 1: λw gradually increases as training proceeds then gradually decays towards the end of training. (Figure 7(a)). Profile 2: λw gradually increases as training proceeds and remains high (Figure 7(c)). Figure 7(a,c) depicts different loss components and Figure 7(b,d) visualizes weights trajectories. Both profiles show that accuracy loss is unimpededly minimized along with WaveQ loss. Our theoretical results align with Profile 1 (Figure 7(b))–what reviewer insightfully pointed out. Although λw decays back towards end of training, the weights mostly remain tied to their
  quantization levels except for a few deflections that cause slight increase of the regularization loss towards end of training. In terms of test accuracy, both profiles yield similar results (Profile 1, 74.95%) vs (Profile 2, 74.45%). Note that while the theorem is stated in terms of a limit as the regularization parameter vanishes, the proof in fact gives a corresponding stability result. Namely, if the regularization parameter is sufficiently small relative to the main loss then the minimizers will be “almost” quantized.
sections.heading: 6 RELATED WORK
sections.text: This research lies at the intersection of (1) quantized training algorithms and (2) techniques that discover bitwidth for quantization. The following discusses the most related works in both directions. Most related methods define a new optimization problem and use a special method for solving it. For example, (Bai et al., 2019) uses a proximal gradient method (adds a prox step after each stochastic gradient step), (Yang et al., 2020) uses ADMM, and (Tung & Mori, 2018) takes a Bayesian approach. This only makes the training more difficult, slower and increases the computational com-
  plexity. In contrast, WaveQ exploits the conventional stochastic gradient descent method while jointly optimizing for the original training loss while softly constraining it to simultaneously learn the quantized parameters, and more importantly bitwidths. The differentiability of the adaptive sinusoidal regularizer enables simultaneously learning both the bitwidths and pushing the weight values to the quantization levels. As such, WaveQ can be used as a complementary method to some of these efforts, which is demonstrated by experiments with both DoReFa-Net (Zhou et al., 2016) and WRPN (Mishra et al., 2018). Our preliminary efforts (Anonymous) and another concurrent work (Naumov et al., 2018) use a sinusoidal regularization to push the weights closer to the quantization levels. However, neither of these two works make the period a differentiable parameter nor find bitwidths during training. Quantized training algorithms There have been several techniques (Zhou et al., 2016; Zhu et al., 2017; Mishra et al., 2018) that train a neural network in a quantized domain after the bitwidth of the layers is determined manually. DoReFa-Net (Zhou et al., 2016) uses straight through estimator (Bengio et al., 2013) for quantization and extends it for any arbitrary k bit quantization in weights, activations, and gradients. WRPN (Mishra et al., 2018) is training algorithm that compensates for the reduced precision by increasing the number of filter maps in a layer (doubling or tripling). TTQ (Zhu et al., 2017) quantizes the weights to ternary values by using per layer scaling coefficients learnt during training. These scaling coefficients are used to scale the weights during inference. PACT (Choi et al., 2018a) proposes a technique for quantizing activations by introducing an activation clipping parameter α. This parameter (α) is used to represent the clipping level in the activation function and is learned via back-propagation during training. More recently, VNQ (Achterhold et al., 2018) uses a variational Bayesian approach for quantizing neural network weights during training. VNQ requires a careful choice prior distribution of the weights, which is not straightforward, and the model is often intractable. In contrast, WaveQ is directly applicable without introducing extra hyperparameters to optimize. Additionally, VNQ takes on a probabilistic approach, while WaveQ is a deterministic approach towards soft quantization. Loss-aware weight quantization. Recent works pursued loss-aware minimization approaches for quantization. (Hou et al., 2017) and (Hou & Kwok, 2018) developed approximate solutions using proximal Newton algorithm to minimize the loss function directly under the constraints of low bitwidth weights. One effort (Choi et al., 2018b) proposed to learn the quantization of DNNs through a regularization term of the mean-squared-quantization error. LQ-Net (Zhang et al., 2018) proposes to jointly train the network and its quantizers. DSQ (Gong et al., 2019) employs a series of tanh functions to gradually approximate the staircase function for low-bit quantization (e.g., sign for 1- bit case), and meanwhile keeps the smoothness for easy gradient calculation. Although some of these techniques use regularization to guide the process of quantized training, none explores the use of adaptive sinusoidal regularizers for quantization. Most recently, (Nguyen et al., 2020) suggests using |cos| function as a regularizer. Moreover, unlike WaveQ, these techniques do not find the bitwidth for quantizing the layers. Techniques for discovering quantization bitwidths. A recent line of research focused on methods which can also find the optimal quantization parameters, e.g., the bitwidth, the stepsize, in parallel to the network weights. Recent work (Ye et al., 2018) based on ADMM (adm) runs a binary search to minimize the total square quantization error in order to decide the quantization levels for the layers. Most recently, (Uhlich et al., 2019) proposed to indirectly learn quantizer’s parameters via Straight Through Estimator (STE) (Bengio et al., 2013) based approach. In a similar vein, (Esser et al., 2019) has proposed to learn the quantization mapping for each layer in a deep network by approximating the gradient to the quantizer step size that is sensitive to quantized state transitions. On another side, recent works (Elthakeb et al., 2018; Wang et al., November 21, 2018) proposed a reinforcement learning based approach to find an optimal bitwidth assignment policy. Quantizing Transformers. FullyQT (Prato et al., 2019) uses a bucketing based uniform quantization proposed by QSGD (Alistarh et al., 2016) and extends it to Tranformers. Q8BERT (Zafrir et al., 2019) quantizes all the GEMM (General Matrix Multiply) operations to 8 bit by adding an additional term for quantization loss during training, which is calculated based on the rounding effect of floating point values (Shaw et al., 2018). WaveQ, however, uses a sinusoidal regularizer to automatically push the weights towards the quantization levels.
sections.heading: 7 CONCLUSION
sections.text: This paper devised WaveQ that casts the two problems of finding layer bitwidth and quantized weights as a gradient-based optimization through parametric sinusoidal regularization. WaveQ provides significant improvements over the state-of-the-art and is even applicable to the Transformers.
sections.heading: A DETAILED THEORETICAL ANALYSIS
sections.text: A.1 MOTIVATION
  The results of this section are motivated by the following question. Question A.1. Suppose that a function F : Rn → [0,∞) has many global minima and thatQ ⊂ Rn is closed. How do we isolate the global minima of F that are closest toQwithout actually computing the full set of global minima of F?
  Intuitively, we would like to show that if > 0 is very small, then the global minima of the function
  F (x) + d(x,Q)
  are very close to the global minima of F closest to Q. To achieve this we will have to introduce first the concept of convergence of sets and then we will show that our intuition is correct by proving that the set of global minima to the above relaxed function converges to a subset of global minima of F closest to Q.
  A.2 RELEVANT DEFINITIONS
  Definition A.2. If F : Rn → [0,∞) satisfies lim|x|→∞ F (x) = +∞, we will say that F is coercive. Definition A.3. For a coercive function F : Rn → [0,∞) we let SF = {x ∈ Rn : F (x) = miny∈Rn F (y)} be coercive. Lemma A.4. Assume that F : Rn → [0,∞) is continuous and coercive. Then F has at least one global minimum. That is, SF is non-empty. Furthermore, SF is a compact set. Definition A.5. Let F,G : Rn → [0,∞) are continuous and assume that F is coercive. Define
  SF,G = {x ∈ SF : G(x) = inf y∈SF G(y)},
  the minima of F which minimize G among the minima of F . Definition A.6. Let Q ⊂ Rn be a closed set and assume that x ∈ Rn. Define the distance from x to the set Q to be
  d(x,Q) = inf y∈Q ‖x− y‖.
  Observe that since Q is a closed set we have that x ∈ Q if and only if d(x,Q) = 0 and otherwise d(x,Q) > 0. Definition A.7. Let A,B ⊂ Rn be compact sets. We define the Hausdorff distance between A and B by
  dH(A,B) = max{sup x∈B d(x,A), sup y∈A d(y,B)}.
  Observe that dH(A,B) = 0 if and only if A = B. Definition A.8. Let {Sδ}δ>0 be a family of compact subsets of Rn. We say that limδ→0 Sδ = S∗ if
  lim δ→0 dH(Sδ, S∗) = 0.
  Lemma A.9. Let Sδ be a family of compact subsets of Rn, then limδ→0 Sδ = S∗ if and only if the following two conditions hold.
  1. If xδ ∈ Sδ converges to x, then x ∈ S∗
  2. For every x ∈ S∗, there exists a family xδ ∈ Sδ with xδ → x.
  The lemma is just an exercise in the definition.
  A.3 STATEMENT OF THE THEOREM
  Theorem 2. Let F,G : Rn → [0,∞) are continuous and assume that F is coercive. Consider the sets SF+δG, the set of points at which F + δG is globally minimum. The following are true:
  1. If δn → 0 and SF+δnG → S∗, then
  S∗ ⊂ SF,G
  2. If δn → 0 then there is a subsequence δnk → 0 and a non-empty set S∗ ⊂ SF,G so that SF+δnkG → S∗.
  Proof. The second statement follows from the standard theory of Hausdorff distance on compact metric spaces and the first statement. For the first statement, assume that SF+δnG → S∗. We wish to show that S∗ ⊂ SF,G. Assume that xn is a sequence of global minima of F + δnG converging to x∗. It suffices to show that x∗ ∈ SF,G. First let us observe that x∗ ∈ SF . Indeed, let
  λ = inf x∈Rn F (x)
  and assume that x ∈ SF . Then,
  λ ≤ F (xn) ≤ (F + δnG)(xn) ≤ (F + δnG)(x) = λ+ δnG(x)→ λ.
  Thus, since F is continuous and xn → x∗ we have that F (x∗) = λ which implies x∗ ∈ SF . Next, define
  µ = inf x∈SF G(x).
  Let x̂ ∈ SF,G so that G(x̂) = µ. Now observe that, by the minimality of xn we have that
  λ+ δnµ = (F + δnG)(x̂) ≥ (F + δnG)(xn) ≥ λ+ δnG(xn)
  Thus, G(xn) ≤ µ
  for all n. Since G is continuous and xn → x∗ we have that G(x∗) ≤ µ which implies that G(x∗) = µ since x∗ ∈ SF . Thus, x∗ ∈ SF,G.
sections.heading: B QUANTIZER
sections.text: Here, we give an overview about the used quantization method. Consider a floating-point variable wf to be mapped into a quantized domain using (b + 1) bits. Let Q be a set of (2k + 1) quantized values, where k = 2b − 1. Considering linear quantization, Q can be represented as{ −1,−k−1k , ...,− 1 k , 0, 1 k , ..., k−1 k , 1 } , where 1k is the size of the quantization bin. Now, wf can be mapped to the b-bit quantization (Zhou et al., 2016) space as follows:
  (B.1)wqo = 2× quantizeb ( tanh(wf )
  2max(|tanh(Wf )|) +
  1
  2
  ) − 1
  where quantizeb(x) = 1 2b−1 round((2 b−1)x), wf is a scalar,Wf is a vector, andwqo is a scalar and tanh is used to limit its range to [−1, 1]. Then, a scaling factor c is determined per layer to map the final quantized weight wq into the range [−c,+c]. As such, wq takes the form cwqo, where c > 0, and wqo ∈ Q. These learned parameters (b, α), as explained in Section 2.2, can be mapped to the quantizer parameters explained in Equation equation B.1. For (b + 1) bits quantization (the extra bit is the sign bit):
  k = 2b − 1, and c = α = 2b/2β (B.2)
sections.heading: C CONVERGENCE ANALYSIS
sections.text: Figure 8 (a), (b) show the convergence behavior of WaveQ by visualizing both accuracy and regularization loss over finetuning epochs for two networks: CIFAR10 and SVHN. As can be seen, the regularization loss (WaveQ Loss) is minimized across the finetuning epochs while the accuracy is maximized. This demonstrates a validity for the proposed regularization being able to optimize the two objectives simultaneously. Figure 8 (c), (d) contrasts the convergence behavior with and without WaveQ for the case of training from scratch for VGG-11. As can be seen, at the onset of training, the accuracy in the presence of WaveQ is behind that without WaveQ. This can be explained as a result of optimizing for an extra objective in case of with WaveQ as compared to without. Shortly thereafter, the regularization effect kicks in and eventually achieves ∼ 6% accuracy improvement. The convergence behavior, however, is primarily controlled by the regularization strengths (λw, λβ). As briefly mentioned in Section 2.2, (λw, λβ) ∈ [0,∞) is a hyperparameter that weights the relative contribution of the proposed regularization objective to the standard accuracy objective.
  We reckon that careful setting of λw, λβ across the layers and during the training epochs is essential for optimum results (Choi et al., 2018b).
  D WAVEQ PERFORMANCE ON BERT
  Additionally, Table 5 provides layer-wise quantization with a heterogeneous mix of 4 and 5 bits for the BERT model. In all cases, WaveQ improves UPOS and LAS metrics for two French treebanks (SPOKEN, PARTUT).
sections.heading: E TRAINING FROM SCRATCH
sections.text: Table 6 shows a comparison between training from scratch with WaveQ vs without. It can be seen that incorporating WaveQ into the training process achieves strictly better accuracy than the baseline training without WaveQ across all cases. Moreover, higher improvements are obtained at lower bitwidths reaching to 35%
sections.heading: F REGULARIZATION STRENGTHS
sections.text: Having a regularization strength is a normal setting associated with any regularization method. The criterion for choosing λw and λβ is to balance the magnitude of regularization loss to be smaller than the magnitude of accuracy loss. We then perform a grid search over a few points and chose the ones with the best convergence.
  From the theoretical perspective, while the theorem is stated in terms of a limit as the regularization parameter vanishes, the proof in fact gives a corresponding stability result. Namely, if the regularization parameter is sufficiently small relative to the main loss then the minimizers will be “almost” quantized.
sections.heading: G HETEROGENEOUS COMPARISON
sections.text: For Mobilenet-V2, WaveQ quantizes the network to an average bitwidth of 3.95(20.66 GBOPS) compared to 5.90(29.16 GBOPs) reported by Uhlich et al. (2019). Similarly, for Resnet-18, WaveQ achieves an average bitwidth of 3.57(62.56 GBOPs) compared to 5.47(65.90 GBOPs) by Uhlich et al. (2019). Table 7 shows this comparison. However this is not a fair comparison since WaveQ is a regularization method and not a full-blown quantization technique.
title: WAVEQ: GRADIENT-BASED DEEP QUANTIZATION