Design goals
- Single-file deployment — models can be distributed and loaded without external files.
- Extensibility — new metadata can be added without breaking existing readers.
mmapcompatibility — tensors are aligned so models can be loaded withmmap.- Full information — everything needed to load the model is embedded in the file itself.
File structure
A GGUF file is laid out sequentially as follows:Header
The header appears at the start of every GGUF file:Models are little-endian by default. Big-endian support was added in format version 3. If no additional information is provided, assume the model is little-endian.
Tensor info
Each tensor is described by agguf_tensor_info_t entry. The actual data starts after all tensor info entries, padded to the alignment boundary:
Alignment
The global alignment is set by thegeneral.alignment metadata key (default: 32). Padding bytes (0x00) are inserted to align tensor data:
Metadata types
Thegguf_type enum describes every value type that can appear in a GGUF key-value pair:
int32_t. Strings are serialized as a uint64_t length followed by the UTF-8 bytes without a null terminator.
Key-value pairs
Each metadata entry is agguf_metadata_kv_t:
namespace.property (e.g. general.architecture, llama.context_length). Community-defined keys should be prefixed with the community name (e.g. rustformers.my_key).
Tensor element types
Theggml_type enum covers all supported tensor element types, including floating-point and quantized formats:
C API
Initializing a context
Writing files
There are three ways to write a GGUF file:- Single pass
- Metadata then data
- Data then metadata
Write everything in one call:
Reading key-value metadata
Writing key-value metadata
Working with tensors
Standardized metadata keys
Required keys
General metadata
LLM hyperparameters
For LLM architectures, replace[llm] with the architecture name (e.g. llama, gpt2):
Tokenizer
Naming convention
GGUF filenames follow this structure:-. Components other than BaseName, SizeLabel, and Version are optional.
Examples
Validation regex
You can validate a filename with the following regular expression:Standardized tensor names
Models using the transformer architecture should use these tensor name conventions: Base layers —AA.weight / AA.bias where AA is:
Attention and feed-forward blocks —
blk.N.BB.weight / blk.N.BB.bias where N is the block index and BB is:
