Skip to main content

QuantizedWeight

Struct QuantizedWeight 

Source
pub struct QuantizedWeight {
    pub data: Vec<u8>,
    pub scales: Vec<f32>,
    pub in_feat: usize,
    pub out_feat: usize,
    pub num_groups: usize,
}
Expand description

Packed INT4 weight tensor with per-group f32 scales.

data: row-major packed nibbles [pair * out_feat + o], total (in_padded / 2) * out_feat bytes. scales: [num_groups * out_feat] f32, row-major [g * out_feat + o]. in_feat: original (unpadded) input dimension. out_feat: output dimension.

Fields§

§data: Vec<u8>§scales: Vec<f32>§in_feat: usize§out_feat: usize§num_groups: usize

Implementations§

Source§

impl QuantizedWeight

Source

pub fn quantize(w: &[f32], in_feat: usize, out_feat: usize) -> Self

Quantize an f32 weight matrix w of shape [in_feat, out_feat]. Matches Python _fake_quantize_int4 exactly.

Source

pub fn dequantize_to(&self, out: &mut [f32])

Dequantize to f32 into out buffer of shape [in_feat, out_feat].

Source

pub fn matvec(&self, x: &[f32], y: &mut [f32])

Matrix-vector multiply: y = W^T x (y shape [out_feat], x shape [in_feat]). Dequantizes on the fly — never materializes the full weight matrix. Uses AVX2 auto-vectorized inner loop on x86_64 when the feature is present.

Source

pub fn matmul(&self, x: &[f32], batch: usize, y: &mut [f32])

Batched matmul: Y = X W (X shape [batch, in_feat], Y shape [batch, out_feat]).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.