GGUF Format Specification: Unified File Format for Efficient Local Large Model Inference

Running large language models on a personal computer is now the norm. People do it for a variety of reasons: privacy, the ability to use them offline and for lower cost. To make that viable you need a file format that can load quickly and run on normal PC hardware. GGUF is that file format. This article is going to explain what GGUF is, how a GGUF file is structured, what quantisation is and what tools are available to work with it.

What GGUF Is and Why It Was Created

GGUF is a binary file format for storing the model weights and all the information required to run the model. It was introduced in August 2023 by the developers of llama.cpp and the GGML tensor library. The name is typically pronounced “GPT-Generated Unified Format”.

The Problem With Earlier Formats

Prior to GGUF, llama.cpp used the GGML era formats (GGML, GGMF, GGJT etc). Those formats contained very little metadata. A new model architecture or setting would often break the older files so users would have to reconvert their models quite frequently.

The GGUF Approach

GGUF deals with this by storing the metadata as flexible key value pairs. You can add new information without having to change the underlying structure. The end result is that a single GGUF file contains everything you need to load the model (the tokeniser, the architecture etc). There’s no need for any separate config files.

Inside a GGUF File

A GGUF file is in a fixed order. Knowing what each section is for is useful when you’re debugging, inspecting or converting models.

1. Header

The file starts off with the “GGUF” magic bytes, followed by a version number. Version 3 is the current version. The header also contains information on the number of tensors and the number of metadata entries.

2. Metadata

Metadata entries are key value pairs. Typical keys are general.architecture, general.name and context length settings. Architecture, general name and context length settings. The tokeniser details (vocabulary, chat template etc) are also stored in the metadata.

3. Tensor Information

Each tensor has a name, a number of dimensions, a shape, a data type and an offset which points to where it is located in the data section.

4. Tensor Data

The weights themselves come last and are aligned to a fixed boundary (32 bytes by default). This enables memory mapping so that the weights are only loaded into memory when required. That in turn reduces start-up time and reduces memory pressure.

Quantisation and Local Inference

Quantisation reduces the number of bits used to store each weight. A 16 bit model may be too large for a laptop, the 4 bit version only needs a little over a quarter of that space.

Common Quantisation Types

GGUF supports a whole host of different types. F16 maintains full half precision. Q8_0 is 8 bit with very little loss in quality. The K-quant types (Q4_K_M, Q5_K_M etc) strike a very good balance between size and accuracy and are by far the most popular. The newer IQ types are designed to deliver good quality at extremely low bit counts.

Choosing the Right Level

Lower bit counts save on memory but can of course lead to a reduction in output quality. The sensible thing to do is start with Q4_K_M and work up to Q5 or Q8 if your hardware is up to it and quality is more important than speed.

Tools and Learning Path

Several widely used tools read GGUF files:

  • llama.cpp, the reference implementation for CPU and GPU inference
  • Ollama, which wraps models in a simple command-line workflow
  • LM Studio, a desktop application with a graphical interface

Hugging Face host thousands of GGUF models and you can view the file metadata in the browser. To create your own files you can use the conversion script that llama.cpp provides for Hugging Face models and a separate quantisation tool. There’s also the gguf Python package which allows you to read and write files programmatically.

For the learner the real understanding comes from hands on work with the tools. If you’re assessing a gen AI course then look at whether it covers local inference, the trade-offs around quantisation and the various model file formats as well as the more familiar areas of prompt engineering and application design. A good gen AI course will have practical labs where the student actually goes out and converts, quantises and benchmarks models on their own machine.

Conclusion

GGUF has become the de facto format for running LLMS locally. The single file structure, the flexibility of the metadata, the memory mapping and the wide range of quantisation options all make it very easy to share models and very fast to load them. Understanding how GGUF works gives you a very clear insight into the journey of a model from the research lab to the end user’s own hardware. A good Gen AI course should have practical labs where the students are actually converting, quantising and benchmarking models on their own machines.

​

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *