ferrum_quantization/factory.rs
1//! `DefaultLinearFactory` — materialises dense f32 weights into
2//! `DenseLinear<B>`. Used by any `WeightLoader` implementation that wants
3//! delegate the "f32 slice → Linear" step without tying itself to a
4//! particular backend.
5
6use ferrum_kernels::backend::Backend;
7
8use crate::dense::DenseLinear;
9use crate::traits::{Linear, LinearFactory};
10
11/// The baseline factory: produces `DenseLinear<B>` from row-major f32 weights.
12///
13/// Loaders handling GPTQ / AWQ / GGUF bypass this factory and build their
14/// own `Linear` variants directly. `DefaultLinearFactory` only exists so
15/// non-quantized paths have one well-known implementation.
16pub struct DefaultLinearFactory;
17
18impl<B: Backend> LinearFactory<B> for DefaultLinearFactory {
19 fn dense(
20 &self,
21 weight_row_major: &[f32],
22 out_features: usize,
23 in_features: usize,
24 ) -> Box<dyn Linear<B>> {
25 Box::new(DenseLinear::<B>::from_rows(
26 weight_row_major,
27 out_features,
28 in_features,
29 ))
30 }
31}