Skip to main content

DType

Enum DType 

Source
pub enum DType {
Show 31 variants F32, F16, Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, Q8_1, Q2_K, Q3_K, Q4_K, Q5_K, Q6_K, Q8_K, IQ2_XXS, IQ2_XS, IQ3_XXS, IQ1_S, IQ4_NL, IQ3_S, IQ2_S, IQ4_XS, IQ1_M, BF16, F64, I8, I16, I32, I64, IQ3_M_BLOCK, Other(u32),
}
Expand description

GGML tensor dtype codes encountered in GGUF checkpoints.

Values mirror the GGML_TYPE_* constants in ggml.h. The parser understands their byte layout (for bounds checking) but performs no arithmetic — raw bytes are returned as-is. BF16 layout parsing is supported even though no BF16→F32 conversion is provided.

Types not explicitly enumerated are captured by DType::Other which preserves the raw code for callers to dispatch on.

Variants§

§

F32

32-bit little-endian float (GGML_TYPE_F32 = 0).

§

F16

16-bit IEEE-754 half float (GGML_TYPE_F16 = 1).

§

Q4_0

GGML_TYPE_Q4_0 — 4-bit symmetric quantization (block size 32).

§

Q4_1

GGML_TYPE_Q4_1 — 4-bit quantization with min (block size 32).

§

Q5_0

GGML_TYPE_Q5_0 — 5-bit symmetric quantization (block size 32).

§

Q5_1

GGML_TYPE_Q5_1 — 5-bit quantization with min (block size 32).

§

Q8_0

GGML_TYPE_Q8_0 — 8-bit symmetric quantization (block size 32).

§

Q8_1

GGML_TYPE_Q8_1 — 8-bit quantization with min (block size 32).

§

Q2_K

GGML_TYPE_Q2_K — k-quant 2-bit.

§

Q3_K

GGML_TYPE_Q3_K — k-quant 3-bit.

§

Q4_K

GGML_TYPE_Q4_K — k-quant 4-bit.

§

Q5_K

GGML_TYPE_Q5_K — k-quant 5-bit.

§

Q6_K

GGML_TYPE_Q6_K — k-quant 6-bit.

§

Q8_K

GGML_TYPE_Q8_K — k-quant 8-bit.

§

IQ2_XXS

GGML_TYPE_IQ2_XXS — i-quant 2-bit extra-extra-small (wire layout only).

§

IQ2_XS

GGML_TYPE_IQ2_XS — i-quant 2-bit extra-small.

§

IQ3_XXS

GGML_TYPE_IQ3_XXS — i-quant 3-bit extra-extra-small.

§

IQ1_S

GGML_TYPE_IQ1_S — i-quant 1-bit small.

§

IQ4_NL

GGML_TYPE_IQ4_NL — i-quant 4-bit non-linear (block size 32).

§

IQ3_S

GGML_TYPE_IQ3_S — i-quant 3-bit small.

§

IQ2_S

GGML_TYPE_IQ2_S — i-quant 2-bit small.

§

IQ4_XS

GGML_TYPE_IQ4_XS — i-quant 4-bit extra-small.

§

IQ1_M

GGML_TYPE_IQ1_M — i-quant 1-bit medium.

§

BF16

Google Brain bfloat16 (GGML_TYPE_BF16 = 30).

§

F64

64-bit IEEE-754 double float (GGML_TYPE_F64 = 28).

§

I8

8-bit signed integer (GGML_TYPE_I8 = 24).

§

I16

16-bit signed integer (GGML_TYPE_I16 = 25).

§

I32

32-bit signed integer (GGML_TYPE_I32 = 26).

§

I64

64-bit signed integer (GGML_TYPE_I64 = 27).

§

IQ3_M_BLOCK

Internal 111-byte IQ3_M block layout (GGML_TYPE_IQ3_M_BLOCK). Not GGUF wire type 31.

§

Other(u32)

Any other GGML dtype not explicitly enumerated above. The raw u32 code is preserved so callers can dispatch on it.

Implementations§

Source§

impl DType

Source

pub fn from_ggml_type(code: u32) -> Self

Map a raw ggml_type code to a DType enum.

Source

pub fn ggml_type(self) -> u32

The raw ggml_type code for this dtype.

Source

pub fn label(self) -> &'static str

Short human-readable label for this dtype (e.g. "F32", "Q4_K").

Single source of truth: ggml_type_label on the wire code.

Source

pub fn quant_block_size(self) -> Option<usize>

Quantization block length along the innermost GGUF dimension, if any.

Used to reject shapes whose dims[0] cannot form complete blocks. None for dense/integer types and unknown/Other codes.

Source

pub fn byte_len_for_elements(self, n_elements: usize) -> Option<usize>

Size in bytes of n_elements values of this dtype, or None for quantized/unknown layouts whose byte-length depends on the tensor’s inner dimension (not a simple n * sizeof(T)).

For quantized dtypes we return the correct blocked byte count when the total element count is divisible by the block size; otherwise None.

Block sizes follow the GGUF / llama.cpp wire layouts (ggml-common.h):

  • Q4_0/Q4_1/Q5_0/Q5_1/Q8_0/Q8_1/IQ4_NL: block size 32
  • K-quants and most IQ types: block size 256
  • Wire type 31 (Q4_0_4_4) is not modeled: use DType::Other

This is layout sizing only — no dequantization.

Source

pub fn has_known_byte_layout(self) -> bool

true if this crate models the wire layout of this dtype, i.e. every variant except DType::Other. For blocked quants the element count must also be block-aligned before Self::byte_len_for_elements returns Some.

Source

pub fn is_float(self) -> bool

Whether the dtype is a plain (non-quantized) float layout.

Matches the 0.1 surface: F32, F16, and BF16 (not F64).

Source

pub fn element_size(self) -> Option<usize>

Byte width of a single dense element, or None for block-quantized / integer / unknown dtypes (same contract as 0.1).

Trait Implementations§

Source§

impl Clone for DType

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DType

Source§

impl Debug for DType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DType

Source§

impl PartialEq for DType

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DType

Auto Trait Implementations§

§

impl Forget for DType

§

impl Freeze for DType

§

impl Move for DType

§

impl RefUnwindSafe for DType

§

impl Send for DType

§

impl Sync for DType

§

impl Unpin for DType

§

impl UnsafeUnpin for DType

§

impl UnwindSafe for DType

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.