pub struct TensorQuantizer { /* private fields */ }Expand description
Multi-precision tensor quantizer.
Supports INT8 (symmetric/asymmetric), INT4, FP16, and BF16 quantization with optional per-channel calibration and percentile-based outlier suppression.
Implementations§
Source§impl TensorQuantizer
impl TensorQuantizer
Sourcepub fn new(config: QuantizerConfig) -> Self
pub fn new(config: QuantizerConfig) -> Self
Create a new quantizer with the given configuration.
Sourcepub fn stats(&self) -> &QuantizerStats
pub fn stats(&self) -> &QuantizerStats
Read-only access to accumulated statistics.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset accumulated statistics.
Sourcepub fn quantize(
&mut self,
values: &[f64],
dims: &[usize],
) -> Result<QuantizedTensor, QuantizerError>
pub fn quantize( &mut self, values: &[f64], dims: &[usize], ) -> Result<QuantizedTensor, QuantizerError>
Quantize a flat tensor described by dims.
Returns a QuantizedTensor whose data encodes the elements in the
same order as values.
Sourcepub fn dequantize(
&self,
qt: &QuantizedTensor,
) -> Result<DequantizedTensor, QuantizerError>
pub fn dequantize( &self, qt: &QuantizedTensor, ) -> Result<DequantizedTensor, QuantizerError>
Reconstruct approximate f64 values from a QuantizedTensor.
Sourcepub fn quantization_error(
&self,
original: &[f64],
qt: &QuantizedTensor,
) -> Result<f64, QuantizerError>
pub fn quantization_error( &self, original: &[f64], qt: &QuantizedTensor, ) -> Result<f64, QuantizerError>
Compute mean-squared error between the original values and the dequantized reconstruction.
Sourcepub fn compression_ratio(original_len: usize, mode: &QuantizationMode) -> f64
pub fn compression_ratio(original_len: usize, mode: &QuantizationMode) -> f64
Compression ratio relative to f64 (64-bit) storage.
- f64 = 64 bits → ratio = 64 / bits_per_element.
Sourcepub fn clamp_to_range(x: f64, mode: &QuantizationMode) -> f64
pub fn clamp_to_range(x: f64, mode: &QuantizationMode) -> f64
Clamp x to the representable integer range for mode.
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