Quantization and pruning trade-offs
Quick answer
Quantization represents values with fewer bits; pruning removes or zeros selected parameters. Either can reduce model storage, but performance and quality must be measured on the intended execution path. Examples use Python and NumPy 2.3.5. Timing examples use fixed synthetic values; actual benchmark timings are in the milestone. ByteMind execution is unverified.
Symmetric quantization
import numpy as npw=np.array([-2.,0.,2.]);scale=2/127q=np.rint(w/scale).astype(np.int8)print(q.tolist(),np.allclose(q*scale,w))Expected output (locally tested): [-127, 0, 127] True. Scale is required to recover the approximate values.
How it works
For simple symmetric int8 weight quantization, choose scale=max(abs(w))/127 for a nonzero tensor, compute q=clip(round(w/scale),-127,127), reconstruct w_hat=scale*q. For an all-zero tensor use a nonzero scale convention. Per-channel scales may improve reconstruction. This lesson stores int8 weights but reconstructs float32 for inference; it is not an integer matrix-multiply kernel. Include scales and metadata in any storage comparison. Quantization-aware training and calibration of activations are separate techniques. Magnitude pruning can set small weights to zero; dense storage remains unchanged unless compressed or structurally reduced, and dense kernels may not skip zeros. Structured pruning can shrink dimensions but changes architecture. Compare output error and task metrics on a frozen representative fixture, especially decisions near thresholds. Use explicit acceptance criteria defined before the test. A smaller artifact or lower numerical error alone does not imply production readiness.
Dense pruning storage
import numpy as npw=np.array([1,.01,2,.02],dtype=np.float32); p=np.where(abs(w)<.1,0,w)print(np.count_nonzero(p),w.nbytes,p.nbytes)Expected output (locally tested): 2 16 16. Zeros do not shrink a dense array.
Common mistakes
Do not label float reconstruction as native int8 inference. Do not claim a dense zeroed tensor uses fewer bytes. Do not select compression parameters by repeatedly inspecting final test labels.
Practice and next steps
Quantize a small weight vector, reconstruct it and compute maximum error. Zero two entries and check whether dense payload bytes change.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Quantization and pruning trade-offs — knowledge check
Apply quantization and pruning trade-offs to small examples and debugging scenarios.
What must accompany symmetric int8 weights?
Does dense zeroing reduce ndarray.nbytes?
What does dequantize-then-matmul execute?
Which metric should accompany numerical parity?
How should compression acceptance be set?