Expand description
§quantize
A tiny, readable quantization library — block-wise symmetric or asymmetric, any bit width.
§Example
use quantize::quantize;
let weights = [0.42_f32, -0.10, 0.70, -0.50];
// 8-bit, block-size-32, f32 scales
let q = quantize::<f32, 8, 32>(&weights).unwrap();
let back = q.dequantize();
assert!((back[0] - weights[0]).abs() < 0.01);BITS and BLOCK are const generics, so quantize::<f32, 4, 32>(...),
quantize::<f32, 8, 64>(...), etc. all compile to specialized code.
See symmetric, asymmetric, and adaptive for the other schemes.
To learn how the library got here, please see chapters/.
Modules§
- adaptive
- Mixed-precision: pick bits per block from a tolerance.
- asymmetric
- Asymmetric quantization: scale and zero-point per group.
- error
- Recoverable failures from quantization and dequantization.
- learned
- After codes are chosen, pick a better scale and zero-point.
- packed
- Bit-packed signed integer codes.
- params
- Integer grids, scale selection, and mixed-precision bit choice.
- scale
- Scale trait — how per-block scale factors are stored.
- scheme
- Runtime scheme selection — one entry point, scheme-specific I/O inside.
- symmetric
- Symmetric quantization: one scale per group, codes centered on zero.
- tensor
- One enum, one variant per scheme.
Structs§
- Packed
- Packed signed codes plus the bit width they were written with.
Enums§
- Error
- An error produced by a fallible quantization API.
- Quantized
- Packed codes and the scheme that produced them.
- Scheme
- Which algorithm to run. Pick this from config or a CLI flag; the returned
Quantizedvariant is the scheme that ran.
Traits§
- Scale
- A type that can serve as a per-block scale (or zero-point) factor.
Functions§
- quantize
- Quantize
valuesinto fixed-size blocks ofBLOCKwithBITS-wide codes. - quantize_
tensor - Quantize the entire tensor with a single scale.
Type Aliases§
- Result
- Result alias for this crate.