pub enum QuantLevel {
Tensor,
Block(BlockSize),
BlockTensor {
block: BlockSize,
global: QuantParam,
},
}Expand description
Level or granularity of quantization.
Append new variants, never insert. Some transports serialize this with a format that encodes variants by position rather than by name, so inserting one silently reinterprets streams and stored schemes written by an older build.
Variants§
Tensor
Quantize the whole tensor using a single tensor.
Block(BlockSize)
Quantize a tensor using multiple blocks.
BlockTensor
Quantize a tensor using multiple blocks whose scales are themselves normalized by a single per-tensor scale.
See QuantLevel::block_tensor for what that buys and what it does not.
Fields
block: BlockSizeSize of each block. The block scales use QuantScheme::param.
global: QuantParamPrecision of the per-tensor scale. Only a param with more range than the block scales use is meaningful.
Implementations§
Source§impl QuantLevel
impl QuantLevel
Sourcepub fn block(values: impl AsRef<[u8]>) -> Self
pub fn block(values: impl AsRef<[u8]>) -> Self
Converting constructor for QuantLevel::Block
Sourcepub fn block_tensor(values: impl AsRef<[u8]>, global: QuantParam) -> Self
pub fn block_tensor(values: impl AsRef<[u8]>, global: QuantParam) -> Self
Converting constructor for QuantLevel::BlockTensor.
The per-tensor scale absorbs the tensor’s dynamic range, which is what lets the block scales
live in a narrow type. Without it a block scale has to cover that range on its own, and a
type like QuantParam::UE4M3 underflows to zero for small values.
What the block param covers is then the spread between blocks, which is still bounded. A
block whose scale falls further below the largest one than the block param can express is
stored at that param’s smallest value, far too coarse for it, and every value in the block
quantizes to zero. QuantParam::UE4M3 spans about 2^18 this way, from its smallest
subnormal to 448, so a tensor holding a genuine outlier can lose its ordinary values.
The kernels in cubecl-std do not implement this level yet and reject it at launch rather
than reconstruct values short by the per-tensor factor.
Sourcepub fn block_size(&self) -> Option<BlockSize>
pub fn block_size(&self) -> Option<BlockSize>
The block size, for the levels that quantize in blocks.
Sourcepub fn global_param(&self) -> Option<QuantParam>
pub fn global_param(&self) -> Option<QuantParam>
The precision of the per-tensor scale, for the levels that have one.
Trait Implementations§
Source§impl Clone for QuantLevel
impl Clone for QuantLevel
Source§fn clone(&self) -> QuantLevel
fn clone(&self) -> QuantLevel
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 QuantLevel
Source§impl Debug for QuantLevel
impl Debug for QuantLevel
Source§impl<'de> Deserialize<'de> for QuantLevel
impl<'de> Deserialize<'de> for QuantLevel
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 QuantLevel
Source§impl Hash for QuantLevel
impl Hash for QuantLevel
Source§impl Ord for QuantLevel
impl Ord for QuantLevel
Source§fn cmp(&self, other: &QuantLevel) -> Ordering
fn cmp(&self, other: &QuantLevel) -> 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 QuantLevel
impl PartialEq for QuantLevel
Source§impl PartialOrd for QuantLevel
impl PartialOrd for QuantLevel
Source§impl Serialize for QuantLevel
impl Serialize for QuantLevel
impl StructuralPartialEq for QuantLevel
Auto Trait Implementations§
impl Freeze for QuantLevel
impl RefUnwindSafe for QuantLevel
impl Send for QuantLevel
impl Sync for QuantLevel
impl Unpin for QuantLevel
impl UnsafeUnpin for QuantLevel
impl UnwindSafe for QuantLevel
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.