GGUF Binary Parser #
Binary parser for GGUF v3 format files. Uses single ByteArray with offset tracking (following gemma.hs pattern for efficiency).
Design Principles #
- Single Buffer Allocation: Pin ByteArray once, pass offsets
- Zero-Copy: Extract sub-arrays without copying when possible
- Bounds Checking: Return Except for all parsing operations
- Little-Endian: All integers are stored in little-endian format
References #
- gemma.hs/src/Gemma/GGUF.hs - Memory pinning strategy
- llama.cpp/gguf-py/gguf/gguf_reader.py - Format specification
Low-level Binary Reading Utilities #
Read Int32 (little-endian) from ByteArray
Equations
Instances For
Read Int64 (little-endian) from ByteArray
Equations
Instances For
Read Float32 (IEEE 754, little-endian) from ByteArray
Equations
Instances For
GGUF Header Parsing #
Parse GGUF header (24 bytes)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Metadata Parsing #
Parse a single metadata value (simplified - stores raw bytes)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Parse all metadata key-value pairs
Equations
- Hesper.GGUF.Parser.parseAllMetadata data offset count = Hesper.GGUF.Parser.parseAllMetadata.loop data offset count.toNat #[]
Instances For
Tensor Info Parsing #
Parse single tensor info
Equations
- One or more equations did not get rendered due to their size.
Instances For
Parse all tensor infos
Equations
- Hesper.GGUF.Parser.parseAllTensorInfos data offset count = Hesper.GGUF.Parser.parseAllTensorInfos.loop data offset count.toNat #[]
Instances For
partial def
Hesper.GGUF.Parser.parseAllTensorInfos.loop
(data : ByteArray)
(offset remaining : Nat)
(acc : Array TensorInfo)
: