๐งโ๐ซ Lecture 5-6
์ด๋ฒ ๊ธ์์๋ MIT HAN LAB์์ ๊ฐ์ํ๋ TinyML and Efficient Deep Learning Computing์ ๋์ค๋ Quantization ๋ฐฉ๋ฒ์ ์๊ฐํ๋ ค ํ๋ค. Quantization(์์ํ) ์ ํธ์ ์ด๋ฏธ์ง์์ ์๋ ๋ก๊ทธ๋ฅผ ๋์งํธ๋ก ๋ณํํ๋ ๊ณผ์ ์์ ์ฌ์ฉํ๋ ๊ฐ๋ ์ด๋ค. ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ์ฐ์์ ์ธ ์ผ์๋ก ๋ถํฐ ๋ค์ด์ค๋ ์๋ ๋ก๊ทธ ๋ฐ์ดํฐ ๋ ์ด๋ฏธ์ง๋ฅผ ํํํ๊ธฐ ์ํด ๋จ์ ์๊ฐ์ ๋ํด์ ๋ฐ์ดํฐ๋ฅผ ์ํ๋งํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์์งํ๋ค.
๋์งํธ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณํํ๊ธฐ ์ํด ๋ฐ์ดํฐ ํ์ ์ ์ ํ๋ฉด์ ์ด๋ฅผ ํ๋์ฉ ์์ํํ๋ค. ์์์ ์์๋ฅผ ํํํ๊ธฐ ์ํด Unsigned Integer ์์ Signed Integer, Signed์์๋ Sign-Magnitude ๋ฐฉ์๊ณผ Twoโs Complement๋ฐฉ์์ผ๋ก, ๊ทธ๋ฆฌ๊ณ ๋ ๋ง์ ์์ซ์ ์๋ฆฌ๋ฅผ ํํํ๊ธฐ ์ํด Fixed-point์์ Floating point๋ก ๋ฐ์ดํฐ ํ์ ์์ ์์ ๋ฒ์ฃผ๋ฅผ ํ์ฅ์ํจ๋ค. ์ฐธ๊ณ ๋ก Device์ Computationality์ ML ๋ชจ๋ธ์ ์ฑ๋ฅ์งํ์ค ํ๋์ธ FLOP์ด ๋ฐ๋ก floating point operations per second์ด๋ค.
์ด ๊ธ์์ floating point๋ฅผ ์ดํดํ๋ฉด, fixed point๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ๋งค๋ชจ๋ฆฌ์์, ๊ทธ๋ฆฌ๊ณ ์ฐ์ฐ์์ ๋ ํจ์จ์ ์ผ ๊ฒ์ด๋ผ๊ณ ์์ํด๋ณผ ์ ์ ์๋ค. ML๋ชจ๋ธ์ ํด๋ผ์ฐ๋ ์๋ฒ์์ ๋๋ฆด ๋๋ ํฌ๊ฒ ๋ฌธ์ ๋์ง ์์์ง๋ง ์๋ ๋ ๊ฐ์ง ํ๋ฅผ ๋ณด๋ฉด ์๋์ง์๋ชจ, ์ฆ ๋ฐฐํฐ๋ฆฌ ํจ์จ์์ ํฌ๊ฒ ์ฐจ์ด๊ฐ ๋ณด์ธ๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๋ชจ๋ธ์์ Floating point๋ฅผ fixed point๋ก ๋ ๋ง์ด ๋ฐ๊พธ๋ ค๊ณ ํ๋๋ฐ ์ด ๋ฐฉ๋ฒ์ผ๋ก ๋์จ ๊ฒ์ด ๋ฐ๋ก Quatization์ด๋ค.
์ด๋ฒ ๊ธ์์๋ Quntization ์ค์์ Quantization ๋ฐฉ๋ฒ๊ณผ ๊ทธ ์ค Linearํ ๋ฐฉ๋ฒ์ ๋ํด ๋ ์์ธํ๊ฒ, ๊ทธ๋ฆฌ๊ณ Post-training Quantization๊น์ง ๋ค๋ฃจ๊ณ , ๋ค์ ๊ธ์์๋ Quantization-Aware Training, Binary/Tenary Quantization, Mixed Precision Quantization๊น์ง ๋ค๋ฃจ๋ ค๊ณ ํ๋ค.
1. Common Network Quantization
์์์ ์๊ฐํ ๊ฒ์ฒ๋ผ Neural Netowork๋ฅผ ์ํ Quantization์ ๋ค์๊ณผ ๊ฐ์ด ๋๋ ์ ์๋ค. Quantization ๋ฐฉ๋ฒ์ ํ๋์ฉ ์์๋ณด์.
Reference. MIT-TinyML-lecture5-Quantization-1 in https://efficientml.ai
1.1 K-Means-based Quantization
๊ทธ ์ค ์ฒซ ๋ฒ์งธ๋ก K-means-based Quantization์ด ์๋ค. Deep Compression [Han et al., ICLR 2016] ๋ ผ๋ฌธ์ ์๊ฐํ๋ค๋ ์ด ๋ฐฉ๋ฒ์ ์ค์ฌ๊ฐ์ ๊ธฐ์ค์ผ๋ก clustering์ ํ๋ ๋ฐฉ๋ฒ์ด๋ค. ์์ ๋ฅผ ๋ด๋ณด์.
์ ์์ ๋ weight๋ฅผ codebook์์ -1, 0, 1.5, 2๋ก ๋๋ ๊ฐ๊ฐ์ ๋ง๋ ์ธ๋ฑ์ค๋ก ํ๊ธฐํ๋ค. ์ด๋ ๊ฒ ์ฐ์ฐ์ ํ๋ฉด ๊ธฐ์กด์ 64bytes๋ฅผ ์ฌ์ฉํ๋ weight๊ฐ 20bytes๋ก ์ค์ด๋ ๋ค. codebook์ผ๋ก ์์ ๋ 2bit๋ก ๋๋ด์ง๋ง, ์ด๋ฅผ N-bit๋งํผ ์ค์ธ๋ค๋ฉด ์ฐ๋ฆฌ๋ ์ด 32/N๋ฐฐ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ค์ผ ์ ์๋ค. ํ์ง๋ง ์ด ๊ณผ์ ์์ quantizatio error, ์ฆ quantization์ ํ๊ธฐ ์ ๊ณผ ํ ํ์ ์ค์ฐจ๊ฐ ์๊ธฐ๋ ๊ฒ์ ์ ์์ ์์ ๋ณผ ์ ์๋ค. ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ์ค์ด๋ ๊ฒ๋ ์ข์ง๋ง, ์ด ๋๋ฌธ์ ์ฑ๋ฅ์ ์ค์ฐจ๊ฐ ์๊ธฐ์ง ์๊ฒ ํ๊ธฐ์ํด ์ด ์ค์ฐจ๋ฅผ ์ค์ด๋ ๊ฒ ๋ํ ์ค์ํ๋ค.
์ด๋ฅผ ๋ณด์ํ๊ธฐ ์ํด Quantizedํ Weight๋ฅผ ์์ ๊ทธ๋ฆผ์ฒ๋ผ Fine-tuningํ๊ธฐ๋ ํ๋ค. centroid๋ฅผ fine-tuningํ๋ค๊ณ ์๊ฐํ๋ฉด ๋๋๋ฐ, ๊ฐ centroid์์ ์๊ธฐ๋ ์ค์ฐจ๋ฅผ ํ๊ท ๋ด tuningํ๋ ๋ฐฉ๋ฒ์ด๋ค. ์ด ๋ฐฉ๋ฒ์ ์ ์ํ ๋ ผ๋ฌธ ์์๋ Convolution ๋ ์ด์ด์์๋ 4bit๊น์ง centroid๋ฅผ ๊ฐ์ก์ ๋, Full-Connected layer์์๋ 2 bit๊น์ง centroid๋ฅผ ๊ฐ์ก์ ๋ ์ฑ๋ฅ์ ํ๋ฝ์ด ์๋ค๊ณ ๋งํ๊ณ ์์๋ค.
์ด๋ ๊ฒ Quantization ๋ Weight๋ ์์ฒ๋ผ ์ฐ์์ ์ธ ๊ฐ์์ ์๋์ฒ๋ผ Discreteํ ๊ฐ์ผ๋ก ๋ฐ๋๋ค.
๋ ผ๋ฌธ์ ์ด๋ ๊ฒ Quantizationํ weight๋ฅผ ํ ๋ฒ ๋ Huffman coding๋ฅผ ์ด์ฉํด ์ต์ ํ์ํจ๋ค. ์งง๊ฒ ์ค๋ช ํ์๋ฉด, ๋น๋์๊ฐ ๋์ ๋ฌธ์๋ ์งง์ ์ด์ง์ฝ๋๋ฅผ, ๋น๋ ์๊ฐ ๋ฎ์ ๋ฌธ์์๋ ๊ธด ์ด์ง์ฝ๋๋ฅผ ์ฐ๋ ๋ฐฉ๋ฒ์ด๋ค. ์์ถ ๊ฒฐ๊ณผ๋ก Generalํ ๋ชจ๋ธ๊ณผ ์์ถ ๋น์จ์ด ๊ฝค ํฐ SqueezeNet์ ์๋ก ๋ ๋ค. ์์ธํ ๋ด์ฉ์ ๋ ผ๋ฌธ์ ์ฐธ๊ณ ํ๋ ๊ฑธ๋ก.
inference๋ฅผ ์ํด weight๋ฅผ Decodingํ๋ ๊ณผ์ ์ inference๊ณผ์ ์์ ์ ์ฅํ cluster์ ์ธ๋ฑ์ค๋ฅผ ์ด์ฉํด codebook์์ ํด๋นํ๋ ๊ฐ์ ์ฐพ์๋ด๋ ๊ฒ์ด๋ค. ์ด ๋ฐฉ๋ฒ์ ์ ์ฅ ๊ณต๊ฐ์ ์ค์ผ ์๋ ์์ง๋ง, floating point Computation์ด๋ ๋ฉ๋ชจ๋ฆฌ ์ ๊ทผํ๋ ๋ฐฉ์์ผ๋ก centroid๋ฅผ ์ฐ๋ ํ๊ณ๊ฐ ์์ ์ ๋ฐ์ ์๋ค.
Reference. Deep Compression [Han et al., ICLR 2016]
1.2 Linear Quantization
๋ ๋ฒ์งธ ๋ฐฉ๋ฒ์ Linear Quatization์ด๋ค. floating-point์ธ weight๋ฅผ N-bit์ ์ ์๋ก affine mapping์ ์ํค๋ ๋ฐฉ๋ฒ์ด๋ค. ๊ฐ๋จํ๊ฒ ์์ผ๋ก ๋ณด๋ ๊ฒ ๋ ์ดํด๊ฐ ์ฝ๋ค.
์ฌ๊ธฐ์ S(Scale of Linear Quantization)์ Z(Zero point of Linear Quantization)๊ฐ ์๋๋ฐ ์ด ๋์ด quantization parameter ๋ก์จ tuning์ ํ ์ ์๋ ๊ฐ์ธ ๊ฒ์ด๋ค.
1.3 Scale and Zero point
์ด Scale๊ณผ Zero point ๋ ํ๋ผ๋ฏธํฐ๋ฅผ ์ด์ฉํด์ affine mapping์ ์ ๊ทธ๋ฆผ๊ณผ ๊ฐ๋ค. Bit ์(Bit Width)๊ฐ ๋ฎ์์ง๋ฉด ๋ฎ์์ง ์๋ก, floating point์์ ํํํ ์๋ ์ ๋ํ ์ค์ด๋ค ๊ฒ์ด๋ค. ๊ทธ๋ ๋ค๋ฉด Scale์ Zero point๋ ๊ฐ๊ฐ ์ด๋ป๊ฒ ๊ณ์ฐํ ๊น?
์ฐ์ floating-point ์ธ ์ซ์์ ๋ฒ์ ์ค ์ต๋๊ฐ๊ณผ ์ต์๊ฐ์ ๋ง๊ฒ ๋ ์์ ์ธ์ฐ๊ณ ์ด๋ฅผ ์ฐ๋ฆฝ๋ฐฉ์ ์์ผ๋ก Scale๊ณผ Zero point์ ๊ตฌํ ์ ์๋ค.
Scale point
Zero point
์๋ฅผ ๋ค์ด, ์๋์ ๊ฐ์ ์์ ์์
๊ทธ๋ผ Symmetricํ๊ฒ r์ ๋ฒ์๋ฅผ ์ ํํ๋ ๊ฒ๊ณผ ๊ฐ์ ๋ค๋ฅธ Linear Quantization์ ์์๊น? ์ด๋ฅผ ์์, Quatized๋ ๊ฐ๋ค์ด Matrix Multiplication์ ํ๋ฉด์ ๋ฏธ๋ฆฌ ๊ณ์ฐ๋ ์ ์๋ ์ (Quantized Weight, Scale, Zero point)๊ฐ ์์ผ๋ inference์ ์ฐ์ฐ๋์ ์ค์ด๊ธฐ ์ํด ๋ฏธ๋ฆฌ ๊ณ์ฐํ ์ ์๋ ํ๋ผ๋ฏธํฐ๋ ์์๊น?
1.4 Quantized Matrix Multiplication
์ ๋ ฅ X, Weight W, ๊ฒฐ๊ณผ Y๊ฐ Matrix Multiplication์ ํ๋ค๊ณ ํ ๋ ์์ ๊ณ์ฐํด๋ณด์.
์ฌ๊ธฐ์ ๋ง์ง๋ง ์ ๋ฆฌํ ์์ ์ดํด๋ณด๋ฉด,
1.5 Symmetric Linear Quantization
Symmetric Linear Quantization์ ์ฃผ์ด์ง ๋ฐ์ดํฐ์์ Full range mode์ Restrict range mode๋ก ๋๋๋ค.
์ฒซ ๋ฒ์งธ Full range mode ๋ Scale์ real number(๋ฐ์ดํฐ, weight)์์ ๋ฒ์๊ฐ ๋์ ์ชฝ์ ๋ง์ถ๋ ๊ฒ์ด๋ค. ์๋ฅผ ๋ค์ด ์๋์ ๊ฒฝ์ฐ, r_min์ด r_max๋ณด๋ค ์ ๋๊ฐ์ด ๋ ํฌ๊ธฐ ๋๋ฌธ์ r_min์ ๋ง์ถฐ q_min์ ๊ฐ์ง๊ณ Scale์ ๊ตฌํ๋ค. ์ด ๋ฐฉ๋ฒ์ Pytorch native quantization๊ณผ ONNX์์ ์ฌ์ฉ๋๋ค๊ณ ๊ฐ์์์ ์๊ฐํ๋ค.
๋ ๋ฒ์งธ Restrict range mode๋ Scale์ real number(๋ฐ์ดํฐ, weight)์์ ๋ฒ์๊ฐ ์ข์ ์ชฝ์ ๋ง์ถ๋ ๊ฒ์ด๋ค. ์๋ฅผ ๋ค์ด ์๋์ ๊ฒฝ์ฐ, r_min๊ฐ r_max๋ณด๋ค ์ ๋๊ฐ์ด ๋ ํฌ๊ธฐ ๋๋ฌธ์ r_min์ ๋ง์ถ๋ฉด์ q_max์ ๋ง๋๋ก Scale์ ๊ตฌํ๋ค. ์ด ๋ฐฉ๋ฒ์ TensorFlow, NVIDIA TensorRT, Intel DNNL์์ ์ฌ์ฉ๋๋ค๊ณ ๊ฐ์์์ ์๊ฐํ๋ค.
๊ทธ๋ ๋ค๋ฉด ์ Symmetric ์จ์ผํ ๊น? Asymmetric ๋ฐฉ๋ฒ๊ณผ Symmetric ๋ฐฉ๋ฒ์ ์ฐจ์ด๋ ๋ญ๊น? (feat. Neural Network Distiller) ์๋ ๊ทธ๋ฆผ์ ์ฐธ๊ณ ํ๋ฉด ๋์ง๋ง, ๊ฐ์ฅ ํฐ ์ฐจ์ด๋ก ๋ณด์ด๋ ๊ฒ์ Computation vs Compactful quantized range๋ก ์ดํด๊ฐ๋ค.
1.6 Linear Quantization examples
๊ทธ๋ผ Quatization ๋ฐฉ๋ฒ์ ๋ํด ์์๋ดค์ผ๋ ์ด๋ฅผ Full-Connected Layer, Convolution Layer์ ์ ์ฉํด๋ณด๊ณ ์ด๋ค ํจ๊ณผ๊ฐ ์๋์ง ์์๋ณด์.
1.6.1 Full-Connected Layer
์๋์ฒ๋ผ ์์ ์ ๊ฐํด๋ณด๋ฉด ๋ฏธ๋ฆฌ ์ฐ์ฐํ ๊ณ์ฐํ ์ ์๋ ํญ๊ณผ N-bit integer๋ก ํํํ ์๋ ํญ์ผ๋ก ๋๋ ์ ์๋ค(์ ๊ฐํ๋ ์ด์ ๋ ์๋ง ๋ฏธ๋ฆฌ ๊ณ์ฐํ ์ ์๋ ํญ์ ์์๋ณด๊ธฐ ์ํจ์ด ์๋๊น ์ถ๋ค).
๊ฐ๋จํ ํ๊ธฐํ๊ธฐ ์ํด
1.6.2 Convolutional Layer
Convolution Layer์ ๊ฒฝ์ฐ๋ Weight์ X์ ๊ณฑ์ ๊ฒฝ์ฐ๋ฅผ Convolution์ผ๋ก ๋ฐ๊ฟ์ ์๊ฐํด๋ณด๋ฉด ๋๋ค. ๊ทธ๋ ๊ทธ๋ด ๊ฒ์ด Convolution์ Kernel๊ณผ Input์ ๊ณฑ์ ํฉ์ผ๋ก ์ด๋ฃจ์ด์ ธ ์๊ธฐ ๋๋ฌธ์ Full-Connected์ ๊ฑฐ์ ์ ์ฌํ๊ฒ ์ ๊ฐ๋ ์ ์์ ๊ฒ์ด๋ค.
2. Post-training Quantization (PTQ)
๊ทธ๋ผ ์์์ Quantizaedํ Layer๋ฅผ Fine tuningํ ์์๊น? โHow should we get the optimal linear quantization parameters (S, Z)?โ ์ด ์ง๋ฌธ์ ๋ํด์ Weight, Activation, Bias ์ธ ๊ฐ์ง์ ๊ทธ์ ๋ํ์ฌ ๋ ผ๋ฌธ์์ ๋ณด์ฌ์ฃผ๋ ๊ฒฐ๊ณผ๊น์ง ์์๋ณด์.
2.1 Weight quantization
TL;DR. ์ด ๊ฐ์์์ ์๊ฐํ๋ Weight quantization์ Grandularity์ ๋ฐ๋ผ Whole(Per-Tensor), Channel, ๊ทธ๋ฆฌ๊ณ Layer๋ก ๋ค์ด๊ฐ๋ค.
2.1.1 Granularity
Weight quantization์์ Granularity์ ๋ฐ๋ผ์ Per-Tensor, Per-Channel, Group, ๊ทธ๋ฆฌ๊ณ Generalized ํ๋ ๋ฐฉ๋ฒ์ผ๋ก ํ์ฅ์์ผ Shared Micro-exponent(MX) data type์ ์ฐจ๋ก๋ก ๋ณด์ฌ์ค๋ค. Scale์ ๋ช ๊ฐ๋ ๋ ๊ฒ์ด๋, ๊ทธ Scale์ ์ ์ฉํ๋ ๋ฒ์๋ฅผ ์ด๋ป๊ฒ ๋ ๊ฒ์ด๋, ๊ทธ๋ฆฌ๊ณ Scale์ ์ผ๋ง๋ ๋ํ ์ผํ๊ฒ(e.g. floating-point)ํ ๊ฒ์ด๋์ ์ด์ ์ ๋๋ค.
์ฒซ ๋ฒ์งธ๋ Per-Tensor Quantization ํน๋ณํ๊ฒ ์ค๋ช ํ ๊ฒ ์์ด ์ด์ ๊น์ง ์ค๋ช ํ๋ ํ๋์ Scale์ ์ฌ์ฉํ๋ Linear Quantization์ด๋ผ๊ณ ์๊ฐํ๋ฉด ๋๊ฒ ๋ค. ํน์ง์ผ๋ก๋ Large model์ ๋ํด์๋ ์ฑ๋ฅ์ด ๊ด์ฐฎ์ง๋ง ์์ ๋ชจ๋ธ๋ก ๋จ์ด์ง๋ฉด ์ฑ๋ฅ์ด ๊ธ๊ฒฉํ๊ฒ ๋จ์ด์ง๋ค๊ณ ์ค๋ช ํ๋ค. Channel๋ณ๋ก weight ๋ฒ์ฃผ๊ฐ ๋์ ๊ฒฝ์ฐ๋ outlier weight๊ฐ ์๋ ๊ฒฝ์ฐ quantization ์ดํ์ ์ฑ๋ฅ์ด ํ๋ฝํ๋ค๊ณ ๋งํ๋ค.
๊ทธ๋์ ๊ทธ ํด๊ฒฐ๋ฐฉ์์ผ๋ก ๋์ค๋ ๊ฒ์ด ๋ ๋ฒ์งธ ๋ฐฉ๋ฒ์ธ Per-Channel Quantization์ด๋ค. ์ ์์ ์์ ๋ณด๋ฉด Channel ๋ง๋ค ์ต๋๊ฐ๊ณผ ๊ฐ๊ฐ์ ๋ง๋ Scale์ ๋ฐ๋ก ๊ฐ์ง๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ๊ทธ๋ฆฌ๊ณ ์ ์ฉํ ๊ฒฐ๊ณผ์ธ ์๋ ๊ทธ๋ฆผ์ ๋ณด๋ฉด Per-Channel๊ณผ Per-Tensor๋ฅผ ๋น๊ตํด๋ณด๋ฉด Per-Channel์ด ๊ธฐ์กด์ floating point weight์์ ์ฐจ์ด๊ฐ ๋ ์ ๋ค. ํ์ง๋ง, ๋ง์ฝ ํ๋์จ์ด์์ Per-Channel Quantization์ ์ง์ํ์ง ์๋๋ค๋ฉด ๋ถํ์ํ ์ฐ์ฐ์ ์ถ๊ฐ๋ก ํด์ผํ๊ธฐ ๋๋ฌธ์ ์ด๋ ์ ํฉํ ๋ฐฉ๋ฒ์ด ๋ ์ ์๋ค๋ ์ ๋ ๊ณ ๋ คํด์ผํ ๊ฒ์ด๋ค(์ด๋ ์ด์ Tiny Engine์ ๋ํ ๊ธ์์ Channel๋ด์ ์บ์ฑ์ ์ด์ฉํ ์ต์ ํ์ ์ฐ๊ด์ด ์๋ค). ๊ทธ๋ผ ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์์๊น?
์ธ ๋ฒ์งธ ๋ฐฉ๋ฒ์ Group Quantization์ผ๋ก ์๊ฐํ๋ Per-vector Scaled Quantization์ Shared Micro-exponent(MX) data type ์ด๋ค. Per-vector Scaled Quantization์ 2023๋ ๋ ๊ฐ์๋ถํฐ ์๊ฐํ๋๋ฐ, ์ด ๋ฐฉ๋ฒ์ Scale factor๋ฅผ ๊ทธ๋ฃน๋ณ๋ก ํ๋, Per-Tensor๋ก ํ๋๋ก ๋๊ฐ๋ฅผ ๋๋ ๋ฐฉ๋ฒ์ด๋ค. ์๋์ ๊ทธ๋ฆผ์ ๋ณด๋ฉด,
์ฌ๊ธฐ์ ๊ฐ์๋ ์งํ์ธ Memory Overhead๋ก โEffective Bit Widthโ๋ฅผ ์๊ฐํ๋ค. ์ด๋ Microsoft์์ ์ ๊ณตํ๋ Quantization Approach MX4, MX6, MX9๊ณผ ์ฐ๊ฒฐ๋ผ ์๋๋ฐ, ์ด ๋ฐ์ดํฐํ์ ์ ์กฐ๊ธ ์ดํ์ ๋ ์์ธํ ์ค๋ช ํ ๊ฒ์ด๋ค. Effective Bit Width? ์์ ํ๋๋ฅผ ๋ค์ด ์ดํดํด๋ณด์. ๋ง์ฝ 4-bit Quatization์ 4-bit per-vector scale์ 16 elements(4๊ฐ์ weight๊ฐ ๊ฐ๊ฐ 4bit๋ฅผ ๊ฐ์ง๋ค๊ณ ์๊ฐํ๋ฉด 16 element๋ก ๊ณ์ฐ๋๋ค ์ ์ถํ ์๋ค) ๋ผ๋ฉด, Effective Bit Width๋ 4(Scale bit) + 4(Vector Scale bit) / 16(Vector Size) = 4.25๊ฐ ๋๋ค. Element๋น Scale bit๋ผ๊ณ ๊ฐ๋จํ๊ฒ ์๊ฐํ ์๋ ์์ ๋ฏ ์ถ๋ค.
๋ง์ง๋ง Per-vector Scaled Quantization์ ์ดํดํ๋ค๋ณด๋ฉด ์ด์ ์ Per-Tensor, Per-Channel๋ ๊ทธ๋ฃน์ผ๋ก ์ผ๋ง๋งํผ ๋ฌถ๋ ์ฐจ์ด๊ฐ ์๊ณ , ์ด๋ ์ด๋ค์ ์ผ๋ฐํํ ์ ์์ด ๋ณด์ธ๋ค. ๊ฐ์์์ ๋ฐ๋ก ๋ค์์ ์๊ฐํ๋ ๋ฐฉ๋ฒ์ด ๋ฐ๋ก Multi-level scaling scheme์ด๋ค. Per-Channel Quantization์ Per-Vector Quantization(VSQ, Vector-Scale Quantization)๋ถํฐ ๋ด๋ณด์.
Per-Channel Quantization๋ Scale factor๊ฐ ํ๋๋ก Effective Bit Width๋ 4๊ฐ ๋๋ค. ๊ทธ๋ฆฌ๊ณ VSQ๋ ์ด์ ์ ๊ณ์ฐํ ๋ฏ 4.25๊ฐ ๋ ๊ฒ์ด๋ค(์ฐธ๊ณ ๋ก Per Channel๋ก ์ ์ฉ๋๋ Scale์ ๊ฒฝ์ฐ element์ ์๊ฐ ๋ง์์ ๊ทธ๋ฐ์ง ๋ฐ๋ก Effective Bit Width๋ก ๊ณ์ฐํ์ง๋ ์๋๋ค). VSQ๊น์ง ๋ณด๋ฉด์ Effective Bit Width๋,
Effective Bit Width = Scale bit + Group 0 Scale bit / Group 0 Size +...
e.g. VSQ Data type int4 = Scale bit (4) + Group 0 Scale bit(4) / Group 0 Size(16) = 4.25
์ด๋ ๊ฒ ๊ณ์ฐํ ์ ์๋ค. ๊ทธ๋ฆฌ๊ณ , MX4, MX6, MX9๊ฐ ๋์จ๋ค. ์ฐธ๊ณ ๋ก S๋ Sign bit, M์ Mantissa bit, E๋ Exponent bit๋ฅผ ์๋ฏธํ๋ค(Mantissa๋ Exponent์ ๋ํ ์์ธํ ๋ด์ฉ์ floating point vs fixed point ๊ธ์ ์ฐธ๊ณ ํ์). ์๋๋ Microsoft์์ ์ ๊ณตํ๋ Quantization Approach MX4, MX6, MX9์ ๋ํ ํ์ด๋ค.
2.1.2 Weight Equalization
์ฌ๊ธฐ๊น์ง Weight Quatization์์ ๊ทธ๋ฃน์ผ๋ก ์ผ๋ง๋งํผ ๋ฌถ๋์ง์ ๋ฐ๋ผ(๊ฐ์์์๋ Granularity) Quatization์ ํ๋ ์ฌ๋ฌ ๋ฐฉ๋ฒ์ ์๊ฐํ๋ค. ๋ค์์ผ๋ก ์๊ฐ ํ ๋ฐฉ๋ฒ์ Weight Equalization์ด๋ค. 2022๋ ์ ์๊ฐํด์ค ๋ด์ฉ์ธ๋ฐ, ์ด๋ i๋ฒ์งธ layer์ output channel๋ฅผ scaling down ํ๋ฉด์ i+1๋ฒ์งธ layer์ input channel์ scaling up ํด์ Scale๋ก ์ธํด Quantization ์ ํ๋ก ์๊ธฐ๋ Layer๊ฐ ์ฐจ์ด๋ฅผ ์ค์ด๋ ๋ฐฉ๋ฒ์ด๋ค.
์๋ฅผ ๋ค์ด ์์ ๊ทธ๋ฆผ์ฒ๋ผ Layer i์ output channel๊ณผ Layer i+1์ input channel์ด ์๋ค. ์ฌ๊ธฐ์ ์์ ์ ๊ฐํ๋ฉด ์๋์ ๊ฐ์๋ฐ,
where
์ฌ๊ธฐ์ Scale(S)๊ฐ i+1๋ฒ์งธ layer์ weight์, i๋ฒ์งธ weight์ 1/S ๋ก Scale๋ ๋ ๊ธฐ์กด์ Scale ํ์ง ์์ ์๊ณผ ์ ์ฌํ๊ฒ ์ ์งํ ์๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ์ฆ,
์ด๋ ๊ฒ ํ๋ฉด i๋ฒ์งธ layer์ output channel๊ณผ i+1๋ฒ์งธ layer์ input channel์ Scale์ ๊ฐ๊ฐ
2.1.3 Adaptive rounding
$$ ### 2.2 Activation quantization ๋ ๋ฒ์งธ๋ก Activation quantization์ด ์๋ค. ๋ชจ๋ธ๊ฒฐ๊ณผ๋ก ๋์ค๋ ๊ฒฐ๊ณผ๋ฅผ ์ง์ ์ ์ผ๋ก ๊ฒฐ์ ํ๋ Activation Quatization์์๋ ๋ ๊ฐ์ง๋ฅผ ๊ณ ๋ คํ ๋ฐฉ๋ฒ์ ์๊ฐํ๋ค. ํ๋๋ Activation ๋ ์ด์ด์์ ๊ฒฐ๊ณผ๊ฐ์ Smoothingํ ๋ถํฌ๋ฅผ ๊ฐ์ง๊ฒ ํ๊ธฐ ์ํด Exponential Moving Average(EMA)๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ด๊ณ , ๋ค๋ฅธ ํ๋๋ ๋ค์ํ ์ ๋ ฅ๊ฐ์ ๊ณ ๋ คํด batch samples์ FP32 ๋ชจ๋ธ๊ณผ calibrationํ๋ ๋ฐฉ๋ฒ์ด๋ค.
Exponential Moving Average (EMA)์ ์๋ ์์์
๋ง์ง๋ง์ผ๋ก Quatization์ผ๋ก biased error๋ฅผ ์ก๋๋ค๋ ๊ฒ์ ์๊ฐํ๋ค.
2.4 Post-Training INT8 Linear Quantization Result
์์ Post-Training Quantization์ ์ ์ฉํ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋ค. ์ด๋ฏธ์ง๊ณ์ด ๋ชจ๋ธ์ ๋ชจ๋ ์ฌ์ฉํ์ผ๋ฉฐ, ์ฑ๋ฅํ๋ฝํญ์ ์งํ๋ก ๋ณด์ฌ์ค๋ค. ๋น๊ต์ ํฐ ๋ชจ๋ธ๋ค์ ๊ฒฝ์ฐ ์ค์ํ ์ฑ๋ฅ์ ๋ณด์ฌ์ฃผ์ง๋ง MobileNetV1, V2์ ๊ฐ์ ์์ ๋ชจ๋ธ์ ์๊ฐ๋ณด๋ค Quantization์ผ๋ก ๋จ์ด์ง๋ ์ฑ๋ฅํญ(-11.8%, -2.1%) ์ด ํฐ ๊ฒ์ ๋ณผ ์ ์๋ค. ๊ทธ๋ผ ์์ ํฌ๊ธฐ์ ๋ชจ๋ธ๋ค์ ์ด๋ป๊ฒ Training ํด์ผํ ๊น?
3. Quantization-Aware Training(QAT)
3.1 Quantization-Aware Training
- Usually, fine-tuning a pre-trained floating point model provides better accuracy than training from scratch.
์ด์ ์ K-mean Quantization์์ Fine-tuning๋ Centroid์ gradient๋ฅผ ๋ฐ์ํ์๋ค. Quantization-Aware Training์ ์ด์ ์ ์ฌํ๊ฒ Quantization - Reconstruction์ ํตํด ๋ง๋ค์ด์ง Weight๋ก Training์ ํ๋ ๋ฐฉ๋ฒ์ ๋งํ๋ค. ์์๋ฅผ ๋ค์ด์ ์์ธํ ์ดํด๋ณด์.
- A full precision copy of the weights W is maintained throughout the training.
- The small gradients are accumulated without loss of precision
- Once the model is trained, only the quantized weights are used for inference
์ ๊ทธ๋ฆผ์์ Layer N์ด ๋ณด์ธ๋ค. ์ด Layer N์ weights๋ฅผ ํ๋ผ๋ฏธํฐ๋ก ๊ฐ์ง์ง๋ง, ์ค์ ๋ก Training ๊ณผ์ ์์ ์ฐ์ด๋ weight๋ โweight quantizationโ์ ํตํด Quantization - Reconstruction์ ํตํด ๋ง๋ค์ด์ง Weight๋ฅผ ๊ฐ์ง๊ณ ํ๋ จ์ ํ ๊ฒ์ด๋ค.
3.2 Straight-Through Estimator(STE)
๊ทธ๋ผ ํ๋ จ์์ gradient๋ ์ด๋ป๊ฒ ์ ๋ฌํ ์ ์์๊น? Quantization์ ๊ฐ๋ ์, weight quantization์์ weight๋ก ๋์ด๊ฐ๋ gradient๋ ์์ ์ ๋ฐ์ ์๋ค. ๊ทธ๋ ๊ฒ ๋๋ฉด ์ฌ์ค์ weight๋ก back propagation์ด ๋ ์ ์๊ฒ ๋๊ณ , ๊ทธ๋์ ์๊ฐํ๋ ๊ฐ๋ ์ด Straight-Through Estimator(STE) ์ ๋๋ค. ๋ง์ด ๊ฑฐ์ฐฝํด์ ๊ทธ๋ ์ง, Q(W)์์ ๋ฐ์ gradient๋ฅผ ๊ทธ๋๋ก weights ๋ก ๋๊ฒจ์ฃผ๋ ๋ฐฉ์์ด๋ค.
Quantization is discrete-valued, and thus the derivative is 0 almost everywhere โ NN will learn nothing!
Straight-Through Estimator(STE) simply passes the gradients through the quantization as if it had been the identity function.
- Reference
- Neural Networks for Machine Learning [Hinton et al., Coursera Video Lecture, 2012]
- Estimating or Propagating Gradients Through Stochastic Neurons for Conditional Computation [Bengio, arXiv 2013]
์ด ํ๋ จ์ ๊ฒฐ๊ณผ๊ฐ ๊ถ๊ธํ์๋ค๋ฉด ์ด ๋ ผ๋ฌธ์ ์ฐธ๊ณ ํ์. ์ฐธ๊ณ ๋ก ๋ ผ๋ฌธ์์๋ MobileNetV1, V2 ๊ทธ๋ฆฌ๊ณ NASNet-Mobile์ ์ด์ฉํด Post-Training Quantization๊ณผ Quantization-Aware Training์ ๋น๊ตํ๊ณ ์๋ค.
4. Binary and Ternary Quantization
์, ๊ทธ๋ผ Quantization์ ๊ถ๊ทน์ ์ผ๋ก 2bit๋ก ํ ์๋ ์์๊น? ๋ฐ๋ก Binary(1, -1)๊ณผ Tenary(1, 0, -1) ์ด๋ค.
Can we push the quantization precision to 1 bit?
Reference. MIT-TinyML-lecture06-Quantization-2 Reference
- BinaryConnect: Training Deep Neural Networks with Binary Weights during Propagations [Courbariaux et al., NeurIPS 2015]
- XNOR-Net: ImageNet Classification using Binary Convolutional Neural Networks [Rastegari et al., ECCV 2016]
๋จผ์ Weight๋ฅผ 2bit๋ก Quantization์ ํ๊ฒ ๋๋ฉด, ๋ฉ๋ชจ๋ฆฌ์์๋ 32bit๋ฅผ 1bit๋ก ์ค์ด๋ 32๋ฐฐ๋ ์ค์ผ ์ ์๊ณ , Computation๋ (8x5)+(-3x2)+(5x0)+(-1x1)์์ 5-2+0-1 ๋ก ์ ๋ฐ์ ์ค์ผ ์ ์๋ค.
4.1 Binarization: Deterministic Binarization
๊ทธ๋ผ Binarization์์ +1๊ณผ -1์ ์ด๋ค ๊ธฐ์ค์ผ๋ก ํด์ผํ ๊น? ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ์ threhold๋ฅผ ๊ธฐ์ค์ผ๋ก +-1๋ก ๋๋๋ ๊ฒ์ด๋ค.
Directly computes the bit value base on a threshold, usually 0 resulting in a sign function.
4.2 Binarization: Stochastic Binarization
๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก๋ output์์ hard-sigmoid function์ ๊ฑฐ์ณ์ ๋์จ ๊ฐ๋งํผ ํ๋ฅ ์ ์ผ๋ก +-1์ด ๋์ค๋๋ก ํ๋ ๊ฒ์ด๋ค. ํ์ง๋ง ์ด ๋ฐฉ๋ฒ์ ๋ฌด์์๋ก ๋นํธ๋ฅผ ์์ฑํ๋ ํ๋์จ์ด๋ฅผ ํ๋ ๊ฒ์ด ์ด๋ ต๊ธฐ ๋๋ฌธ์ ์ฌ์ฉํ์ง ์๋๋ค๊ณ ์ธ๊ธํ๋ค.
Use global statistics or the value of input data to determine the probability of being -1 or +1
In Binary Connect(BC), probability is determined by hard sigmoid function
Reference. MIT-TinyML-lecture06-Quantization-2 Harder to implement as it requires the hardware to generate random bits when quantizing.
4.3 Binarization: Use Scale
์์ ๋ฐฉ๋ฒ์ ์ด์ฉํด์ ImageNet Top-1 ์ ํ๊ฐํด๋ณด๋ฉด Quantization์ดํ -21.2%๋ ์ฑ๋ฅ์ด ํ๋ฝํ๋ ๊ฑธ ๋ณผ ์ ์๋ค. โ์ด๋ป๊ฒ ๋ณด์ํ ์ ์์๊น?โ ํ ๊ฒ์ด linear qunatization์์ ์ฌ์ฉํ๋ Scale ๊ฐ๋ ์ด๋ค.
Using Scale, Minimizing Quantization Error in Binarization
Reference. MIT-TinyML-lecture06-Quantization-2
์ฌ๊ธฐ์ Scale์
Why
is ?- Reference. XNOR-Net: ImageNet Classification using Binary Convolutional Neural Networks [Rastegari et al., ECCV 2016]
- B*๋ J(B,
)์์ ์ต์๊ฐ์ ๊ตฌํด์ผํ๋ฏ๋ก B ๊ฐ ์ต๋์ฌ์ผํ๊ณ ๊ทธ๋ฌ๊ธฐ ์ํด์๋ W๊ฐ ์์์ผ๋๋ B๋ ์์, W๊ฐ ์์์ผ ๋๋ B๋ ์์์ฌ์ผ ์ด ๋๋ฉด์ ์ต๋๊ฐ์ด ๋ ์ ์๋ค.
4.4 Binarization: Activation
๊ทธ๋ผ Activation๊น์ง Quantization์ ํด๋ด ์๋ค.
4.4.1 Activation
์ฌ๊ธฐ์ ์กฐ๊ธ ๋ ์ฐ์ฐ์ ์ต์ ํ ํ ์ ์์ด๋ณด์ด๋ ๊ฒ์ด Matrix Muliplication์ด XOR ์ฐ์ฐ๊ณผ ๋น์ทํ๊ฒ ๋ณด์ธ๋ค.
4.4.2 XNOR bit count
โ popcount returns the number of 1
๊ทธ๋์ popcount๊ณผ XNOR์ ์ด์ฉํด์ Computation์์ ์ข ๋ ์ต์ ํ๋ฅผ ์งํํฉ๋๋ค. ์ด๋ ๊ฒ ์ต์ ํ๋ฅผ ์งํํ๊ฒ ๋๋ฉด, ๋ฉ๋ชจ๋ฆฌ๋ 32๋ฐฐ, Computation์ 58๋ฐฐ๊ฐ๋ ์ค์ด๋ค ์ ์๋ค๊ณ ๋งํ๋ค.
์ด๋ ๊ฒ Weight, Scale factor, Activation, ๊ทธ๋ฆฌ๊ณ XNOR-Bitcout ๊น์ง. ์ด ๋ค ๊ฐ์ง ๋จ๊ณ๋ก Binary Quantization์ ๋๋๋ค. ๋ค์์ผ๋ก๋ Ternary Quantization์ ์์๋ณด์.
- Binarizing Input ์ ๊ฒฝ์ฐ๋ average๋ฅผ ๋ชจ๋ channel์ ๊ฐ์ด ์ ์ฉํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ๊ทธ c๋งํผ์ average filter๋ก ํ ๋ฒ์ ์ ์ฉํ๋ค๋ ๋ง์ด๋ค.
4.5 Ternary Weight Networks(TWN)
Ternary๋ Binary Quantization๊ณผ ๋จ๊ณ๋ ๋ชจ๋ ๊ฐ์ง๋ง, ๊ฐ์ง ์ ์๋ ๊ฐ์ผ๋ก 0 ์ ์ถ๊ฐํ๋ค. ์๋ ๊ทธ๋ฆผ์ Scale์ ์ด์ฉํด์ Quantization Error๋ฅผ ์ค์ด๋ ๋ฐฉ๋ฒ์ ๋งํ๊ณ ์๋ค. ### 4.6 Trained Ternary Quantization(TTQ)
Tenary Quantization์์ ๋ ํ๊ฐ์ง ๋ค๋ฅด๊ฒ ์ค๋ช
ํ๋ ๊ฒ์ 1๊ณผ -1๋ก๋ง ์ ํด์ ธ ์๋ Binary Quantization๊ณผ ๋ค๋ฅด๊ฒ Tenary๋ 1, 0, -1๋ก Quantization์ ํ ํ, ์ถ๊ฐ์ ์ธ ํ๋ จ์ ํตํด
4.7 Accuracy Degradation
Binary, Ternary Quantization์ ์ฌ์ฉํ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋ค(Resnet-18 ๊ฒฝ์ฐ์๋ Ternary ๊ฐ ์คํ๋ ค Binary๋ณด๋ค ์ฑ๋ฅ์ด ๋ ๋จ์ด์ง๋ค!)
Binarization
Reference. Binarized Neural Networks: Training Deep Neural Networks with Weights and Activations Constrained to +1 or โ1. [Courbariaux et al., Arxiv 2016], XNOR-Net: ImageNet Classification using Binary Convolutional Neural Networks [Rastegari et al., ECCV 2016] Ternary Weight Networks (TWN)
Reference. Ternary Weight Networks [Li et al., Arxiv 2016] Trained Ternary Quantization (TTQ)
Reference. Trained Ternary Quantization [Zhu et al., ICLR 2017]
5. Low Bit-Width Quantization
๋จ์ ๋ถ๋ถ๋ค์ ์ฌ๋ฌ๊ฐ์ง ์คํ / ์ฐ๊ตฌ๋ค์ ์๊ฐํ๊ณ ์๋ค.
- Binary Quantization์ Quantization Aware Training์ ํ ์ ์์๊น?
- 2,3 bit๊ณผ 8bit ๊ทธ ์ค๊ฐ์ผ๋ก๋ Quantization์ ํ ์ ์์๊น?
- ๋ ์ด์ด์์ Quantization์ ํ์ง ์๋ ๋ ์ด์ด, ์๋ฅผ ๋ค์ด ๊ฒฐ๊ณผ์ ์ํฅ์ ์๋ฏผํ๊ฒ ๋ฏธ์น๋ ์ฒซ ๋ฒ์งธ ๋ ์ด์ด๊ฐ ๊ฐ์ ๊ฒฝ์ฐ Quantization์ ํ์ง ์์ผ๋ฉด ์ด๋ป๊ฒ ๋ ๊น?
- Activation ํจ์๋ฅผ ๋ฐ๊พธ๋ฉด ์ด๋จ๊น?
- ์๋ฅผ ๋ค์ด ์ฒซ๋ฒ์งธ ๋ ์ด์ด์ N๋ฐฐ ๋๊ฒ ํ๋ ๊ฒ๊ณผ ๊ฐ์ด ๋ชจ๋ธ ๊ตฌ์กฐ๋ฅผ ๋ฐ๊พธ๋ฉด ์ด๋ป๊ฒ ๋ ๊น?
- ์กฐ๊ธ์ฉ Quantization์ ํ ์ ์์๊น? (20% โ 40% โ โฆ โ 100%)
๊ฐ์์์๋ ํฌ๊ฒ ์ธ๊ธํ์ง ์๊ณ ๊ฐ ๋ด์ฉ๋ค์ด๋ผ ์ค๋ช ์ ํ์ง๋ ์๊ฒ ๋ค. ํด๋น ๋ด์ฉ๋ค์ ์์ธํ ๋ด์ฉ์ ์๊ณ ์ถ์ผ๋ฉด ๊ฐ ํํธ์ ์ธ๊ธ๋ ๋ ผ๋ฌธ์ ์ฐธ์กฐํ๊ธธ!
5.1 Train Binarized Neural Networks From Scratch
- Straight-Through Estimator(STE)
- Gradient pass straight to floating-point weights
- Floating-point weight with in [-1, 1]
- Reference. Binarized Neural Networks: Training Deep Neural Networks with Weights and Activations Constrained to +1 or โ1. [Courbariaux et al., Arxiv 2016]
5.2 Quantization-Aware Training: DoReFa-Net With Low Bit-Width Gradients
Gradient Quantization
- Noise function
is added to compensate the potential bias introduced by gradient quantization.
- Noise function
Result
Reference. DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients [Zhou et al., arXiv 2016]
5.3 Replace the Activation Function: Parameterized Clipping Activation Function
The most common activation function ReLU is unbounded. The dynamic range of inputs becomes problematic for low bit-width quantization due to very limited range and resolution.
ReLU is replaced with hard-coded bounded activation functions: ReLU6, ReLU1, etc
The clipping value per layer can be learned as well: PACT(Parametrized Clipping Activation Function)
The upper clipping value of the activation function is a trainable. With STE, the gradient is computed as
The larger
, the more the parameterized clipping function resembles a ReLU function- To avoid large quantization errors due to a wide dynamic range
, L2-regularizer for is included in the training loss function.
- To avoid large quantization errors due to a wide dynamic range
Result
Reference. PACT: Parameterized Clipping Activation for Quantized Neural Networks [Choi et al., arXiv 2018]
5.4 Modify the Neural Network Architecture
Widen the neural network to compensate for the loss of information due to quantization
ex. Double the channels, reduce the quantization precision
Reference. WRPN: Wide Reduced-Precision Networks [Mishra et al., ICLR 2018] Replace a single floating-point convolution with multiple binary convolutions.
- Towards Accurate Binary Convolutional Neural Network [Lin et al., NeurIPS 2017]
- Quantization [Neural Network Distiller]
5.5 No Quantization on First and Last Layer
- Because it is more sensitive to quantization and small portion of the overall computation
- Quantizing these layers to 8-bit integer does not reduce accuracy
5.6 Iterative Quantization: Incremental Network Quantization
- Reference. Incremental Network Quantization: Towards Lossless CNNs with Low-precision Weights [Zhou et al., ICLR 2017]
- Setting
- Weight quantization only
- Quantize weights to
for faster computation (bit shift instead of multiply)
- Algorithm
- Start from a pre-trained fp32 model
- For the remaining fp32 weights
- Partition into two disjoint groups(e.g., according to magnitude)
- Quantize the first group (higher magnitude), and re-train the other group to recover accuracy
- Repeat until all the weights are quantized (a popular stride is {50%, 75%, 87.5%, 100%})
Reference. MIT-TinyML-lecture06-Quantization-2
6. Mixed-precision quantization
๋ง์ง๋ง์ผ๋ก ๋ ์ด์ด๋ง๋ค Quantization bit๋ฅผ ๋ค๋ฅด๊ฒ ๊ฐ์ ธ๊ฐ๋ฉด ์ด๋จ์ง์ ๋ํด์ ์ด์ผ๊ธฐํ๋ค. ํ์ง๋ง ๊ฒฝ์ฐ์ ์๊ฐ 8bit ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ๊ฒ Quantization์ ํ ์, weight์ activation๋ก ๊ฒฝ์ฐ์ ์๋ฅผ ๊ณ ๋ ค๋ฅผ ํ๋ค๋ฉด N๊ฐ ๋ ์ด์ด์ ๋ํด์
6.1 Uniform Quantization
6.2 Mixed-precision Quantization
6.3 Huge Design Space and Solution: Design Automation
Design Space: Each of Choices(8x8=64) โ
Reference. HAQ: Hardware-Aware Automated Quantization with Mixed Precision [Wang et al., CVPR 2019] Result in Mixed-Precision Quantized MobileNetV1
Reference. HAQ: Hardware-Aware Automated Quantization with Mixed Precision [Wang et al., CVPR 2019] - This paper compares with Model size, Latency and Energy
๊ฐ์ฅ ๋ง์ง๋ง์ ์ธ๊ธํ๋ Edge์ ํด๋ผ์ฐ๋์์๋ Convolution ๋ ์ด์ด์ ์ข ๋ฅ ์ค ๋ํ๊ณ ๋ Quantizationํ๋ ๋ ์ด์ด๊ฐ ๊ฐ๊ฐ depthwise์ pointwise๋ก ๋ค๋ฅด๋ค๊ณ ์ด์ผ๊ธฐํ๋ค. ์ด ๋ด์ฉ์ ๋ํด์ ๋ ์์ธํ ์ดํดํ๊ธฐ ์ํด์๋ ์๋ง๋ NAS๋ก ๋์ด๊ฐ๋ด์ผ ์ ์ ์์ง ์์๊น ์ถ๋ค.
Quantization Policy for Edge and Cloud
Reference. HAQ: Hardware-Aware Automated Quantization with Mixed Precision [Wang et al., CVPR 2019]
7. Reference
- TinyML and Efficient Deep Learning Computing on MIT HAN LAB
- Youtube for TinyML and Efficient Deep Learning Computing on MIT HAN LAB
- Deep Compression [Han et al., ICLR 2016]
- Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference [Jacob et al., CVPR 2018]
- With Shared Microexponents, A Little Shifting Goes a Long Way [Bita Rouhani et al.]
- Data-Free Quantization Through Weight Equalization and Bias Correction [Markus et al., ICCV 2019]
- Estimating or Propagating Gradients Through Stochastic Neurons for Conditional Computation [Bengio, arXiv 2013]
- Binarized Neural Networks: Training Deep Neural Networks with Weights and Activations Constrained to +1 or โ1. [Courbariaux et al., Arxiv 2016]
- XNOR-Net: ImageNet Classification using Binary Convolutional Neural Networks [Rastegari et al., ECCV 2016]
- Ternary Weight Networks [Li et al., Arxiv 2016]
- Trained Ternary Quantization [Zhu et al., ICLR 2017]
- DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients [Zhou et al., arXiv 2016]
- WRPN: Wide Reduced-Precision Networks [Mishra et al., ICLR 2018]
- PACT: Parameterized Clipping Activation for Quantized Neural Networks [Choi et al., arXiv 2018]
- HAQ: Hardware-Aware Automated Quantization with Mixed Precision [Wang et al., CVPR 2019]