Skip to main content

ferrum_quantization/
lib.rs

1//! Weight-format abstraction for Ferrum models.
2//!
3//! Separates "what is the weight matrix like" (dense f32, GPTQ int4, AWQ,
4//! GGUF, ...) from "what device does the math" (Backend) and "how does the
5//! model wire things together" (model code).
6//!
7//! Usage in model code:
8//! ```ignore
9//! let qkv: Box<dyn Linear<B>> = loader.load_linear("model.layers.0.self_attn.qkv_proj")?;
10//! qkv.forward(ctx, &input, &mut out, m);
11//! ```
12//!
13//! The `Linear` trait dispatches to the appropriate backend kernel
14//! (`B::gemm` for Dense, `B::gemm_gptq` for GPTQ, etc.) without the model
15//! having to branch on quantization type.
16
17#![forbid(unsafe_op_in_unsafe_fn)]
18
19pub mod dense;
20pub mod gguf;
21pub mod gptq;
22pub mod gptq_marlin_source;
23pub mod loader;
24pub mod lora;
25pub mod native_safetensors;
26pub mod quant_linear;
27pub mod safetensors_archive;
28pub mod traits;
29
30pub use dense::DenseLinear;
31pub use gguf::{GgufFile, GgufLinear, GgufLoader, GgufWeightComponentSource};
32pub use gptq::{GptqLinear, StackedExpertLinear};
33pub use gptq_marlin_source::{GptqMarlinSafetensorsSource, GPTQ_MARLIN_INT4_FORMAT_ID};
34pub use loader::{PrefixedLoader, WeightLoader};
35pub use lora::LoraLinearRef;
36pub use native_safetensors::NativeSafetensorsLoader;
37pub use quant_linear::QuantLinear;
38pub use safetensors_archive::{SafetensorsArchive, SafetensorsTensor};
39pub use traits::Linear;
40
41// Quant config types — populated from safetensors metadata or GGUF header.
42pub mod config;
43pub use config::{QuantConfig, QuantMethod};