Move activation scale without changing the real linear map
Distinguish exact inverse rescaling from the approximation introduced by quantizing the rescaled tensors.
On this page
The question for today
What you’ll understand
- Derive inverse channel rescaling for a declared matrix orientation.
- Identify graph edges and operations that prevent naive scale folding.
- Distinguish SmoothQuant, AWQ and mixed-precision outlier decomposition.
A few large activation channels can force a shared quantizer to use steps too coarse for the remaining channels. One response is to change the representation before quantization: divide an activation channel by a factor and multiply the corresponding weight channel by the same factor. The real linear map remains unchanged, but the two tensors present different ranges to their quantizers. That separation between exact reparameterization and approximate quantization is essential.
Write the orientation before moving scales
Use row activations X with shape tokens by input channels and weights W with shape input channels by output channels, so Y=XW. Let S be an invertible diagonal matrix of positive channel factors. Then X times inverse S and S times W produce the same Y in exact arithmetic. Scaling the wrong weight dimension is not an approximation of this identity; it is a different linear operation. The factors must be finite and nonzero, and their chosen numerical precision must avoid overflow or underflow.
Smoothing redistributes a range problem rather than eliminating it. Reducing a large activation channel can increase magnitudes in the corresponding weights and stretch their quantization groups. SmoothQuant selects such factors using activation and weight statistics to support weight-and-activation quantization. Its empirical quality results concern the models and settings tested in the paper. The algebra proves equivalence before rounding; it cannot prove that both newly quantized tensors, their product or the final language model will retain a particular accuracy.
Check the whole graph when folding factors
To avoid an extra runtime scaling kernel, a compiler may fold inverse factors into the preceding operation. This is legal only when that graph transformation preserves every consumer. If one activation feeds three projections, each affected path must receive the corresponding compensation or retain an explicit scaling operation. Moving a diagonal factor across an arbitrary nonlinearity or residual addition is not generally valid. Biases, normalization parameters and shared tensors require separate treatment; a locally correct matrix identity does not automatically justify a whole-graph rewrite.
Keep the related algorithms distinct. AWQ uses activation information to choose channel rescaling that protects important weights during weight-only quantization; it does not perform GPTQ’s approximate second-order compensation of remaining weights. LLM.int8 instead separates selected outlier dimensions into a higher-precision contribution alongside a quantized contribution. Those are different numerical and kernel contracts. Combining their names does not combine their published results or make all intermediate tensors integer-only. Compare the actual exported representation and supported kernels, not an algorithm label alone.
Measure the trade after the exact rewrite
First test the unquantized transformed graph against the original using controlled finite-precision tolerances. Then quantize and measure activation clipping, weight reconstruction and task-level changes independently. If the first comparison already fails badly, calibration cannot repair an incorrect rewrite. Select smoothing strength on calibration or development data and preserve an untouched final evaluation. Extreme factors can amplify scale rounding or require unsupported kernel ranges, so inspect representability as well as the apparent reduction of activation maxima.
For an axis-scaling analogy, Reset the matrix lab and set both a=0.25 and b=0. Predict determinant 0.25, and that the first basis vector maps to one quarter of its length while the second is unchanged. Play interpolates geometry; readouts remain those of the selected matrix. The compensating inverse scale four must be applied on paper to the matching weight channel. This restricted matrix family neither quantizes values nor verifies that a neural-network graph permits folding the factors.
Work it through
Verify an exact two-channel reparameterization
Use row activation x=[8,1], W=[[1,2],[3,4]] and S=diag(4,1). Compute the original output, the rescaled tensors and their product in exact arithmetic before introducing any quantizer.
The original output is [8 times 1 plus 1 times 3, 8 times 2 plus 1 times 4]=[11,20]. These two values provide the reference for testing orientation and compensation.
The activation becomes x times inverse S=[2,1]. Multiplying S times W scales its first row, yielding [[4,8],[3,4]]. The activation maximum falls from 8 to 2, while the weight maximum increases from 4 to 8.
Multiply [2,1] by the transformed weights: [2 times 4 plus 1 times 3, 2 times 8 plus 1 times 4]=[11,20]. Both outputs match exactly. Quantizing either transformed tensor would introduce new errors that this equality has not bounded.
Correctly paired inverse scales preserve the real output while shifting range between activations and weights. Whether that trade helps a concrete quantized model remains an empirical question.
The living notebook
Explore the model
Interactive lab · matrix
Identify the rescaled channel
Reset → set a=0.25 and b=0 → predict determinant 0.25 and first-axis compression. Play interpolates the shape; the inverse weight compensation is a separate paper calculation.
- Area scale · det A
- 1.4
- Singular values · σmax, σmin
- 1.597, 0.876
- Condition number · κ₂(A)
- 1.823
The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA channel transform needs its inverse on the matching linear-map dimension. This geometry does not implement smoothing or quantization.
Pause & reason
Check your understanding
Your turn
Try it yourself
Let x=[6,2], W=[[2,1],[1,3]] and S=diag(3,1). Compute the reference and transformed outputs. What happens if the activation is rescaled but W is left unchanged?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The first weight row must multiply by three, matching the first activation channel divided by three.
Compare with the solution
The reference is [14,12]. The transformed activation is [2,2] and weights [[6,3],[1,3]], producing [14,12]. Leaving W unchanged gives [6,8], which is a wrong linear map even before quantization. A smaller activation range alone therefore does not establish a valid graph transformation.
Keep the idea
Take it with you
- Inverse rescaling is exact only with matching axes and compensation.
- Graph consumers, nonlinearities and shared tensors constrain scale folding.
- SmoothQuant, AWQ and LLM.int8 use distinct approximation and execution strategies.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.