Per-Tensor vs Per-Channel Quantization
What You'll Learn
You'll understand how choosing different quantization granularities—applying one scale factor to an entire tensor versus using separate scales for each channel—affects model accuracy and compression.
The Granularity Trade-off
When quantizing weights or activations, you must decide how many scale factors to use. This is where per-tensor and per-channel quantization differ:
Per-Tensor Quantization uses a single scale (and zero-point) for the entire tensor. If you have a weight matrix of shape [64, 128, 3, 3] (64 output channels, 128 input channels, 3×3 kernels), one scale factor quantizes all ~74,000 values. This is simple and fast but can lose precision when the tensor contains values with very different ranges.
Per-Channel Quantization uses separate scale factors for each output channel. In the same [64, 128, 3, 3] tensor, you'd have 64 different scales—one per output channel. Each channel's values are quantized using its own scale, preserving information when different channels have dramatically different ranges.
Why Per-Channel Works Better
Think of it like adjusting audio levels: per-tensor quantization uses one volume knob for all instruments in an orchestra, while per-channel gives each instrument its own knob. If the drums are loud and flutes are quiet, per-channel preserves both better.
In convolutional layers, different filters often learn to detect different features with varying activation magnitudes. Per-channel quantization respects these differences, typically recovering 1-2% accuracy lost in per-tensor quantization.
The cost? Slightly more complex implementation and marginally increased memory for storing multiple scales (though negligible compared to weight savings).
Key Takeaway: Per-channel quantization uses separate scale factors for each output channel, preserving accuracy better than per-tensor's single scale, especially when channel activation ranges differ significantly.