pub struct QuantConfig {
pub bits: u8,
pub per_channel: bool,
pub symmetric: bool,
pub calibration_method: Option<CalibrationMethod>,
pub excluded_layers: Vec<String>,
pub layer_bits: HashMap<String, u8>,
pub min_elements: usize,
}Expand description
Configuration for a quantization pass.
Fields are public for ergonomic construction in callers; new fields are
added only on a minor version bump and downstream ..Default::default()
callers continue to compile. Always construct via
QuantConfig { /* fields */, ..Default::default() }.
Fields§
§bits: u8Bit width: 4 for INT4 or 8 for INT8.
per_channel: boolWhen true, compute separate scale/zero-point per output channel (axis 0).
symmetric: boolWhen true, force zero_point == 0 (symmetric quantization) — required
by most ONNX Runtime / TensorRT INT8 matmul kernels for per-channel
weight quantization. Defaults to false (asymmetric).
calibration_method: Option<CalibrationMethod>Optional calibration method used for range optimization.
excluded_layers: Vec<String>Layer names to skip entirely (exact match against the initializer name).
layer_bits: HashMap<String, u8>Per-layer bit-width overrides. Key = initializer name, value = 4 or 8.
min_elements: usizeMinimum number of elements a tensor must have to be quantized. Tensors with fewer elements are left in FP32. Defaults to 0 (no minimum).
Implementations§
Source§impl QuantConfig
impl QuantConfig
Sourcepub fn with_per_channel(self, enabled: bool) -> Self
pub fn with_per_channel(self, enabled: bool) -> Self
Enable or disable per-channel quantization.
Sourcepub fn with_symmetric(self, enabled: bool) -> Self
pub fn with_symmetric(self, enabled: bool) -> Self
Enable or disable symmetric quantization (zero_point == 0).
Sourcepub fn with_calibration(self, method: CalibrationMethod) -> Self
pub fn with_calibration(self, method: CalibrationMethod) -> Self
Set the calibration method for range optimization.
Sourcepub fn should_quantize(&self, name: &str, num_elements: usize) -> bool
pub fn should_quantize(&self, name: &str, num_elements: usize) -> bool
Return true if the layer should be quantized.
A layer is skipped when:
- its name appears in
Self::excluded_layers, or num_elementsis belowSelf::min_elements(andmin_elements > 0).
Sourcepub fn bits_for_layer(&self, name: &str) -> u8
pub fn bits_for_layer(&self, name: &str) -> u8
Return the effective bit width for a layer.
If the layer name has an entry in Self::layer_bits, that value is used;
otherwise the global Self::bits is returned.
Trait Implementations§
Source§impl Clone for QuantConfig
impl Clone for QuantConfig
Source§fn clone(&self) -> QuantConfig
fn clone(&self) -> QuantConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QuantConfig
impl Debug for QuantConfig
Auto Trait Implementations§
impl Freeze for QuantConfig
impl RefUnwindSafe for QuantConfig
impl Send for QuantConfig
impl Sync for QuantConfig
impl Unpin for QuantConfig
impl UnsafeUnpin for QuantConfig
impl UnwindSafe for QuantConfig
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
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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