pub struct QuantizedLinear { /* private fields */ }Expand description
Affine map x @ W^T + b whose weight stays packed in a QuantMatrix.
QuantizedLinear is the model-level quantized-inference contract: the
weight is frozen at quantization time, exposes no trainable parameters,
and the forward pass dequantizes inside the dispatch rather than
materializing an F32 weight on the device. State-dict round-trips run the
standard quantize-on-export flow — checkpoints carry the F32 module and
from_linear re-derives the packed planes.
Implementations§
Source§impl QuantizedLinear
impl QuantizedLinear
Sourcepub fn from_linear(linear: &Linear, quantization: Quantization) -> Result<Self>
pub fn from_linear(linear: &Linear, quantization: Quantization) -> Result<Self>
Quantize an existing super::Linear’s weight into quantization.
The bias, when the source module carries one, moves into this module unchanged as a persistent buffer.
§Errors
Returns an error when the weight fails the crate::ml::matrix::quantize
contract or buffer registration fails.
Sourcepub fn from_quantized(weight: QuantMatrix, bias: Option<Matrix>) -> Result<Self>
pub fn from_quantized(weight: QuantMatrix, bias: Option<Matrix>) -> Result<Self>
Wrap an already-quantized [N, K] weight and optional [N] bias.
§Errors
Returns an error when the weight is not rank 2, the bias is not [N],
or buffer registration fails.
Sourcepub const fn input_features(&self) -> usize
pub const fn input_features(&self) -> usize
Return the accepted input feature count K.
Sourcepub const fn output_features(&self) -> usize
pub const fn output_features(&self) -> usize
Return the produced output feature count N.
Sourcepub const fn quantization(&self) -> Quantization
pub const fn quantization(&self) -> Quantization
Return the packed weight format.
Sourcepub const fn weight(&self) -> &QuantMatrix
pub const fn weight(&self) -> &QuantMatrix
Return the packed weight value.
Trait Implementations§
Source§impl Module for QuantizedLinear
impl Module for QuantizedLinear
Source§fn forward(&self, input: &Matrix) -> Result<Matrix>
fn forward(&self, input: &Matrix) -> Result<Matrix>
Source§fn registry(&self) -> &ModuleRegistry
fn registry(&self) -> &ModuleRegistry
Source§fn parameters(&self) -> Vec<Parameter>
fn parameters(&self) -> Vec<Parameter>
Source§fn named_parameters(&self) -> Vec<NamedParameter>
fn named_parameters(&self) -> Vec<NamedParameter>
Source§fn named_buffers(&self) -> Vec<NamedBuffer>
fn named_buffers(&self) -> Vec<NamedBuffer>
Source§fn all_parameters(&self) -> Result<Vec<Parameter>>
fn all_parameters(&self) -> Result<Vec<Parameter>>
Source§fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
Source§fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
Source§fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
u32 scalar state in
deterministic depth-first order. Read more