pub struct Quantization { /* private fields */ }Expand description
Quantization parameters for an integer tensor.
Covers all four modes the edgefirst.json spec defines:
| Mode | scale.len() | zero_point | axis |
|---|---|---|---|
| Per-tensor symmetric | 1 | None | None |
| Per-tensor asymmetric | 1 | Some(len == 1) | None |
| Per-channel symmetric | >1 | None | Some(c) |
| Per-channel asymmetric | >1 | Some(len == scale.len()) | Some(c) |
The quantized storage type is carried on the parent Tensor<T>; this
struct does not duplicate it. Construct via the four named constructors
(the only public entry points); direct field mutation is not allowed so
invalid combinations cannot be represented.
Dequantization formula:
real_value = scale[c] × (quantized_value[c] - zero_point[c])where c is the channel index (always 0 for per-tensor).
Implementations§
Source§impl Quantization
impl Quantization
Sourcepub fn per_tensor_symmetric(scale: f32) -> Self
pub fn per_tensor_symmetric(scale: f32) -> Self
Per-tensor symmetric (zero_point = 0).
Sourcepub fn per_tensor(scale: f32, zero_point: i32) -> Self
pub fn per_tensor(scale: f32, zero_point: i32) -> Self
Per-tensor asymmetric — the most common runtime shape.
Sourcepub fn per_channel_symmetric(scales: Vec<f32>, axis: usize) -> Result<Self>
pub fn per_channel_symmetric(scales: Vec<f32>, axis: usize) -> Result<Self>
Per-channel symmetric. Errors on empty scales.
Sourcepub fn per_channel(
scales: Vec<f32>,
zero_points: Vec<i32>,
axis: usize,
) -> Result<Self>
pub fn per_channel( scales: Vec<f32>, zero_points: Vec<i32>, axis: usize, ) -> Result<Self>
Per-channel asymmetric. Errors on length mismatch between scales
and zero_points, or empty arrays.
Sourcepub fn is_per_tensor(&self) -> bool
pub fn is_per_tensor(&self) -> bool
Returns true for per-tensor quantization (scale.len() == 1).
Sourcepub fn is_per_channel(&self) -> bool
pub fn is_per_channel(&self) -> bool
Returns true for per-channel quantization (scale.len() > 1).
Sourcepub fn is_symmetric(&self) -> bool
pub fn is_symmetric(&self) -> bool
Returns true for symmetric quantization (no zero-point, or
zero-point vector of all zeros).
Sourcepub fn scale(&self) -> &[f32]
pub fn scale(&self) -> &[f32]
Borrow the scale array. Length 1 for per-tensor; num_channels for
per-channel.
Sourcepub fn zero_point(&self) -> Option<&[i32]>
pub fn zero_point(&self) -> Option<&[i32]>
Borrow the zero-point array. None for symmetric.
Trait Implementations§
Source§impl Clone for Quantization
impl Clone for Quantization
Source§fn clone(&self) -> Quantization
fn clone(&self) -> Quantization
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Quantization
impl Debug for Quantization
Source§impl<'de> Deserialize<'de> for Quantization
impl<'de> Deserialize<'de> for Quantization
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for Quantization
impl PartialEq for Quantization
Source§impl Serialize for Quantization
impl Serialize for Quantization
impl StructuralPartialEq for Quantization
Auto Trait Implementations§
impl Freeze for Quantization
impl RefUnwindSafe for Quantization
impl Send for Quantization
impl Sync for Quantization
impl Unpin for Quantization
impl UnsafeUnpin for Quantization
impl UnwindSafe for Quantization
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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