pub struct QuantizedLinear {
pub weight: Array,
pub scales: Array,
pub biases: Array,
pub bias: Option<Array>,
pub group_size: usize,
pub bits: u32,
}Expand description
A Linear layer with its weight quantized (MLX’s nn.QuantizedLinear): x Wᵀ + b
computed by quantized_matmul from the packed weight, its scales and biases.
The packed weight, scales and biases are frozen; the bias stays trainable, as in MLX.
Fields§
§weight: ArrayThe packed weight (uint32), [output_dims, input_dims · bits / 32].
scales: ArrayOne scale per group of input values, [output_dims, input_dims / group_size].
biases: ArrayOne bias per group of input values, shaped like scales.
bias: Option<Array>The layer’s bias, [output_dims].
group_size: usizeInput values per scale and bias.
bits: u32Bits per weight.
Implementations§
Source§impl QuantizedLinear
impl QuantizedLinear
Sourcepub fn from_linear(
linear: &Linear,
group_size: usize,
bits: u32,
) -> Result<Self>
pub fn from_linear( linear: &Linear, group_size: usize, bits: u32, ) -> Result<Self>
Quantizes linear’s weight in groups of group_size (32, 64 or 128) input values
with bits (1–6 or 8) bits each; the bias is kept. MLX’s defaults are 64 and 4.
Sourcepub fn dequantized_weight(&self) -> Result<Array>
pub fn dequantized_weight(&self) -> Result<Array>
The dequantized weight, [output_dims, input_dims].
Trait Implementations§
Source§impl Clone for QuantizedLinear
impl Clone for QuantizedLinear
Source§impl Debug for QuantizedLinear
impl Debug for QuantizedLinear
Source§impl Module for QuantizedLinear
impl Module for QuantizedLinear
Source§fn visit(&mut self, p: &mut Parameters<'_>)
fn visit(&mut self, p: &mut Parameters<'_>)
Reports every parameter and submodule to
p, frozen ones included.Source§fn parameters(&self) -> Vec<(String, Array)>
fn parameters(&self) -> Vec<(String, Array)>
Every parameter with its path (
layers.0.weight), in visiting order.Source§fn trainable_parameters(&self) -> Vec<(String, Array)>
fn trainable_parameters(&self) -> Vec<(String, Array)>
The parameters that are trained (not frozen), with their paths.
Source§fn update_trainable(&mut self, values: &[Array]) -> Result<()>
fn update_trainable(&mut self, values: &[Array]) -> Result<()>
Replaces the trainable parameters, given in the order of
Module::trainable_parameters (as optimizers return them).Source§fn load_weights(
&mut self,
weights: impl IntoIterator<Item = (String, Array)>,
strict: bool,
) -> Result<()>
fn load_weights( &mut self, weights: impl IntoIterator<Item = (String, Array)>, strict: bool, ) -> Result<()>
Replaces parameters by path, as MLX’s
load_weights: each weight must have its
parameter’s shape (the dtype is kept as loaded). With strict, every parameter
must be given and no unknown names are allowed.Auto Trait Implementations§
impl Freeze for QuantizedLinear
impl RefUnwindSafe for QuantizedLinear
impl Send for QuantizedLinear
impl Sync for QuantizedLinear
impl Unpin for QuantizedLinear
impl UnsafeUnpin for QuantizedLinear
impl UnwindSafe for QuantizedLinear
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more