EfficientML.ai Lecture 5 - Quantization (Part I) (MIT 6.5940 Fall 2026)
Overview
Quantization reduces neural-network storage and computation by representing values with fewer bits, building on the lecture's review of integer and floating-point formats such as FP32, FP16, and BF16. It compares K-means codebook quantization, which compresses weights but retains floating-point computation, with affine linear quantization, which enables integer arithmetic; it also connects quantization with pruning, Huffman coding, and compact architectures such as SqueezeNet.
Key takeaways
- Reducing a stored value from 32 bits to 4 bits cuts the data moved per value by eight times, and reduced memory traffic can save energy because data movement may cost up to 200 times more than computation.
- BF16 preserves FP32's 8-bit exponent range while using only 7 fraction bits, making it useful when dynamic range matters more than mantissa precision.
- K-means quantization stores compact codebook indices but still needs floating-point codebook lookups and computation; a 4-entry codebook reduces the lecture's 4 × 4 matrix from 64 bytes to 20 bytes.
- Deep Compression orders its methods as pruning, K-means quantization, then Huffman coding; pruning before quantization preserves more flexibility for fine-tuning the remaining weights.
- Affine quantization uses R = S × (Q - Z), with S = (Rmax - Rmin) / (Qmax - Qmin) and a rounded integer zero point, enabling integer matrix multiplication and convolution with precomputed corrections.
- SqueezeNet's compact architecture combined with Deep Compression was reported to be about 500 times smaller than AlexNet at the same accuracy, illustrating the value of designing small models before applying compression.
Chapters
- Quantization reduces the bit width used for parameters and activations, complementing pruning, which reduces their number.
- Moving a 4-bit integer takes one-eighth the data of a 32-bit float, reducing memory traffic.
- Data movement can consume up to 200 times more energy than computation, making lower-precision storage valuable.
- An unsigned n-bit integer represents values from 0 to 2^n minus 1.
- Two's complement uses one zero representation and covers negative values, unlike sign-magnitude representation with separate positive and negative zeros.
- Fixed-point values use a set number of fractional bits; the example 3.0625 can be represented by summing bit values or scaling an integer by 2^-4.
- IEEE FP32 allocates 1 sign bit, 8 exponent bits, and 23 fraction or mantissa bits.
- A normal value uses a signed significand of 1 plus the fraction, multiplied by 2 raised to the exponent minus the bias.
- The FP32 exponent bias is 127, allowing the exponent field to encode positive and negative powers of two.
- An all-zero exponent indicates subnormal values, which omit the implicit leading 1 and use an exponent of 1 minus the bias.
- For FP32, the smallest positive subnormal is 2^-149, and the largest is (1 - 2^-23) × 2^-126.
- An all-one exponent with a zero fraction represents positive or negative infinity; an all-one exponent with a nonzero fraction represents NaN.
- IEEE FP16 uses 5 exponent bits and 10 fraction bits, while BF16 uses 8 exponent bits and 7 fraction bits.
- BF16 preserves FP32's exponent width and therefore its broad dynamic range, trading away fraction precision.
- The worked conversions decode an FP16 bit pattern as -7 and encode 2.5 in BF16 using its sign, biased exponent, and fraction.
- NVIDIA FP8 E4M3 and E5M2 allocate bits differently: E5M2 has greater dynamic range, useful for gradients, while E4M3 offers more mantissa precision.
- Four-bit formats have few representable values; E2M1 places more levels near zero and increasingly spaces them apart, matching concentrated neural-network weight distributions.
- The lecture contrasts E2M1 with linear integer representations and E3M0, which maximizes range at the cost of mantissa precision.
- K-means groups similar floating-point weights around centroids, then stores an integer index for each weight and a floating-point codebook.
- In the 4 × 4 example, weights near 2 map to a centroid of 2, while values near -1 map to a centroid of -1.
- With four codebook entries, each weight needs a 2-bit index; including the codebook, the example shrinks from 64 bytes to 20 bytes, or 3.2 times smaller.
- During fine-tuning, gradients for weights assigned to the same centroid are summed, and the centroid is updated using the learning rate.
- The lecture's AlexNet results show convolution weights can reach about 4-bit quantization and fully connected weights about 2-bit before accuracy loss.
- Combining pruning and quantization preserves accuracy at smaller model sizes than either method alone, with retraining adjusting centroids to recover accuracy.
- Deep Compression applies pruning first, K-means quantization second, and Huffman coding third.
- Pruning and retraining can reduce model size by roughly 9 to 13 times; adding quantization yields reported reductions around 27 to 31 times.
- Huffman coding assigns shorter bit patterns to frequent weight indices and longer ones to rare indices, though variable-length codes can make hardware processing less regular.
- SqueezeNet uses 1 × 1 convolutions to reduce channels, followed by 1 × 1 and 3 × 3 branches, then expands channels again.
- Combining a compact architecture with Deep Compression made SqueezeNet about 500 times smaller than AlexNet at the same reported accuracy.
- K-means codebooks save storage but require weight lookup and floating-point computation; linear quantization instead targets integer weights and integer arithmetic.
- Linear quantization maps an integer Q to a real value R using R = S × (Q - Z), where S is a scale and Z is an integer zero point.
- For a 2-bit signed range from -2 to 1, the example matrix spans -1.08 to 2.12 and gives a scale of about 1.07.
- The zero point is rounded to the nearest integer so real zero maps exactly to an integer value, avoiding quantization error at zero.
- Substituting affine quantized weights and activations into Y = WX produces integer products plus zero-point correction terms.
- Symmetric weight distributions often allow the weight zero point to be set to zero; constant corrections can be precomputed, and scaling can use integer multiplication followed by shifts.
- The same approach extends to Y = WX + B and convolution, using integer accumulation, quantized bias, and output scaling.
- Reported 8-bit integer models recovered nearly all FP32 accuracy on ResNet-50 and Inception-v3, with latency and accuracy trading off against each other.
- K-means quantization reduces storage but retains floating-point computation, whereas linear quantization can reduce both storage and computation.
- The lecture closes by introducing binary and ternary quantization as the next topic and directing students to the EfficientML.ai lab materials.
Transcript excerpt
0:00 Test. Test. Okay. All right. Let's get it started. Welcome to efficient ml.ai. Today is lecture five. We are going to talk about quantization. So in the last lecture we talked about pruning, how to reduce the number of parameters. We can reduce the number of parameters and activations by 10 times or three times without hurting the accuracy if you properly fine tune it. We also talked about how to find the optimal sparsity ratio for different layers using both automated approach and also rule-based approach. Now we are going to dive into the next chapter, which is quantization. Beyond reducing the number of parameters, we can also reduce the bit width for each parameter. You don't need
0:49 a full precision, but we can use integer bits or low precision bit to represent the number. So in this lecture we'll first review the numeric data types including integers and floating point. We're also going to learn the basic concepts of neural network quantization and the three types of network quantization method, which is K-means based approach, the linear quantization, and also binary and ternary quantization. Some background. The uh computation is cheap, but memory is expensive. So if you go lower precision, if you have less precision, you need to fetch fewer number of bits and also the you fetch less number of bits, so you
1:37 reduce the num- memory movement. For example, if you have to move 32-bit floating point versus you just need to move 4-bit integer, you can save eight times uh less memory and have fewer um memory traffic. And less memory means it's more energy efficient. Data movement can be as much as 200 times more energy consuming compared with computation. So, let's first talk about numeric data types. How are the numbers actually
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, MIT HAN Lab.