深度貝氏神經網路自適應量化之研究
Adaptive Quantization for Deep Bayesian Neural Network
摘要
舉凡自然語言處理到電腦視覺,深度學習在很多分類任務都達到卓越的結果。正如我們所知,過度擬合依然發生在深度學習中,如何解決此問題是機器學習中新興的分支。一般來說,深層神經網絡(DNNs)的高計算成本和大量記憶體存儲,導致在硬件實現的困難。一個具有挑戰性的問題是開發正規化的解決方案,以平衡執行效率和系統性能。最近的解決方式主要分成,張量矩陣的矩陣分解,與通過施加稀疏約束修剪神經參數。另外,對神經網絡進行量化,以減少內存和加速計算,同時確保分類的準確率。
量化神經網絡採用與一般DNN相同的架構,並把參數設定為一般DNN參數的量化值。在量化神經網路的參數由兩部分組成,一個是量化代表而另一個是分區的間隔。訓練網路的目的是找到自適應的量化代表,並降低量化參數時造成的量化損失與提高分類正確率。以往的研究通常只學習量化代表,但分區的間隔由經驗法則制定。調節超參數的時間造成訓練時間大增。本論文介紹了基於end-to-end訓練方式的自適應量化神經網路。量化器的設計不僅針對一般DNNs,也可以應用於貝葉氏神經網路,其中權重的不確定性增強了模型訓練時的穩定性與魯棒性。
由於所有的權重只由量化代表表示,在非貝氏的自適應量化神經網路有降低記憶體佔量的優點。由精度較高的參數量化成量化代表的量化誤差比只利用少量位元的量化更低。而在貝氏神經網路的量化,欲最小化量化誤差相當於最大化變分下界,設計貝氏神經網路量化器的目的是找到適合的定值來表示隨機變數。”Multi-spike-and-slab”是一個用以表示網路權重事前機率的機率密度,如此假設的原因在於,希望網路權重的事後機率同樣是”Multi-spike-and-slab”,多數權重集中於”spike”,又同時有夠大的機率逃離spike。根據事前機率的假設,最大化變分下界之中的Kullback-Leibler (KL) 散度是沒有解析解的,因此需推導全新的近似方程式。
自適應量化網路在三個層面上有顯著的優勢,第一,解除了對於量化區間的限制,意味著在更大的參數空間找尋最佳解。第二,量化的等分是可調整的,可以量化至任意等分。第三,量化分區與先前研究不同的是,不一定強制對稱於零點,提供非對稱性的量化準則。在實驗分析,我們探索自適應量化神經網路在MNIST與CIFAR10的分類準確率,並且適用於各種不同的神經網路架構,如LeNet與ResNet。
量化神經網絡採用與一般DNN相同的架構,並把參數設定為一般DNN參數的量化值。在量化神經網路的參數由兩部分組成,一個是量化代表而另一個是分區的間隔。訓練網路的目的是找到自適應的量化代表,並降低量化參數時造成的量化損失與提高分類正確率。以往的研究通常只學習量化代表,但分區的間隔由經驗法則制定。調節超參數的時間造成訓練時間大增。本論文介紹了基於end-to-end訓練方式的自適應量化神經網路。量化器的設計不僅針對一般DNNs,也可以應用於貝葉氏神經網路,其中權重的不確定性增強了模型訓練時的穩定性與魯棒性。
由於所有的權重只由量化代表表示,在非貝氏的自適應量化神經網路有降低記憶體佔量的優點。由精度較高的參數量化成量化代表的量化誤差比只利用少量位元的量化更低。而在貝氏神經網路的量化,欲最小化量化誤差相當於最大化變分下界,設計貝氏神經網路量化器的目的是找到適合的定值來表示隨機變數。”Multi-spike-and-slab”是一個用以表示網路權重事前機率的機率密度,如此假設的原因在於,希望網路權重的事後機率同樣是”Multi-spike-and-slab”,多數權重集中於”spike”,又同時有夠大的機率逃離spike。根據事前機率的假設,最大化變分下界之中的Kullback-Leibler (KL) 散度是沒有解析解的,因此需推導全新的近似方程式。
自適應量化網路在三個層面上有顯著的優勢,第一,解除了對於量化區間的限制,意味著在更大的參數空間找尋最佳解。第二,量化的等分是可調整的,可以量化至任意等分。第三,量化分區與先前研究不同的是,不一定強制對稱於零點,提供非對稱性的量化準則。在實驗分析,我們探索自適應量化神經網路在MNIST與CIFAR10的分類準確率,並且適用於各種不同的神經網路架構,如LeNet與ResNet。
Deep learning has achieved a great success in many classification tasks ranging from natural language processing to computer vision. As we know, deep learning is an emerging and growing branch in machine learning where the overfitting problem still happens and model regularization is required. In general, deep neural networks (DNNs) suffer from high computation cost and memory storage which result in difficulty in hardware implementation for end devices. A challenging issue is to develop a regularized solution to balance the tradeoff between implementation efficiency and system performance. Such an issue was recently tackled through the complexity reduction in DNNs where either tensor weights were decomposed or neural parameters were pruned by imposing sparsity constraint. Alternatively, the quantized neural networks were proposed to reduce memory storage and speed up computation without too much sacrifice in classification accuracy.
Quantized neural networks basically adopt the same architecture as the regular DNNs except that the precision of weights is reduced by quantizing the parameter values. The quantization in DNN consists of two components. One is the representation levels while the other is the partition intervals. The learning objective is to minimize the quantization loss by adaptively choosing these two quantization parameters. Previous studies usually learn the representation levels, but handcraft the partitions. A significant concern in construction of quantized neural networks is the computation time due to a large number of hyperparameter tuning. This dissertation presents a direct solution to adaptively quantize neural network parameters based on an end-to-end learning machine. The quantization schemes are not only developed for non-Bayesian DNNs but also for Bayesian DNNs where the weight uncertainties are considered to enhance the robustness in the estimated model.
Since the weights are only represented by the quantized values, the adaptive quantization in non-Bayesian DNNs provides the merit of memory reduction. Also, the representation values start from full-precision values where the loss of performance due to quantization errors is decreased when compared with previous methods with fewer bits for computation. In Bayesian DNNs, the model parameters are assumed to be random in model construction. Minimizing the quantization loss is comparable to maximizing the variational lower bound of log likelihood where the weight uncertainties are marginalized. The quantization scheme in Bayesian DNN is implemented to deal with how deterministic values are adopted to reflect stochastic values. The implementation is based on the “multi-spike-and-slab” distribution which reflects the prior representation levels or clusters of weight parameters. The resulting posterior also corresponds to a “multi-spike-and-slab” distribution. A new variational inference for quantization of Bayesian DNN is accordingly formulated for efficient computation with the Kullback-Leibler (KL) divergence between true posterior and parameterized posterior to be minimized. There are threefold advantages the proposed quantization methods can provide. First, the restriction in adaptive quantization is relaxed. The optimized values are searched in a wide range of parameter space. Second, the number of representation levels is flexible and adjustable. Such a number was fixed in previous methods. Third, the partition intervals are adaptive and asymmetric instead of fixed and symmetric in traditional methods. In the experiments, the proposed methods are illustrated by a number of analytical results and classification accuracies by using MNIST and CIFAR10 datasets. Furthermore, we use LeNet and ResNet to demonstrate the quantization methods which are feasible to different network structures.
Quantized neural networks basically adopt the same architecture as the regular DNNs except that the precision of weights is reduced by quantizing the parameter values. The quantization in DNN consists of two components. One is the representation levels while the other is the partition intervals. The learning objective is to minimize the quantization loss by adaptively choosing these two quantization parameters. Previous studies usually learn the representation levels, but handcraft the partitions. A significant concern in construction of quantized neural networks is the computation time due to a large number of hyperparameter tuning. This dissertation presents a direct solution to adaptively quantize neural network parameters based on an end-to-end learning machine. The quantization schemes are not only developed for non-Bayesian DNNs but also for Bayesian DNNs where the weight uncertainties are considered to enhance the robustness in the estimated model.
Since the weights are only represented by the quantized values, the adaptive quantization in non-Bayesian DNNs provides the merit of memory reduction. Also, the representation values start from full-precision values where the loss of performance due to quantization errors is decreased when compared with previous methods with fewer bits for computation. In Bayesian DNNs, the model parameters are assumed to be random in model construction. Minimizing the quantization loss is comparable to maximizing the variational lower bound of log likelihood where the weight uncertainties are marginalized. The quantization scheme in Bayesian DNN is implemented to deal with how deterministic values are adopted to reflect stochastic values. The implementation is based on the “multi-spike-and-slab” distribution which reflects the prior representation levels or clusters of weight parameters. The resulting posterior also corresponds to a “multi-spike-and-slab” distribution. A new variational inference for quantization of Bayesian DNN is accordingly formulated for efficient computation with the Kullback-Leibler (KL) divergence between true posterior and parameterized posterior to be minimized. There are threefold advantages the proposed quantization methods can provide. First, the restriction in adaptive quantization is relaxed. The optimized values are searched in a wide range of parameter space. Second, the number of representation levels is flexible and adjustable. Such a number was fixed in previous methods. Third, the partition intervals are adaptive and asymmetric instead of fixed and symmetric in traditional methods. In the experiments, the proposed methods are illustrated by a number of analytical results and classification accuracies by using MNIST and CIFAR10 datasets. Furthermore, we use LeNet and ResNet to demonstrate the quantization methods which are feasible to different network structures.