nodedb_codec/vector_quant/ternary/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! BitNet b1.58 ternary quantization codec.
4//!
5//! Encodes FP32 vectors into ternary trits `{-1, 0, +1}` using per-vector
6//! mean-absolute-value (absmean) scaling. Two storage layouts are supported:
7//!
8//! - **Cold** ([`QuantMode::TernaryPacked`]): 5 trits/byte via base-3 packing
9//! (1.6 bpw). Optimal for disk; decompressed on page-in.
10//! - **Hot** ([`QuantMode::TernarySimd`]): 2 bpw, 4 trits/byte, suitable for
11//! direct SIMD load. [`VectorCodec::encode`] produces hot format by default.
12//!
13//! [`QuantMode::TernaryPacked`]: crate::vector_quant::layout::QuantMode::TernaryPacked
14//! [`QuantMode::TernarySimd`]: crate::vector_quant::layout::QuantMode::TernarySimd
15//! [`VectorCodec::encode`]: crate::vector_quant::codec::VectorCodec::encode
16
17pub mod codec;
18pub mod packing;
19pub mod simd;
20
21pub use codec::{TernaryCodec, TernaryQuantized, TernaryQuery};
22pub use packing::{cold_to_hot, pack_cold, pack_hot, quantize, unpack_cold, unpack_hot};
23pub use simd::ternary_dot;