axonml_quant/lib.rs
1//! Model quantization for AxonML — GGUF formats + BitNet I2_S ternary.
2//!
3//! `types` (QuantType enum, block structs for Q8_0/Q4_0/Q4_1/Q5_0/Q5_1/F16),
4//! `quantize` (tensor/model quantization with RMSE error analysis),
5//! `dequantize` (block/tensor reconstruction to f32), `bitnet` (I2_S 1.58-bit
6//! ternary — 128-weight blocks, fused add-only matmul, int8 activation
7//! quantizer, AVX-VNNI dispatch scaffolded), `calibration` (MinMax/Percentile/
8//! MeanStd/Entropy methods), `inference` (QuantizedLinear drop-in layer,
9//! QuantizedModel wrapper), `error` (QuantError/QuantResult).
10//!
11//! # File
12//! `crates/axonml-quant/src/lib.rs`
13//!
14//! # Author
15//! Andrew Jewell Sr. — AutomataNexus LLC
16//! ORCID: 0009-0005-2158-7060
17//!
18//! # Updated
19//! April 14, 2026 11:15 PM EST
20//!
21//! # Disclaimer
22//! Use at own risk. This software is provided "as is", without warranty of any
23//! kind, express or implied. The author and AutomataNexus shall not be held
24//! liable for any damages arising from the use of this software.
25
26#![warn(missing_docs)]
27#![warn(clippy::all)]
28#![allow(clippy::module_name_repetitions)]
29#![allow(clippy::must_use_candidate)]
30#![allow(clippy::missing_errors_doc)]
31
32pub mod bitnet;
33pub mod calibration;
34pub mod dequantize;
35pub mod error;
36pub mod inference;
37pub mod quantize;
38pub mod types;
39
40pub use calibration::{CalibrationData, calibrate};
41pub use dequantize::{dequantize_block, dequantize_tensor};
42pub use error::{QuantError, QuantResult};
43pub use inference::{QuantizedLinear, QuantizedModel, deserialize_quantized, serialize_quantized};
44pub use quantize::{quantize_model, quantize_tensor};
45pub use types::{QuantType, QuantizedBlock, QuantizedTensor};
46
47// =============================================================================
48// Constants
49// =============================================================================
50
51/// Default block size for quantization.
52pub const DEFAULT_BLOCK_SIZE: usize = 32;
53
54/// Maximum block size supported.
55pub const MAX_BLOCK_SIZE: usize = 256;
56
57// =============================================================================
58// Tests
59// =============================================================================
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_constants() {
67 assert!(DEFAULT_BLOCK_SIZE > 0);
68 assert!(MAX_BLOCK_SIZE >= DEFAULT_BLOCK_SIZE);
69 }
70}