pub struct QuantStats {
pub min_val: f32,
pub max_val: f32,
pub mean_val: f32,
pub std_val: f32,
}Expand description
Quantization statistics for calibration.
Fields§
§min_val: f32§max_val: f32§mean_val: f32§std_val: f32Implementations§
Source§impl QuantStats
impl QuantStats
Sourcepub fn from_tensor(data: &ArrayD<f32>) -> Self
pub fn from_tensor(data: &ArrayD<f32>) -> Self
Compute statistics from a tensor.
Examples found in repository?
examples/full_inference_pipeline.rs (line 128)
113fn quantize_model() {
114 println!("3. Model Quantization");
115
116 let calibration_data = vec![
117 Tensor::random(&[1, 224, 224, 3]).data,
118 Tensor::random(&[1, 224, 224, 3]).data,
119 Tensor::random(&[1, 224, 224, 3]).data,
120 ];
121
122 let ptq = PTQEngine::new(8, false);
123 match ptq.calibrate(&calibration_data) {
124 Ok(converter) => {
125 println!(" ✓ Calibration complete");
126
127 let sample = &calibration_data[0];
128 let stats = QuantStats::from_tensor(sample);
129 println!(" Calibration Stats:");
130 println!(" - Min: {:.6}", stats.min_val);
131 println!(" - Max: {:.6}", stats.max_val);
132 println!(" - Mean: {:.6}", stats.mean_val);
133 println!(" - Std: {:.6}", stats.std_val);
134
135 match converter.quantize_tensor(sample) {
136 Ok(quantized) => {
137 println!(" ✓ Quantization complete: {} values", quantized.len());
138 println!(" Compression: {:.2}x\n",
139 (sample.len() * 4) as f64 / quantized.len() as f64
140 );
141 }
142 Err(e) => println!(" ✗ Quantization failed: {}\n", e),
143 }
144 }
145 Err(e) => println!(" ✗ Calibration failed: {}\n", e),
146 }
147}Sourcepub fn get_zero_point(&self, num_bits: u32, signed: bool) -> i32
pub fn get_zero_point(&self, num_bits: u32, signed: bool) -> i32
Get zero point.
Trait Implementations§
Source§impl Clone for QuantStats
impl Clone for QuantStats
Source§fn clone(&self) -> QuantStats
fn clone(&self) -> QuantStats
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for QuantStats
impl RefUnwindSafe for QuantStats
impl Send for QuantStats
impl Sync for QuantStats
impl Unpin for QuantStats
impl UnwindSafe for QuantStats
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
Mutably borrows from an owned value. Read more