Skip to content
OriginalGuideAI

GGUF vs. SafeTensors vs. ONNX: three file formats, three different jobs

GGUF packs a runnable model, SafeTensors stores weights safely, and ONNX describes the computation. The extension tells you which job the file was built for.

Generative mathematical art on a near-black ground: a magenta torus knot, a cyan twisted lattice, and a lime-green wireframe polyhedron arranged on a rising diagonal, with a small warm-white wireframe sphere at the centre
Three wireframe forms around one small sphere: the same core, rendered three different ways.
On this page

In brief

  • GGUF packs weights, tokenizer, chat template, and metadata into one file built for local inference with llama.cpp, Ollama, and LM Studio.
  • SafeTensors stores only the weights plus a small metadata map, in a format that cannot execute code — the safe replacement for PyTorch pickle files.
  • ONNX stores a computation graph of operator nodes, so a model trained in one framework can run in ONNX Runtime on different hardware.
  • A model declares an IR version and an opset; a runtime on an older opset cannot run it — ONNX Runtime 1.32.0, released November 13, 2026, restored opset 28 support.
  • The choice is set by the software at the other end: GGUF for local running, SafeTensors for training and publishing, ONNX for moving models between frameworks.

Three files sit in a downloads folder, each several gigabytes, each a model. One ends in .gguf, one in .safetensors, one in .onnx. They look interchangeable. They are not. Each was built for a different job, and the extension tells you which one.

A model is mostly numbers, billions of weights, plus the information needed to use them. A file format decides how those pieces are packed, what else travels with them, and which programs can open the result.

The three jobs, in one table

FormatWhat it storesWhat runs itYou meet it when
GGUFWeights, tokenizer, chat template, and metadata in one filellama.cpp, Ollama, LM Studio, GPT4AllRunning a language model on your own machine
SafeTensorsWeights only, plus a small metadata mapHugging Face Transformers, diffusers, llama.cppDownloading weights from the Hub, or training in PyTorch
ONNXA computation graph: operators, weights, and the order to run themONNX Runtime, and anything that speaks the standardMoving a trained model between frameworks or onto different hardware
Three stacked bars showing what each format contains: GGUF packs metadata and tensor data in one file, SafeTensors holds a JSON header and a tensor buffer, ONNX holds a graph with weights inline or in external files
What is actually inside each file: GGUF packs everything into one file, SafeTensors stores only the weights, and ONNX stores the graph, with large weights often in separate files. Source.

GGUF: the whole model in one file

GGUF is a binary format built for GGML, the tensor library underneath llama.cpp. Its design goal is that a single file contains everything needed to load a model, with nothing else to fetch. The weights sit beside a key-value metadata section that carries the architecture, the quantization recipe, and the tokenizer: the token list, the merge rules, and the chat template that formats a conversation for the model.

Download one file, point llama.cpp or Ollama at it, and it runs. The format is also built to be memory-mapped, so the operating system can page the weights in from disk instead of reading the whole file into RAM first.

GGUF file names follow a convention of base name, size, version, and encoding, so Mixtral-8x7B-v0.1-KQ2.gguf reads as an 8-by-7-billion mixture-of-experts model, version 0.1, quantized with KQ2. The quant suffix decides the file size: Q4_K_M, the level most people download first, stores each weight in about 4.89 bits instead of 16, which is why an 8-billion-parameter model lands at roughly 4.6 GB instead of 15.

SafeTensors: just the weights, and safe to open

PyTorch's default weight files are Python pickle, and unpickling a file runs whatever code the file contains. SafeTensors, built by Hugging Face and released in 2022, stores tensors in a format that cannot execute code at all.

Eight bytes state the length of a JSON header. The header lists every tensor by name with its data type, shape, and byte offsets. The rest of the file is one flat buffer of tensor data. Nothing in the file is code, and the header is capped at 100 MB so a malicious file cannot force a parser to chew through an enormous JSON document. A loader can read one tensor without touching the rest.

What it does not store is the point: no tokenizer, no architecture description, no training config, only the tensors and an optional string-to-string metadata map. The architecture and tokenizer live in separate files on the model page. That split is why a Hugging Face model repository has a dozen files and a GGUF download has one.

It is also the Hub's recommended format. If you train or fine-tune in PyTorch and save the result, this is almost certainly the file you produce. If you then want to run it on your laptop, the usual next step is converting it to GGUF: the conversion bakes in a quantization level and a GGML-specific layout, and converting back recovers neither the original precision nor the original structure.

ONNX: the model as a recipe

ONNX solves a different problem again. A model trained in PyTorch cannot run in TensorFlow, and neither runs natively on a phone's neural processor or a browser's WebGPU backend. ONNX, the Open Neural Network Exchange, describes a model as a computation graph: operator nodes, MatMul, Attention, RotaryEmbedding, connected in order, with the weights attached. Train in one framework, export to ONNX, run it in ONNX Runtime on whatever hardware has an execution provider for it.

The graph is the real content: two files can hold identical weights and be different models if their graphs differ, which is why ONNX keeps adding operators. The current release, ONNX 1.23.2 from October 2026, uses IR version 14 and opset 28, and added a SwiGLU operator, the activation function modern language models use.

A model declares the IR version, the version of the file format itself, and the opset, the version of the operator library it was written against. A runtime that only implements an older opset cannot run a model written against a newer one, and the two do not always move together: ONNX Runtime 1.31 was still built on ONNX 1.22, one opset behind the format, until version 1.32.0 on November 13, 2026 reintegrated ONNX 1.23.2 and restored opset 28 support. The mismatch surfaces as a cryptic load error.

ONNX files are Protocol Buffers, and a single protobuf message has a 2 GB ceiling. Large models keep their weights in separate external data files next to the .onnx file instead of inside it.

How to choose

The choice is set by the software at the other end.

If the model is going to run on your machine through Ollama, llama.cpp, or LM Studio, you want GGUF, and specifically the quantization level that fits your memory. The arithmetic for that decision, weights plus the conversation's KV cache, is the same one that decides which machine to buy. If you are training, fine-tuning, or publishing weights for others to build on, SafeTensors is the file to produce: it is what the Hub expects, and the only one of the three designed around not executing code from a stranger. If you are shipping a model into production across frameworks, or onto hardware your training framework does not target, ONNX is the interchange format, and the runtime version deserves as much attention as the model version.

Converting between them is possible in some directions and pointless in most: GGUF to SafeTensors loses the quantization choice and the GGML layout without recovering the original weights. SafeTensors to GGUF is routine and is how most local models are made. Either of them to ONNX is a different operation entirely, because ONNX wants the computation graph, and the graph has to come from the framework that built the model, not from a file that never stored it.

The formats overlap just enough to be confusing and too little to be interchangeable. A .gguf file is a runnable model. A .safetensors file is a set of weights waiting for a framework. An .onnx file is a recipe for a computation, with the weights sometimes sitting next door.

Related reporting

More from grep.tips

All articles