pub struct Quantizer { /* private fields */ }Expand description
High-level quantizer that combines configuration with optional calibration.
Implementations§
Source§impl Quantizer
impl Quantizer
Sourcepub fn new(config: QuantConfig) -> Self
pub fn new(config: QuantConfig) -> Self
Create a quantizer with the given configuration (no calibration).
Sourcepub fn with_calibration(
config: QuantConfig,
stats: HashMap<String, ActivationStats>,
) -> Self
pub fn with_calibration( config: QuantConfig, stats: HashMap<String, ActivationStats>, ) -> Self
Create a quantizer with configuration and pre-collected activation statistics.
Sourcepub fn quantize_tensor_with_name(
&self,
name: &str,
data: &[f32],
shape: Vec<usize>,
) -> Result<QuantizedTensorType>
pub fn quantize_tensor_with_name( &self, name: &str, data: &[f32], shape: Vec<usize>, ) -> Result<QuantizedTensorType>
Quantize a tensor with optional calibration.
Sourcepub fn quantize_tensor(
&self,
data: &[f32],
shape: Vec<usize>,
) -> Result<QuantizedTensorType>
pub fn quantize_tensor( &self, data: &[f32], shape: Vec<usize>, ) -> Result<QuantizedTensorType>
Quantize a tensor using the configured bit width and per-channel setting.
§Errors
Returns QuantizeError::InvalidTensor or QuantizeError::UnsupportedConfig.
Sourcepub fn quantize_model(
&self,
model: &OnnxModel,
) -> Result<Vec<QuantizedWeightOutput>>
pub fn quantize_model( &self, model: &OnnxModel, ) -> Result<Vec<QuantizedWeightOutput>>
Quantize every weight in model that passes
QuantConfig::should_quantize. Honours per-layer bit-width overrides.
When this quantizer was built with calibration, activation-based range optimization is used for the default bit-width; layers whose bit-width is overridden fall back to weight-only quantization (the calibration stats are keyed by the default configuration).
Skipped weights do not appear in the returned vector.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Quantizer
impl RefUnwindSafe for Quantizer
impl Send for Quantizer
impl Sync for Quantizer
impl Unpin for Quantizer
impl UnsafeUnpin for Quantizer
impl UnwindSafe for Quantizer
Blanket Implementations§
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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>
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>
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