Skip to main content

QuantizedBytes

Struct QuantizedBytes 

Source
pub struct QuantizedBytes {
    pub bytes: Bytes,
    pub scheme: QuantScheme,
    pub shape: Shape,
}
Expand description

Quantized data bytes representation.

§Notes

  1. The quantized values are laid out as the scheme’s store says: a byte each for Native, or packed into little-endian words along the packed axis as cubecl stores them, each line padded to whole words.
  2. Quantization parameters are appended to the tensor data. As such, the last bytes always correspond to the scale parameter. If the quantization scheme includes an offset (zero-point) parameter, it is next to last.

Fields§

§bytes: Bytes

The quantized values and quantization parameters represented as bytes.

§scheme: QuantScheme

The quantization scheme.

§shape: Shape

The shape of the quantized tensor. The block count, and so the scale count, follows from it per axis: a block that does not span the trailing dimension is not a run of elements.

Implementations§

Source§

impl QuantizedBytes

Source

pub fn new<E: CheckedBitPattern + NoUninit>( value: Vec<E>, shape: impl Into<Shape>, scheme: QuantScheme, scales: &[f32], global: Option<f32>, ) -> Self

Creates a new quantized bytes representation.

value holds one code per element and scales the block scales, both row-major; global is the per-tensor scale, required by a two-level scheme and rejected by a one-level one.

Source

pub fn num_elements(&self) -> usize

The number of quantized elements.

Source

pub fn into_vec_i8(self) -> (Vec<i8>, DecodedScales)

The codes, one i8 per element in row-major order, and the scales; a float code is its bits.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.