pub struct Quantized {
pub weight: Array,
pub scales: Array,
pub biases: Option<Array>,
pub quant: Quant,
}Expand description
Quantized weights: packed codes (uint32), one scale per group (affine: the weights’ dtype; floating-point modes: uint8 codes), affine biases, and how they were quantized.
use nuvec_core::{DType, QuantMode, ops::ones};
let w = ones([2, 64], DType::F32);
let q = w.quantize(QuantMode::Mxfp4);
assert_eq!((q.weight.shape(), q.scales.shape(), q.biases.is_none()), (&[2, 8][..], &[2, 2][..], true));
assert_eq!(q.dequantize(DType::F32).to_vec::<f32>().unwrap(), vec![1.0; 128]);Fields§
§weight: ArrayThe packed codes (uint32, last dimension values · bits / 32).
scales: ArrayOne scale per group (last dimension values / group_size).
biases: Option<Array>One bias per group: affine only.
quant: QuantHow the weights were quantized.
Implementations§
Source§impl Quantized
impl Quantized
Sourcepub fn new(
weight: Array,
scales: Array,
biases: Option<Array>,
quant: impl Into<Quant>,
) -> Self
pub fn new( weight: Array, scales: Array, biases: Option<Array>, quant: impl Into<Quant>, ) -> Self
Weights quantized elsewhere (a checkpoint’s tensors).
Trait Implementations§
Source§impl Leaves for Quantized
A tree of buffers (never trainable, as quantized layers’ tensors) with MLX’s names
weight, scales and biases, and quant as a static field: eval(&q), the
transforms and save_safetensors take quantized weights directly.
impl Leaves for Quantized
A tree of buffers (never trainable, as quantized layers’ tensors) with MLX’s names
weight, scales and biases, and quant as a static field: eval(&q), the
transforms and save_safetensors take quantized weights directly.
Source§impl Tree for Quantized
impl Tree for Quantized
Source§fn visit_mut(&mut self, v: &mut VisitMut<'_>)
fn visit_mut(&mut self, v: &mut VisitMut<'_>)
Reports every leaf (and child tree and mode flag) to
v mutably, in the order of
Leaves::visit.Source§fn map(&self, f: impl FnMut(&str, &Array) -> Array) -> Self
fn map(&self, f: impl FnMut(&str, &Array) -> Array) -> Self
The tree with every leaf replaced by
f(path, leaf) (same structure; parameters keep
their frozen flag).Source§fn flatten(&self) -> Vec<(String, Array)>
fn flatten(&self) -> Vec<(String, Array)>
The leaves with their paths, in order (MLX’s
tree_flatten).Source§fn unflatten(&self, leaves: impl IntoIterator<Item = Array>) -> Result<Self>
fn unflatten(&self, leaves: impl IntoIterator<Item = Array>) -> Result<Self>
A tree of this structure (
self is the template) with leaves in order: exactly
Tree::len of them, else an error naming both counts.Source§fn load_flat(
&mut self,
named: impl IntoIterator<Item = (String, Array)>,
mode: LoadMode,
) -> Result<()>
fn load_flat( &mut self, named: impl IntoIterator<Item = (String, Array)>, mode: LoadMode, ) -> Result<()>
Replaces leaves by path.
LoadMode::Strict requires exactly the tree’s paths with
matching shapes; LoadMode::Partial assigns the matching names and ignores
unknown ones (shapes must still match). Loaded dtypes are kept. On any problem the
error lists every one (missing, unknown and mismatched names, sorted) and the tree is
unchanged. Duplicate paths (in the tree or in named) are an error.Auto Trait Implementations§
impl !RefUnwindSafe for Quantized
impl !UnwindSafe for Quantized
impl Freeze for Quantized
impl Send for Quantized
impl Sync for Quantized
impl Unpin for Quantized
impl UnsafeUnpin for Quantized
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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