#![cfg_attr(
test,
allow(
clippy::expect_used,
clippy::unwrap_used,
clippy::disallowed_methods,
clippy::float_cmp,
clippy::panic,
clippy::cast_precision_loss
)
)]
#![warn(missing_docs)]
mod dequantize;
pub mod ggml_type;
pub mod iq;
mod quantize;
mod transpose;
#[cfg(test)]
mod tests;
#[cfg(test)]
mod roundtrip_fidelity_tests;
pub use dequantize::{dequantize_q4_k_to_f32, dequantize_q5_k_to_f32, dequantize_q6_k_to_f32};
pub use quantize::{
quantize_q4_k, quantize_q4_k_matrix, quantize_q5_k, quantize_q5_k_matrix, quantize_q6_k,
quantize_q6_k_matrix,
};
pub use transpose::{transpose_q4k_for_matmul, transpose_q5k_for_matmul, transpose_q6k_for_matmul};
pub use iq::{dequantize_iq_to_f32, iq_block_layout, IqDequantError};
pub use ggml_type::{
GgmlFamily, GgmlType, GgmlTypeError, QuantTraits, ALL, GGML_TYPE_COUNT, TRAITS,
};
pub const F16_MIN_NORMAL: f32 = 6.1e-5;
pub const Q4_K_BLOCK_SIZE: usize = 256;
pub const Q4_K_BLOCK_BYTES: usize = 144;
pub const Q5_K_BLOCK_SIZE: usize = 256;
pub const Q5_K_BLOCK_BYTES: usize = 176;
pub const Q6_K_BLOCK_SIZE: usize = 256;
pub const Q6_K_BLOCK_BYTES: usize = 210;
const _: () = {
assert!(Q4_K_BLOCK_SIZE == TRAITS[GgmlType::Q4K.as_id() as usize].blck_size as usize);
assert!(Q4_K_BLOCK_BYTES == TRAITS[GgmlType::Q4K.as_id() as usize].type_size as usize);
assert!(Q5_K_BLOCK_SIZE == TRAITS[GgmlType::Q5K.as_id() as usize].blck_size as usize);
assert!(Q5_K_BLOCK_BYTES == TRAITS[GgmlType::Q5K.as_id() as usize].type_size as usize);
assert!(Q6_K_BLOCK_SIZE == TRAITS[GgmlType::Q6K.as_id() as usize].blck_size as usize);
assert!(Q6_K_BLOCK_BYTES == TRAITS[GgmlType::Q6K.as_id() as usize].type_size as usize);
};
#[inline]
#[must_use]
pub fn f32_to_f16(value: f32) -> u16 {
half::f16::from_f32(value).to_bits()
}
#[inline]
#[must_use]
pub fn f16_to_f32(bits: u16) -> f32 {
half::f16::from_bits(bits).to_f32()
}