GGUF

On this page 7

GGUF is a single-file binary format for storing the weights, tokenizer and configuration of a machine learning model, designed for fast loading and local inference with the llama.cpp ecosystem. In edge AI, it has become the most common way to distribute quantized large language models that run on laptops, desktops, phones and small servers without a cloud connection.

The format was introduced in 2023 by the developers of the ggml tensor library as the successor to the older GGML and GGJT files. Its main improvement is an extensible key-value metadata section, which lets one file describe the model architecture, context length, tokenizer and quantization scheme, so a runtime needs no separate configuration files.

How the GGUF file is structured

A GGUF file is laid out as a header, a metadata block, a tensor index and a data region, written in little-endian byte order by default. The runtime reads the small header and index, then memory-maps the data region, so the operating system loads weights on demand instead of copying the whole file into memory.

The table below describes each part of the file in the order it appears.

PartContentsPurpose
Magic and versionThe bytes GGUF and a format version numberIdentifies the file and its revision
CountsNumber of tensors and number of metadata pairsLets the reader parse the rest
Metadata pairsTyped keys such as general.architectureDescribes model, tokenizer and settings
Tensor infosName, shape, data type and offset of each tensorLocates every weight in the file
PaddingBytes up to the alignment boundary, usually 32Enables efficient memory mapping
Tensor dataRaw or quantized weight blocksThe model parameters themselves
Layout of a GGUF file

Metadata keys follow namespaced conventions: general keys for name and license, architecture-specific keys such as attention head counts and rotary embedding settings, and tokenizer keys holding the vocabulary, merges and special tokens. Because unknown keys are simply ignored, new fields can be added without breaking older readers.

Quantization types stored in GGUF

GGUF stores weights in block-based quantization formats defined by ggml. Weights are grouped into small blocks, and each block keeps low-bit integers plus one or more scale factors. The newer k-quants organize blocks into super-blocks of 256 weights with quantized scales, which improves accuracy at the same size.

Typical variants differ in bits per weight, file size and quality loss, as the table shows for a model of roughly 7 to 8 billion parameters.

TypeApproximate bits per weightApproximate size for 8B modelQuality impact
F1616About 16 GBReference quality
Q8_0About 8.5About 8.5 GBNearly indistinguishable
Q6_KAbout 6.6About 6.6 GBVery small loss
Q5_K_MAbout 5.7About 5.7 GBSmall loss
Q4_K_MAbout 4.8About 4.9 GBModerate, widely accepted default
IQ2_XSAbout 2.3About 2.5 GBNoticeable degradation
Common GGUF quantization variants

The lowest-bit i-quants rely on an importance matrix computed from calibration text, which tells the quantizer which weights matter most. Suffixes such as M and S indicate mixed precision: sensitive tensors, such as attention output or embedding layers, receive more bits than the rest.

GGUF compared with other model formats

GGUF is an inference-oriented container, whereas most other formats target training or general interchange. The key differences concern self-containment, quantization support and loading speed.

FormatMain useQuantizationSelf-contained
GGUFLocal inference with llama.cpp and derived toolsBuilt-in block formats from 1.5 to 8 bitsYes, includes tokenizer and configuration
SafetensorsSafe sharing of training checkpointsDepends on external librariesNo, configuration files are separate
PyTorch pickleLegacy checkpointsNot standardizedNo, and loading can execute code
ONNXCross-runtime graph exchangeINT8 and some 4-bit operatorsGraph and weights, tokenizer separate
GGML (legacy)Predecessor of GGUFEarly block formatsPartly, with fragile versioning
GGUF and related model formats

Unlike pickle files, GGUF contains no executable code, which removes a common attack path. It still relies on a parser written in native code, so files from untrusted sources should be handled with an up-to-date runtime.

Using GGUF for local inference

The usual workflow is conversion, quantization and loading. A conversion script reads a Hugging Face checkpoint and writes an F16 or BF16 GGUF file; the quantize tool then produces smaller variants; finally a runtime such as llama.cpp, Ollama or LM Studio loads the file and optionally offloads some layers to a GPU.

SituationRecommended choiceReason
Laptop with 16 GB of shared memoryQ4_K_M of a 7B to 8B modelLeaves room for context and the system
Workstation with a 24 GB GPUQ5_K_M or Q6_K, all layers offloadedHigher quality at full GPU speed
Phone or single-board computerQ4_0 or IQ4 of a 1B to 3B modelFits tight memory and simple kernels
Quality-critical evaluationQ8_0 or F16Minimizes quantization error
Very long contextSmaller weights plus quantized KV cacheContext memory grows with length
Choosing a GGUF variant

Memory needs are roughly file size plus the KV cache plus runtime overhead. A 4.9 GB model with an 8,000-token context typically needs 6 to 7 GB in total, depending on architecture and cache precision.

Limitations and common mistakes

GGUF is tied closely to the ggml and llama.cpp ecosystem. Support for a new architecture appears only after developers implement it in the runtime, so a freshly released model may not be convertible immediately.

  • Wrong chat template: an outdated or missing template in metadata produces rambling or malformed answers.
  • Over-aggressive quantization: 2-bit and 3-bit variants of small models lose reasoning and coding ability quickly.
  • Ignoring the KV cache: users size memory for the file alone and run out at long contexts.
  • Version mismatch: older runtimes may reject files that use newer quantization types.
  • Training expectations: GGUF targets inference; fine-tuning normally happens on the original checkpoint.

A plain-language summary

An AI language model is a huge collection of numbers. GGUF is a way to pack those numbers into one tidy file. The file also holds the instructions a program needs to use them.

Think of a flat-pack furniture box. Everything is inside: the parts, the screws and the manual. GGUF works the same way. It also lets the numbers be stored in a compressed, rounded form. That makes the file small enough for an ordinary computer. The model can then run privately on your own device, without sending anything to the cloud.

An example from practice

A small law office wants an assistant that summarizes contracts, but its policy forbids sending client documents to external services. The office has a desktop with 32 GB of RAM and a GPU with 12 GB of video memory. An IT consultant downloads an 8-billion-parameter instruction model in Q5_K_M GGUF format, about 5.7 GB, and serves it with llama.cpp on the local network.

All layers fit on the GPU, and the assistant produces summaries at roughly 40 to 50 tokens per second with an 8,000-token context. Tests on twenty past contracts show summaries close to those of the F16 version. The office gains a fully offline tool that keeps confidential documents on its own hardware, at the cost of reviewing every summary before use.