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
impl DType
Sourcepub fn from_ggml_type(code: u32) -> Self
pub fn from_ggml_type(code: u32) -> Self
Map a raw ggml_type code to a DType enum.
Sourcepub fn label(self) -> &'static str
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.
Sourcepub fn quant_block_size(self) -> Option<usize>
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.
Sourcepub fn byte_len_for_elements(self, n_elements: usize) -> Option<usize>
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: useDType::Other
This is layout sizing only — no dequantization.
Sourcepub fn has_known_byte_layout(self) -> bool
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.
Sourcepub fn is_float(self) -> bool
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).
Sourcepub fn element_size(self) -> Option<usize>
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).