Skip to main content

MinMaxQuantizer

Struct MinMaxQuantizer 

Source
pub struct MinMaxQuantizer { /* private fields */ }
Expand description

Calibrates quantization parameters using tensor min/max statistics.

Implementations§

Source§

impl MinMaxQuantizer

Source

pub fn new( bits: u32, scheme: QuantScheme, granularity: QuantGranularity, ) -> Self

Create a new quantizer.

§Panics

Panics if bits is 0 or > 16.

Source

pub fn int8_symmetric() -> Self

Standard INT8 symmetric per-tensor quantizer.

Source

pub fn int4_per_group(group_size: usize) -> Self

Standard INT4 symmetric per-group quantizer (group = 128, as in GGML).

Source

pub fn calibrate(&self, tensor: &[f32]) -> QuantResult<QuantParams>

Calibrate parameters from a flat tensor.

For PerChannel, the tensor is assumed to be in row-major layout with n_channels rows of length tensor.len() / n_channels.

§Errors
Source

pub fn calibrate_2d( &self, tensor: &[f32], rows: usize, cols: usize, ) -> QuantResult<QuantParams>

Calibrate from a 2-D tensor (rows = channels).

Returns one (scale, zp) per row.

§Errors
Source

pub fn quantize( &self, tensor: &[f32], params: &QuantParams, ) -> QuantResult<Vec<i32>>

Quantize a flat tensor given pre-computed params (PerTensor mode).

Returns Vec<i32> of integer codes.

§Errors
Source

pub fn quantize_grouped( &self, tensor: &[f32], params: &QuantParams, group_size: usize, ) -> QuantResult<Vec<i32>>

Quantize using per-group params.

§Errors
Source

pub fn dequantize(&self, codes: &[i32], params: &QuantParams) -> Vec<f32>

Dequantize integer codes back to f32.

Source

pub fn dequantize_grouped( &self, codes: &[i32], params: &QuantParams, group_size: usize, ) -> Vec<f32>

Dequantize per-group codes.

Trait Implementations§

Source§

impl Clone for MinMaxQuantizer

Source§

fn clone(&self) -> MinMaxQuantizer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MinMaxQuantizer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.