File Formats
  • Audio
  • Video
  • Images
  • 3D & CAD
  • Documents
  • Data
  • Code
  • System
Data
  • Structured text
  • Binary serialisation
  • Databases
  • Scientific
  • Geospatial
  • Machine learning
  • Messages & calendars
  • Compression
  • Archives
  1. Home
  2. Data
  3. Machine learning
  4. Safetensors
.SAFETENSORS
  • Overview

.SAFETENSORS

Safetensors

Introduction

Safetensors is a simple format for storing the weights of a neural network, made by Hugging Face in 2022. Earlier PyTorch checkpoints used Python’s pickle format, which can run code when a file is loaded. A safetensors file holds only a description of each tensor and its raw numbers, so loading one is safe, and the data can be mapped straight into memory. It is now the usual format for models shared on Hugging Face, including image generation checkpoints.

Software

  • safetensors, the reference library for Python and Rust
  • Hugging Face Transformers and other Hugging Face libraries
  • PyTorch, through the safetensors library
  • ComfyUI, for image generation models (Windows, macOS, Linux)
  • Stable Diffusion web UI (Windows, macOS, Linux)

Structure

  1. 0Header size an unsigned 64-bit little-endian number, N8 bytes
  2. 8Header a UTF-8 JSON objectN bytes
  3. 8 + NData the tensors’ bytes, one after anotherthe rest
A safetensors file: header size, JSON header, tensor data.

The header maps each tensor’s name to an object with its dtype (such as F32, F16, BF16 or I8), its shape, and data_offsets: the start and end of its bytes, counted from the start of the data. An optional __metadata__ entry holds free text pairs, such as the format of the original checkpoint. The header may be padded with spaces at the end.

© 2026 fileformats.org About Contact Made by Lewpen