pub enum ScaleDtype {
F32,
F16,
BF16,
UE8M0,
UE4M3,
}Expand description
The data type a scale level stores its scales in.
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 ScaleDtype
impl ScaleDtype
Sourcepub fn max_representable(&self) -> f32
pub fn max_representable(&self) -> f32
The largest finite value representable by the dtype.
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 dtype narrower than the scale it divides: dividing by
ScaleDtype::F32’s or ScaleDtype::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 dtype 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.
ScaleDtype::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 dtype’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 ScaleDtype::F32, which is the grid itself, and ScaleDtype::UE8M0, which is not
yet supported.
Trait Implementations§
Source§impl Clone for ScaleDtype
impl Clone for ScaleDtype
Source§fn clone(&self) -> ScaleDtype
fn clone(&self) -> ScaleDtype
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 ScaleDtype
Source§impl Debug for ScaleDtype
impl Debug for ScaleDtype
Source§impl<'de> Deserialize<'de> for ScaleDtype
impl<'de> Deserialize<'de> for ScaleDtype
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ScaleDtype, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ScaleDtype, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for ScaleDtype
Source§impl Hash for ScaleDtype
impl Hash for ScaleDtype
Source§impl Ord for ScaleDtype
impl Ord for ScaleDtype
Source§fn cmp(&self, other: &ScaleDtype) -> Ordering
fn cmp(&self, other: &ScaleDtype) -> 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 ScaleDtype
impl PartialEq for ScaleDtype
Source§impl PartialOrd for ScaleDtype
impl PartialOrd for ScaleDtype
Source§impl Serialize for ScaleDtype
impl Serialize for ScaleDtype
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ScaleDtype
Auto Trait Implementations§
impl Freeze for ScaleDtype
impl RefUnwindSafe for ScaleDtype
impl Send for ScaleDtype
impl Sync for ScaleDtype
impl Unpin for ScaleDtype
impl UnsafeUnpin for ScaleDtype
impl UnwindSafe for ScaleDtype
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.