pub struct FloatLayout {
pub exponent_bits: u8,
pub mantissa_bits: u8,
pub specials: Specials,
pub bias_override: Option<i16>,
pub sign: SignEncoding,
}Expand description
A sign encoding, exponent_bits, mantissa_bits; at most 32 bits wide. An integer is the
layout with exponent_bits 0 and a bias_override of 1 - mantissa_bits, which makes its
scale exactly 1.
Fields§
§exponent_bits: u8Width of the exponent field; 3 for E3M2, 8 for binary32.
mantissa_bits: u8Width of the stored mantissa field, excluding the implicit leading one; 2 for E3M2, 23 for binary32.
specials: SpecialsPolicy for the all-ones exponent and for overflow; Specials::None for E3M2.
bias_override: Option<i16>Replaces the IEEE bias 2^(exponent_bits - 1) - 1 when set; Some(4) on E3M2 shifts
its max normal from 28.0 to 14.0.
sign: SignEncodingHow the sign is encoded; Magnitude for IEEE floats, TwosComplement for int8.
Implementations§
Source§impl FloatLayout
impl FloatLayout
pub const E5M2: Self
Sourcepub const E5M2_SATURATING: Self
pub const E5M2_SATURATING: Self
E5M2 widths with saturation: the GGUF bf8 storage policy, which keeps infinities out of stored weights.
pub const E2M1: Self
Sourcepub const E3M2: Self
pub const E3M2: Self
OCP MX v1.0 FP6 E3M2: bias 3, no inf or nan, max normal 28.0 (page 12, section 5.3.2, Table 4).
pub const E2M3: Self
pub const BF32: Self
pub const BF16: Self
pub const BF8: Self = Self::E5M2
pub const BF4: Self = Self::E2M1
pub const INT8: Self
pub const UINT8: Self
pub const INT16: Self
pub const UINT16: Self
pub const INT32: Self
pub const UINT32: Self
pub const UINT1: Self
pub const UINT2: Self
pub const UINT3: Self
pub const UINT4: Self
pub const UINT5: Self
pub const UINT6: Self
Sourcepub const SIGN_MAGNITUDE_INT8: Self
pub const SIGN_MAGNITUDE_INT8: Self
Sign-magnitude eight bits: range -127..=127 with a negative zero.
pub const fn bias(&self) -> i16
pub const fn width(&self) -> u8
Sourcepub fn same_format(&self, other: &Self) -> bool
pub fn same_format(&self, other: &Self) -> bool
Whether two layouts are the same format: equal exponent and mantissa widths, equal
specials, and equal effective bias. == also compares the raw bias_override, so a
layout spelled with Some(15) and one with None differ under == and agree here.
Sourcepub const fn packed_bytes(
&self,
elements: u64,
scale_block: Option<(FloatLayout, u64)>,
) -> u64
pub const fn packed_bytes( &self, elements: u64, scale_block: Option<(FloatLayout, u64)>, ) -> u64
Bytes elements values occupy packed densely at width() bits each, plus one scale code
per block elements when scale_block is Some((scale, block)), rounded up to whole
bytes: 32 elements of E3M2 under an f16 scale are 32 * 6 + 16 = 208 bits, 26 bytes.
pub const fn max_normal(&self) -> f32
pub const fn min_normal(&self) -> f32
pub const fn min_subnormal(&self) -> f32
Trait Implementations§
Source§impl Clone for FloatLayout
impl Clone for FloatLayout
impl Copy for FloatLayout
Source§impl Debug for FloatLayout
impl Debug for FloatLayout
Source§impl<'de> Deserialize<'de> for FloatLayout
impl<'de> Deserialize<'de> for FloatLayout
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 FloatLayout
Source§impl Hash for FloatLayout
impl Hash for FloatLayout
Source§impl PartialEq for FloatLayout
impl PartialEq for FloatLayout
Source§impl Serialize for FloatLayout
impl Serialize for FloatLayout
impl StructuralPartialEq for FloatLayout
Auto Trait Implementations§
impl Freeze for FloatLayout
impl RefUnwindSafe for FloatLayout
impl Send for FloatLayout
impl Sync for FloatLayout
impl Unpin for FloatLayout
impl UnsafeUnpin for FloatLayout
impl UnwindSafe for FloatLayout
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,
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§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.