pub struct TensorQuantizer { /* private fields */ }Expand description
Calibration-based tensor quantizer.
Usage: call calibrate with representative
data, then compute_params to derive
quantization parameters.
Implementations§
Source§impl TensorQuantizer
impl TensorQuantizer
Sourcepub fn calibrate(&mut self, values: &[f64])
pub fn calibrate(&mut self, values: &[f64])
Update calibration range from observed values.
Can be called multiple times; min/max accumulate across calls.
Sourcepub fn compute_params(
&self,
mode: QuantMode,
bits: QuantBits,
) -> Result<QuantParams, String>
pub fn compute_params( &self, mode: QuantMode, bits: QuantBits, ) -> Result<QuantParams, String>
Compute quantization parameters from calibration data.
Returns an error if no samples have been observed.
Sourcepub fn quantize(values: &[f64], params: &QuantParams) -> Vec<i32>
pub fn quantize(values: &[f64], params: &QuantParams) -> Vec<i32>
Quantize floating-point values to integers using the given parameters.
Each value is mapped as: clamp(round(value / scale) + zero_point, qmin, qmax)
Sourcepub fn dequantize(quantized: &[i32], params: &QuantParams) -> Vec<f64>
pub fn dequantize(quantized: &[i32], params: &QuantParams) -> Vec<f64>
Dequantize integer values back to floating-point.
Each value is mapped as: (q - zero_point) * scale
Sourcepub fn quantization_error(original: &[f64], params: &QuantParams) -> f64
pub fn quantization_error(original: &[f64], params: &QuantParams) -> f64
Compute mean squared error between original values and their quantize→dequantize roundtrip.
Sourcepub fn reset_calibration(&mut self)
pub fn reset_calibration(&mut self)
Reset calibration state.
Sourcepub fn stats(&self) -> QuantizerStats
pub fn stats(&self) -> QuantizerStats
Return current calibration statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TensorQuantizer
impl RefUnwindSafe for TensorQuantizer
impl Send for TensorQuantizer
impl Sync for TensorQuantizer
impl Unpin for TensorQuantizer
impl UnsafeUnpin for TensorQuantizer
impl UnwindSafe for TensorQuantizer
Blanket Implementations§
impl<T> Allocation for T
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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