pub enum QuantParam {
F32,
F16,
BF16,
UE8M0,
UE4M3,
}Expand description
Quantization floating-point precision.
This is used to represent the floating-point precision of quantization parameters like the scale(s) or the accumulation precision used during operations like matrix multiplication.
Variants§
F32
Full precision.
F16
Half precision.
BF16
bfloat16 precision.
UE8M0
unsigned floating point, e8m0 format.
UE4M3
unsigned floating point, e4m3 format.
Implementations§
Source§impl QuantParam
impl QuantParam
Sourcepub fn max_representable(&self) -> f32
pub fn max_representable(&self) -> f32
The largest finite value representable by the parameter type.
A two-level scheme picks its per-tensor scale so that the largest block scale lands here,
which is what keeps the block scales inside the range their type can express. That recipe
only holds for a block param narrower than the scale it divides: dividing by
QuantParam::F32’s or QuantParam::UE8M0’s maximum drives the per-tensor scale
subnormal and the renormalized block scales to infinity. A two-level scheme has nothing to
gain from those params anyway, since their block scales already reach the full range.
Sourcepub fn round_up(&self, scale: f32) -> Option<f32>
pub fn round_up(&self, scale: f32) -> Option<f32>
The smallest value representable by the parameter type that is not below scale.
Storing a quantization scale wants this rather than the nearest value. Rounding down puts the scale below what calibration asked for, so every value at the block maximum clips to the quantization range; rounding up costs one step of coarseness instead. Backends have to agree on this, or a tensor quantized on one reconstructs differently on another.
This is not a cast. Conversion to these types rounds to nearest, which is what a cast should do; this is the storage policy for a scale specifically.
scale must not be negative. Symmetric quantization only produces non-negative scales,
and the stepping below walks away from zero for a negative input.
QuantParam::UE8M0 answers None. Its minimum is 2^-127, subnormal in f32, where the
grid below no longer holds.
Sourcepub fn f32_grid(&self) -> F32Grid
pub fn f32_grid(&self) -> F32Grid
The param’s grid, expressed on the f32 bit pattern. See F32Grid.
bf16 reports no subnormal range because it does not need the separate treatment: its pattern is f32’s top half all the way down, so the bit step stays right where the others stop. Its own subnormals start at 2^-133, which is subnormal in f32 too and flushed to zero by most backends.
§Panics
For QuantParam::F32, which is the grid itself, and QuantParam::UE8M0, which is not
yet supported.
Trait Implementations§
Source§impl Clone for QuantParam
impl Clone for QuantParam
Source§fn clone(&self) -> QuantParam
fn clone(&self) -> QuantParam
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for QuantParam
Source§impl Debug for QuantParam
impl Debug for QuantParam
Source§impl<'de> Deserialize<'de> for QuantParam
impl<'de> Deserialize<'de> for QuantParam
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>,
impl Eq for QuantParam
Source§impl Hash for QuantParam
impl Hash for QuantParam
Source§impl Ord for QuantParam
impl Ord for QuantParam
Source§fn cmp(&self, other: &QuantParam) -> Ordering
fn cmp(&self, other: &QuantParam) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for QuantParam
impl PartialEq for QuantParam
Source§impl PartialOrd for QuantParam
impl PartialOrd for QuantParam
Source§impl Serialize for QuantParam
impl Serialize for QuantParam
impl StructuralPartialEq for QuantParam
Auto Trait Implementations§
impl Freeze for QuantParam
impl RefUnwindSafe for QuantParam
impl Send for QuantParam
impl Sync for QuantParam
impl Unpin for QuantParam
impl UnsafeUnpin for QuantParam
impl UnwindSafe for QuantParam
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.