Introduction
GGUF is the model format of the ggml machine learning library and of llama.cpp, which runs large language models on ordinary computers. It was introduced in August 2023 to replace the earlier GGML files. One GGUF file holds everything needed to run a model: its weights, often quantised to 8, 5 or 4 bits per value to save memory, and metadata such as the architecture, the context length and the tokenizer’s vocabulary.
A GGUF file can also hold a LoRA adapter instead of a whole model: a small set of extra weights that adjust a base model. llama.cpp converts adapters from the Hugging Face LoRA layout to GGUF and applies them to the base model when it loads.
Structure
Numbers are little-endian. A string is a 64-bit length followed by that many bytes of UTF-8.
0Magic the four bytesGGUF4 bytes4Version currently 34 bytes8Tensor count8 bytes16Metadata count8 bytes24Metadata key, value type, value; keys such asgeneral.architecturerepeated…Tensor info name, number of dimensions, dimensions, type, offsetrepeated…Padding to the alignment, 32 bytes unlessgeneral.alignmentsays otherwisevaries…Tensor data each tensor at its offset from heremost of the file
The type of each tensor names its encoding: plain floats such as F32 and F16, or one of the quantised block formats such as Q8_0 and Q4_K, which store small groups of values with a shared scale.
Version 1 files used 32-bit counts and string lengths; version 2 widened them to the 64 bits shown above, and version 3 added support for big-endian files. Current software writes version 3. The header and metadata and tensors and types pages give every field and code.
Not described
The reference follows docs/gguf.md, ggml-common.h and
ggml-quants.c.
Known, not yet covered
- Viewer: it does not read GGUF files that are split into shards as one model: each shard opens on its own.
Unknown
- Reference and viewer: the byte order inside the blocks of a big-endian file
is not defined by
docs/gguf.md, which says only that all values are big-endian. The viewer followsgguf-py/gguf/scripts/gguf_convert_endian.py(itsbyteswap_tensorstable: the multi-byte fieldsd,m,dmin,qh,scales_hare swapped, the byte arrays are not) for Q1_0, Q2_0, Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, Q2_K to Q6_K, IQ4_NL, IQ4_XS, TQ1_0, TQ2_0, MXFP4 and NVFP4, and for the types that script refuses (Q8_1, Q8_K, IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, IQ1_S, IQ1_M) it swaps each multi-byte field of the struct inggml-common.hwith the widthggml-quants.creads it with. No tool or file that produces those nine types big-endian is known, so that layout is the reading of the C code, not of a sample, and the Values tab says so. Q8_1 has nodequantize_rowfunction in ggml; the viewer shows d × qs[j], the inverse ofquantize_row_q8_1_ref, which the source does not state as a dequantiser. The i-quant decoders read their grid tables from the grids page when the viewer loads; if that page cannot be fetched they are labelled "not yet decoded" with that reason. - Reference: what the architecture-specific keys mean beyond what
llama.cpp's source states. The keys page gives
the meaning, default and checks of the keys read for every architecture and the
one-line comments the source has on its fields; for the remaining keys the source gives
only the field name, and what they do is in each architecture's graph code under
src/models, which was not read. The loader page has their value types, required flags and tensors. - Reference: prompting metadata and the computation graph: the specification marks them "TODO" or a future extension. The loader page shows what llama.cpp reads, including the adapter keys.
Links
Software
- llama.cpp – the reference program that runs GGUF language models (Windows, macOS, Linux)
- Ollama – downloads and runs GGUF models from the command line or an app (Windows, macOS, Linux)
- LM Studio – desktop app for finding and chatting with GGUF models (Windows, macOS, Linux)
- GPT4All – desktop chat app that runs GGUF models locally (Windows, macOS, Linux)
- Hugging Face – hosts GGUF models and shows their metadata on each model page (web)
Developers
Reference
- GGUF specification – the format description in the ggml repository