Choose scale granularity with its metadata cost
Relate logical axes and groups to precision, storage and kernel compatibility.
On this page
The question for today
What you’ll understand
- Name the logical axis or group to which each scale belongs.
- Compute packed payload and scale metadata separately.
- Explain why more scales can improve resolution without guaranteeing task quality.
A single scale forces every element sharing it to negotiate one range. That negotiation becomes expensive when one output channel has values a hundred times larger than another. Per-axis and grouped schemes spend additional metadata and kernel work to reduce this conflict. Choosing granularity means choosing which elements must share a compromise, while making the mapping from logical elements to scale entries completely unambiguous.
Scale scope is a logical statement
Per-tensor quantization assigns one scale and zero point to the whole tensor. Per-channel is more precisely per-axis: one pair applies to each slice along a named logical dimension. For a weight matrix stored as output channels by input channels, per-output-channel scales index the first dimension. Transposing the matrix changes the physical arrangement and the axis number unless the representation carries the corresponding mapping. Never infer scale semantics from whichever dimension happens to be contiguous in one packed kernel layout.
Consider two rows [0.1,-0.1] and [10,-10]. With symmetric codes -127 through 127, a shared maximum magnitude of 10 gives scale 10/127. The small row then has roughly one code step available near its values. Independent row scales give the small row a hundred times finer spacing. This is a resolution argument, not proof of better generated answers: downstream sensitivity, correlations and clipping policy still determine how the altered errors affect a model.
Groups buy flexibility with overhead
Grouped quantization partitions a row or another declared axis into blocks, often so nearby weights share a scale. State the group size, direction, treatment of an incomplete final group and whether zero points are present. Smaller groups can isolate large magnitudes, but they need more metadata loads and can constrain vectorization. A group containing only a few elements may spend as many bytes on scales as on codes. Padding groups to a hardware tile can further enlarge the actual stored representation.
For a clean accounting exercise, assume N weights partition exactly into groups of G, b packed bits per code and h metadata bytes per group. Payload and metadata add; neither replaces the other. A symmetric format can omit zero points, while an affine format may need them. If scales are stored with reduced precision, their reconstruction error becomes part of the numerical model too. A theoretical byte count must be labeled as such until alignment, headers and packing have been specified.
Verify the format the kernel consumes
A checkpoint with per-row scales cannot be relabeled as per-group merely because a runtime expects the latter. Conversion may require unpacking, reconstructing and requantizing, introducing another approximation. Test a small matrix whose rows have deliberately different scales and compare decoded logical elements before running a large multiply. Include partial groups in this test suite. This catches axis swaps that can leave every array shape legal while multiplying a row by the scale intended for a different channel.
The matrix lab offers a limited geometric analogy for changing one axis independently. Reset and set both diagonal a=0.5 and shear b=0. Predict determinant 0.5 and a unit square compressed horizontally while the vertical coordinate remains unchanged; Play interpolates the geometry, while readouts describe the final selected matrix. This instrument has only two parameters and no quantization groups. Use it to articulate which coordinate is scaled, then return to the explicit logical group map in the tensor contract.
Work it through
Include group metadata in compression
Store 1,024 weights with four-bit packed codes, groups of 32 weights, one two-byte scale per group and no zero points. Assume exact packing, no padding or headers, and compare with two-byte floating-point weights.
The code payload occupies 1,024 times 4 divided by 8, or 512 bytes. This counts only packed codes; treating each four-bit code as a whole byte would describe a different unpacked representation.
There are 1,024 divided by 32, or 32 groups. At two bytes per scale their metadata occupies 64 bytes. The quantized representation therefore totals 576 bytes under the stated exclusions.
The floating-point payload is 1,024 times 2, or 2,048 bytes. Dividing 2,048 by 576 gives approximately 3.56 times compression, below the fourfold payload-only ratio. The difference is entirely explained by declared scale metadata.
The format uses 576 bytes rather than 512. Compression is about 3.56 times before implementation-specific storage overhead, and says nothing by itself about error or runtime speed.
The living notebook
Explore the model
Interactive lab · matrix
State which axis receives the scale
Reset, set both a=0.5 and b=0, and predict determinant 0.5. Play shows interpolation toward the selected transform; numerical readouts always describe that transform.
- 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 forAxis-specific scaling has explicit geometry, but this two-dimensional matrix family does not quantize tensors or choose group sizes.
Pause & reason
Check your understanding
Your turn
Try it yourself
Repeat the storage calculation for the same 1,024 four-bit weights with groups of 16 and two-byte scales. What is the compression ratio against 2,048 bytes, and what tradeoff changed?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
There are twice as many groups, while code payload is unchanged. Divide the original byte count by the new total rather than by code bytes alone.
Compare with the solution
There are 64 groups and 128 metadata bytes. Add the unchanged 512-byte payload for 640 bytes total; 2,048/640=3.2 times compression. Finer groups can reduce range sharing, but increase metadata. The arithmetic alone cannot establish an accuracy improvement or account for padding and kernel overhead.
Keep the idea
Take it with you
- Per-channel names an axis, not a universal physical layout.
- Group metadata reduces the payload-only compression ratio.
- Decode and test scale mappings before trusting a packed multiply.
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.