moongguf

GGUF · version 3 · MoonBit

Every byte of a
GGUF file.

The header, the metadata table, the tensor index, and the quantised blocks behind them — read from bytes, written back byte for byte, and handed over without a copy.

— encodings — value kinds versions 1–3 read v3 written
a file, to scale sample.gguf reading…

reading…

§ 01 — the shape of it

Four parts, one file.

A GGUF file is a small directory followed by a lot of weights. The directory holds everything a reader needs to answer questions about a model without touching a single weight.

01 / HEADER

The header

Four bytes of magic, the version, and two counts. Twenty-four bytes that say how much is coming.

fn is_gguf(bytes)
02 / METADATA

The metadata table

Key–value pairs the format types: architecture, layer count, the vocabulary. Thirteen kinds, arrays and arrays of arrays among them.

file.meta().text("general.architecture")
03 / TENSOR INDEX

The tensor index

One entry per tensor: its name, its shape in ggml's order, its encoding, and where its bytes begin.

file.tensor("token_embd.weight")
04 / DATA

The data section

The weights, block after block, each row a whole number of blocks. Read as a view into the bytes you already have.

file.data("token_embd.weight")
§ 02 — a file, read here

Ask a file what it holds.

Paste the hex of a file, or drop a .gguf from your disk. The library on this page is this repository compiled to JavaScript: the same parser, the same refusals, the same numbers.

bytes
reading…
what the library read
byte map header metadata index data
§ 03 — the table

Every encoding, one table.

A tensor's bytes are blocks: so many values, so many bytes. The library carries the whole table, from F32 to F8_E4M3, and uses it to check that a row is a whole number of blocks.

§ 04 — in MoonBit

Four lines to a weight.

The library deals in bytes, never in files: whatever read the file — a disk, a range request, a mapped buffer — hands the bytes over.

moonbit main.mbt
let file = @moongguf.File::parse(bytes[:])
let arch = file.meta().text("general.architecture")
let extent = file.extent("token_embd.weight")
let weight = file.data("token_embd.weight")