Skip to main content

ferrum_quantization/
config.rs

1//! Quantization configuration parsed from model metadata.
2//!
3//! Populated by `WeightLoader` implementations from sources like
4//! `quantize_config.json` (GPTQ/AWQ) or a GGUF header.
5
6use serde::{Deserialize, Serialize};
7
8/// The quantization scheme in use, if any.
9#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
10#[serde(rename_all = "lowercase")]
11#[derive(Default)]
12pub enum QuantMethod {
13    /// No quantization — dense fp32/fp16/bf16 weights.
14    #[default]
15    None,
16    /// GPTQ: int4/int8 group-wise with scales + zeros, asymmetric.
17    Gptq,
18    /// AWQ: int4 group-wise, similar to GPTQ but different packing.
19    Awq,
20    /// GGUF: k-quants and legacy quants embedded in a single-file format.
21    Gguf,
22}
23
24/// Combined quantization config.
25#[derive(Clone, Debug, Serialize, Deserialize, Default)]
26pub struct QuantConfig {
27    pub method: QuantMethod,
28    /// Bit-width (typically 4 or 8 for GPTQ/AWQ).
29    #[serde(default)]
30    pub bits: u32,
31    /// Group size for group-wise scales (typically 128).
32    #[serde(default)]
33    pub group_size: usize,
34    /// Whether to use descending activation order (GPTQ only).
35    #[serde(default)]
36    pub desc_act: bool,
37    /// Whether scales use symmetric quantization.
38    #[serde(default)]
39    pub sym: bool,
40}