ferrum_quantization/traits.rs
1//! Re-export of `Linear` trait (canonical home: ferrum-kernels) plus
2//! `LinearFactory` for weight-loader-side Linear construction.
3//!
4//! The trait itself lives in `ferrum-kernels::linear` so that Backend-level
5//! helpers (`layer_forward_fused`) can reference it without ferrum-kernels
6//! depending on this crate (which would be circular).
7
8use ferrum_kernels::backend::Backend;
9
10pub use ferrum_kernels::Linear;
11
12/// Factory for constructing `Linear<B>` from raw loaded tensors.
13///
14/// A `WeightLoader` will typically hold a `LinearFactory<B>` and call it
15/// for each layer weight. This indirection keeps the loader independent
16/// of any specific `Backend`.
17pub trait LinearFactory<B: Backend>: Send + Sync {
18 /// Build a dense `Linear` from an already-materialised weight buffer.
19 ///
20 /// `weight_row_major`: `[out_features, in_features]` laid out contiguously.
21 fn dense(
22 &self,
23 weight_row_major: &[f32],
24 out_features: usize,
25 in_features: usize,
26 ) -> Box<dyn Linear<B>>;
27}