Thursday, June 13, 2024
HomeArtificial IntelligencePosit AI Weblog: safetensors 0.1.0

Posit AI Weblog: safetensors 0.1.0

safetensors is a brand new, easy, quick, and secure file format for storing tensors. The design of the file format and its unique implementation are being led
by Hugging Face, and it’s getting largely adopted of their standard ‘transformers’ framework. The safetensors R package deal is a pure-R implementation, permitting to each learn and write safetensor information.

The preliminary model (0.1.0) of safetensors is now on CRAN.


The primary motivation for safetensors within the Python neighborhood is safety. As famous
within the official documentation:

The primary rationale for this crate is to take away the necessity to use pickle on PyTorch which is utilized by default.

Pickle is taken into account an unsafe format, because the motion of loading a Pickle file can
set off the execution of arbitrary code. This has by no means been a priority for torch
for R customers, because the Pickle parser that’s included in LibTorch solely helps a subset
of the Pickle format, which doesn’t embody executing code.

Nonetheless, the file format has further benefits over different generally used codecs, together with:

  • Help for lazy loading: You possibly can select to learn a subset of the tensors saved within the file.

  • Zero copy: Studying the file doesn’t require extra reminiscence than the file itself.
    (Technically the present R implementation does makes a single copy, however that may
    be optimized out if we actually want it sooner or later).

  • Easy: Implementing the file format is easy, and doesn’t require complicated dependencies.
    Because of this it’s a great format for exchanging tensors between ML frameworks and
    between totally different programming languages. As an illustration, you may write a safetensors file
    in R and cargo it in Python, and vice-versa.

There are further benefits in comparison with different file codecs frequent on this house, and
you may see a comparability desk right here.


The safetensors format is described within the determine beneath. It’s principally a header file
containing some metadata, adopted by uncooked tensor buffers.

Diagram describing the safetensors file format.

Primary utilization

safetensors could be put in from CRAN utilizing:

Nick Fewings on Unsplash


Textual content and figures are licensed beneath Inventive Commons Attribution CC BY 4.0. The figures which were reused from different sources do not fall beneath this license and could be acknowledged by a observe of their caption: “Determine from …”.


For attribution, please cite this work as

Falbel (2023, June 15). Posit AI Weblog: safetensors 0.1.0. Retrieved from

BibTeX quotation

  creator = {Falbel, Daniel},
  title = {Posit AI Weblog: safetensors 0.1.0},
  url = {},
  12 months = {2023}


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments