Last updated: 2026-06-12
Model Format & Loading
GGUF
Parse GGUF container files and expose the metadata needed by the loader.
The helpers in this module decode GGUF headers, metadata values, tensor offsets, and GGML quantization information without copying the whole file.
10 exports shown
constant
GGUF_MAGIC
pub const GGUF_MAGIC: u32 = 0x46554747 Little-endian magic value expected at the start of every GGUF file.
enum
GGUFVersion
pub const GGUFVersion = enum(u32) GGUF container versions recognized by the parser.
enum
GGUFType
pub const GGUFType = enum(u32) Primitive metadata value tags defined by the GGUF format.
enum
GGMLType
pub const GGMLType = enum(u32) GGML tensor storage and quantization formats referenced by GGUF tensors.
union
MetadataValue
pub const MetadataValue = union(enum) Typed representation of a GGUF metadata value.
Methods
5method
MetadataValue.asString
pub fn asString(self: MetadataValue) ?[]const u8 Interpret the metadata value as a string slice when the stored type is `.string`.
method
MetadataValue.asU32
pub fn asU32(self: MetadataValue) ?u32 Interpret the metadata value as an unsigned 32-bit integer when it fits.
method
MetadataValue.asU64
pub fn asU64(self: MetadataValue) ?u64 Interpret the metadata value as an unsigned 64-bit integer when it fits.
method
MetadataValue.asF32
pub fn asF32(self: MetadataValue) ?f32 Interpret the metadata value as a 32-bit floating-point number when possible.
method
MetadataValue.asBool
pub fn asBool(self: MetadataValue) ?bool Interpret the metadata value as a boolean when possible.
struct
TensorInfo
pub const TensorInfo = struct Tensor descriptor read from the GGUF header for a single named weight tensor.
Methods
2method
TensorInfo.numElements
pub fn numElements(self: *const TensorInfo) u64 Multiply the active tensor dimensions to get the logical element count.
method
TensorInfo.sizeBytes
pub fn sizeBytes(self: *const TensorInfo) u64 Compute the serialized tensor byte size for the descriptor's GGML storage format.
struct
GGUFFile
pub const GGUFFile = struct Fully decoded GGUF file: header fields, key-value metadata, and tensor descriptor table.
Methods
6method
GGUFFile.deinit
pub fn deinit(self: *GGUFFile) void Release metadata keys, metadata payloads, and tensor names owned by the parsed file.
method
GGUFFile.getString
pub fn getString(self: *const GGUFFile, key: []const u8) ?[]const u8 Look up a metadata string value by key.
method
GGUFFile.getU32
pub fn getU32(self: *const GGUFFile, key: []const u8) ?u32 Look up a metadata value as `u32` when it can be normalized to that type.
method
GGUFFile.getF32
pub fn getF32(self: *const GGUFFile, key: []const u8) ?f32 Look up a metadata value as `f32` when it can be normalized to that type.
method
GGUFFile.getBool
pub fn getBool(self: *const GGUFFile, key: []const u8) ?bool Look up a metadata value as `bool` when it can be normalized to that type.
method
GGUFFile.findTensor
pub fn findTensor(self: *const GGUFFile, name: []const u8) ?*const TensorInfo Find a tensor descriptor by name.
struct
ParseOptions
pub const ParseOptions = struct Optional flags that control GGUF parsing behavior.
function
parse
pub fn parse(data: []const u8, allocator: std.mem.Allocator) !GGUFFile Parse a GGUF file from a byte slice.
function
parseWithOptions
pub fn parseWithOptions(data: []const u8, allocator: std.mem.Allocator, options: ParseOptions) !GGUFFile Parse a GGUF file from a byte slice with optional logging control.