Safetensors stores tensor data without pickle object loading
Summary
Safetensors is a tensor-storage format designed as an alternative to pickle. Its Python interface can read named tensors, and safe_open also supports reading a slice. [S1]
Details
The file begins with a header-length field followed by a JSON header and a tensor byte buffer. Header entries describe tensor names, shapes, data types, and byte offsets. The README limits metadata to string-to-string values. Format safety is not a claim about the meaning of a tensor: the README notes that tensor values can include NaN and infinity. [S1, S2]
Claims
- id: C1 claim: "safe_open can retrieve only a portion of tensor data." source: S1 evidence: "Loading only part of the tensors"
- id: C2 claim: "The header is a UTF-8 JSON string." source: S2 evidence: "a JSON UTF-8 string representing the header"
- id: C3 claim: "Tensor values are not validated for NaN or infinity." source: S2 evidence: "Tensor values are not checked against"
Sources
- [S1] Safetensors. Hugging Face Safetensors contributors. https://raw.githubusercontent.com/huggingface/safetensors/main/docs/source/index.mdx. Apache-2.0; license: https://raw.githubusercontent.com/huggingface/safetensors/main/LICENSE. Accessed 2026-11-05.
- [S2] safetensors. Hugging Face Safetensors contributors. https://raw.githubusercontent.com/huggingface/safetensors/main/README.md. Apache-2.0; license: https://raw.githubusercontent.com/huggingface/safetensors/main/LICENSE. Accessed 2026-11-05.
Attribution and notices
This note is CC BY 4.0. Source material has been condensed and restated; short evidence excerpts retain their source license.
Hugging Face Safetensors documentation is Apache-2.0. This note restates the documentation and includes only short evidence excerpts. See the accompanying source license.
License: CC-BY-4.0 · Original synthesis by iinventedlight, drafted by Librarian with AI assistance; based on the attributed sources
Cite this
Librarian. n.d.. "Safetensors stores tensor data without pickle object loading." iinventedlight Library, iil:note:9hcfshzf. https://iinventedlight.com/library/notes/hf-safetensors/. License: CC-BY-4.0.
@misc{iil_note_9hcfshzf,
author = {{Librarian}},
title = {{Safetensors stores tensor data without pickle object loading}},
howpublished = {iinventedlight Library},
url = {https://iinventedlight.com/library/notes/hf-safetensors/},
note = {Permanent ID iil:note:9hcfshzf. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/hf-safetensors.md.