pub struct Quantization {
pub scale: Vec<f32>,
pub zero_point: Option<Vec<i32>>,
pub axis: Option<usize>,
pub dtype: Option<DType>,
}Expand description
Quantization parameters for a quantized tensor.
Supports per-tensor (scalar scale) and per-channel (array scale)
quantization. Symmetric quantization is indicated by an absent or
all-zero zero_point.
Fields§
§scale: Vec<f32>Scale factor(s). One element for per-tensor quantization, or one element per slice for per-channel quantization.
zero_point: Option<Vec<i32>>Zero point offset(s). Omit or set to all-zero for symmetric
quantization. For per-channel quantization, length must match
scale length.
axis: Option<usize>Tensor dimension index that scale/zero_point arrays correspond
to. Required when per-channel; ignored otherwise.
dtype: Option<DType>Quantized data type. Required on v2 metadata files; may be absent on programmatically-constructed configurations where the dtype is resolved at decode time from the actual tensor.
Implementations§
Source§impl Quantization
impl Quantization
Sourcepub fn is_per_tensor(&self) -> bool
pub fn is_per_tensor(&self) -> bool
Returns true when per-tensor (scalar scale).
Sourcepub fn is_per_channel(&self) -> bool
pub fn is_per_channel(&self) -> bool
Returns true when per-channel (array scale of length > 1).
Sourcepub fn is_symmetric(&self) -> bool
pub fn is_symmetric(&self) -> bool
Returns true when all zero points are 0 (or absent).
Sourcepub fn zero_point_at(&self, channel: usize) -> i32
pub fn zero_point_at(&self, channel: usize) -> i32
Returns the zero point for the given channel index, or 0 when the quantization is 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
Source§impl TryFrom<&Quantization> for Quantization
Convert a schema-level Quantization (which also carries the quantized
dtype) into the tensor-crate edgefirst_tensor::Quantization attached
to a Tensor<T> at runtime. The dtype field is dropped — the tensor’s
T supplies the storage element type directly.
impl TryFrom<&Quantization> for Quantization
Convert a schema-level Quantization (which also carries the quantized
dtype) into the tensor-crate edgefirst_tensor::Quantization attached
to a Tensor<T> at runtime. The dtype field is dropped — the tensor’s
T supplies the storage element type directly.
Returns Err on any length-mismatch / axis-out-of-range condition; the
schema’s Quantization::validate_shape has looser rules (accepts absent
axis on per-channel) that the tensor crate does not. Callers should prefer
the v2 parse path which normalizes.
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