Safetensors
Safetensors is a file format from Hugging Face for storing model weights. Unlike Python pickle files, loading it cannot run hidden code, and it supports fast, memory-mapped loading of individual tensors.
Also called: .safetensors
By Divya Sharma · Checked Nov 15, 2026 · How we review
Model weights used to be shared mostly as PyTorch .bin or .pt files, which use Python's pickle format. Loading a pickle file can run arbitrary code, so a downloaded model could carry malware. Safetensors was built to remove that risk while keeping loading fast.
How it works
A safetensors file has a short JSON header that lists each tensor's name, data type, shape and position, followed by the raw tensor bytes. There is no code in it, only data. Because the layout is known in advance, a loader can map the file into memory and read just the tensors it needs without scanning the whole file. The project calls this zero-copy and lazy loading, which helps when splitting a model across several GPUs.
Why it matters
Safetensors is the common format on the Hugging Face hub and in the Transformers library. If a repo offers both safetensors and pickle files, choose safetensors. It is one simple defence against the kind of AI supply chain attack where a poisoned model file runs code on your machine.
How it differs from GGUF
Both store model weights. Safetensors is a neutral container used by Python training and serving stacks, with weights usually in full or half precision. GGUF is the format of llama.cpp and related local runners; it bundles metadata such as the tokenizer and is mostly used for quantized models. People often convert from safetensors to GGUF to run a model locally.
Limits
Safetensors makes loading safe, not the model itself. A file can still contain weights that behave badly, and the code in a repo that loads it can still be unsafe.
Related terms
- Model weights
- Model weights are the learned numbers inside a neural network, set during training, that decide how it turns input into output. A checkpoint is a saved file or set of files containing those weights.
- GGUF
- GGUF is a binary file format for storing a model's weights, tokenizer and metadata in one file, built for fast loading and local inference with GGML-based tools such as llama.cpp, often in quantized form.
- AI supply-chain attack
- An AI supply-chain attack compromises an AI application through something it depends on, such as a downloaded model, a LoRA adapter, a dataset, a Python package, an MCP server or an agent skill, rather than attacking the application directly.
- Open-weight model
- An open-weight model is a model whose trained weights are published for anyone to download and run, often without the training code or full training data, so it is not necessarily open source.
- Quantization
- Quantization is a technique that stores a model's weights, and sometimes activations, with fewer bits, such as 8 or 4 instead of 16, so the model needs less memory and often runs faster, at some cost in accuracy.