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 packed into 32-bit unsigned integers. For example, int8 quantized values pack 4 grouped values into a single u32. When unpacking these values, we make sure to retrieve only the meaningful values (and ignore the alignment padding).
  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.

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)

Returns the int8 quantized values with the quantization parameters.

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, <T as TryFrom<U>>::Error>

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.