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 compressed_tensors_marlin_source;
20pub mod dense;
21pub mod gguf;
22pub mod gptq;
23pub mod gptq_marlin_source;
24pub mod loader;
25pub mod lora;
26pub mod native_safetensors;
27pub mod quant_linear;
28pub mod safetensors_archive;
29pub mod traits;
30
31pub use compressed_tensors_marlin_source::{
32    CompressedTensorsMarlinSafetensorsSource, COMPRESSED_TENSORS_MARLIN_INT4_FORMAT_ID,
33};
34pub use dense::DenseLinear;
35pub use gguf::{GgufFile, GgufLinear, GgufLoader, GgufWeightComponentSource};
36pub use gptq::{GptqLinear, StackedExpertLinear};
37pub use gptq_marlin_source::{GptqMarlinSafetensorsSource, GPTQ_MARLIN_INT4_FORMAT_ID};
38pub use loader::{PrefixedLoader, WeightLoader};
39pub use lora::LoraLinearRef;
40pub use native_safetensors::NativeSafetensorsLoader;
41pub use quant_linear::QuantLinear;
42pub use safetensors_archive::{SafetensorsArchive, SafetensorsTensor};
43pub use traits::Linear;
44
45// Quant config types — populated from safetensors metadata or GGUF header.
46pub mod config;
47pub use config::{QuantConfig, QuantMethod};