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 authentic implementation are being led
by Hugging Face, and it’s getting largely adopted of their well-liked ‘transformers’ framework. The safetensors R bundle is a pure-R implementation, permitting to each learn and write safetensor recordsdata.

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

Motivation

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

The principle 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, for the reason that Pickle parser that’s included in LibTorch solely helps a subset
of the Pickle format, which doesn’t embrace executing code.

Nevertheless, the file format has extra benefits over different generally used codecs, together with:

  • Assist for lazy loading: You’ll be able to 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 in some unspecified time in the future).

  • Easy: Implementing the file format is straightforward, and doesn’t require complicated dependencies.
    Which means it’s a very good format for exchanging tensors between ML frameworks and
    between completely different programming languages. For example, you’ll be able to write a safetensors file
    in R and cargo it in Python, and vice-versa.

There are extra benefits in comparison with different file codecs frequent on this area, and
you’ll be able to see a comparability desk right here.

Format

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

Diagram describing the safetensors file format.

Fundamental utilization

safetensors could be put in from CRAN utilizing:

Nick Fewings on Unsplash

Reuse

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

Quotation

For attribution, please cite this work as

Falbel (2023, June 15). Posit AI Weblog: safetensors 0.1.0. Retrieved from https://blogs.rstudio.com/tensorflow/posts/2023-06-15-safetensors/

BibTeX quotation

@misc{safetensors,
  creator = {Falbel, Daniel},
  title = {Posit AI Weblog: safetensors 0.1.0},
  url = {https://blogs.rstudio.com/tensorflow/posts/2023-06-15-safetensors/},
  yr = {2023}
}

Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox