Skip to main content

quantize/
lib.rs

1//! # quantize
2//!
3//! A tiny, readable quantization library — block-wise symmetric or asymmetric,
4//! any bit width.
5//!
6//! ## Example
7//!
8//! ```
9//! use quantize::quantize;
10//!
11//! let weights = [0.42_f32, -0.10, 0.70, -0.50];
12//!
13//! // 8-bit, block-size-32, f32 scales
14//! let q = quantize::<f32, 8, 32>(&weights).unwrap();
15//! let back = q.dequantize();
16//!
17//! assert!((back[0] - weights[0]).abs() < 0.01);
18//! ```
19//!
20//! `BITS` and `BLOCK` are const generics, so `quantize::<f32, 4, 32>(...)`,
21//! `quantize::<f32, 8, 64>(...)`, etc. all compile to specialized code.
22//!
23//! See `symmetric`, `asymmetric`, and `adaptive` for the other schemes.
24//! To learn how the library got here, please see `chapters/`.
25
26mod kernels;
27mod methods;
28mod shared;
29
30pub use methods::{adaptive, asymmetric, learned, symmetric};
31
32pub use shared::error::{Error, Result};
33pub use shared::packed::Packed;
34pub use shared::scale::Scale;
35pub use shared::scheme::Scheme;
36pub use shared::tensor::Quantized;
37pub use shared::{error, packed, params, scale, scheme, tensor};
38pub use symmetric::{quantize, quantize_tensor};
39
40pub(crate) use shared::decode;