Safetensors
What is Safetensors?
In one sentence: Safetensors is a safe, fast file format for storing model weights, created by Hugging Face.
Older formats could hide malicious code that runs when the file is loaded. Safetensors only stores numbers, so loading it cannot run hidden code. It also loads quickly.
What does Safetensors look like?
A model download containing "model.safetensors" uses this format.
Why does Safetensors matter?
Safetensors protects users from dangerous model files.
Safetensors vs. GGUF
Safetensors is the standard safe format for sharing model weights on Hugging Face and serving them on GPUs, while GGUF packs (usually quantized) weights plus tokenizer and settings into one file built for local tools like llama.cpp and Ollama.
| Dimension | Safetensors | GGUF |
|---|---|---|
| Primary ecosystem | PyTorch, vLLM, Hugging Face (training & servers) | llama.cpp, Ollama, LM Studio (local devices) |
| Packaging | Weight shards alongside config/tokenizer JSONs | Single self-contained file (weights + metadata) |
| Security | Zero-copy safe format replacing unsafe pickle files | Memory-mappable binary format (no arbitrary code) |
Last updated · Fact-checked by The AI Math
Linking to this page from a lesson or article? <a href="https://getaimath.com/dictionary/safetensors/">Safetensors, explained simply</a> (The AI Math Dictionary)