01/02 built quantize and dequantize as isolated operations. The actual reason anyone quantizes a real model is a tradeoff: smaller storage and faster integer arithmetic, in exchange for some amount of accuracy loss — and "some amount" needs to be an actual measured number, not just an assumption, before shipping a quantized model.
Implement quantize_weight_matrix(weight), which quantizes a whole weight matrix with one shared scale/zero_point, then reports both sides of the tradeoff: the compression ratio achieved, and the reconstruction error that compression cost.
weight: any-shape float32 array (e.g. a real layer's weight matrix).quantized, scale, zero_point, compression_ratio, max_abs_error, mean_abs_error.compression_ratio assumes the original was stored as float32 (4 bytes/element) and the quantized version as int8 (1 byte/element) — always exactly 4.0 for this dtype pair, regardless of the matrix's actual values.max_abs_error/mean_abs_error: plain Python floats, computed against the dequantized reconstruction.Open one at a time. Each gives away a little more than the last.
This is almost entirely composition: call 01's quantize and 02's dequantize, and this question's own job is just computing and packaging the tradeoff numbers around them.
compression_ratio doesn't depend on the matrix's actual content at all — it's a fixed 4.0 from 4 bytes / 1 byte, the same for every float32-to-int8 quantization regardless of shape or values.
No results yet
Run your code to check it against the examples, or submit to run every test.