Close Menu
geekfence.comgeekfence.com
    What's Hot

    From answer to act: the next phase of Artificial Intelligence (AI) in banking and financial services 

    July 9, 2026

    Posit AI Blog: Introducing the text package

    July 9, 2026

    Cut costs and simplify operations with writable warm storage in Amazon OpenSearch Service

    July 9, 2026
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»Artificial Intelligence»Posit AI Blog: safetensors 0.1.0
    Artificial Intelligence

    Posit AI Blog: safetensors 0.1.0

    AdminBy AdminJanuary 28, 2026No Comments4 Mins Read4 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    Posit AI Blog: safetensors 0.1.0
    Share
    Facebook Twitter LinkedIn Pinterest Email


    safetensors is a new, simple, fast, and safe file format for storing tensors. The design of the file format and its original implementation are being led
    by Hugging Face, and it’s getting largely adopted in their popular ‘transformers’ framework. The safetensors R package is a pure-R implementation, allowing to both read and write safetensor files.

    The initial version (0.1.0) of safetensors is now on CRAN.

    Motivation

    The main motivation for safetensors in the Python community is security. As noted
    in the official documentation:

    The main rationale for this crate is to remove the need to use pickle on PyTorch which is used by default.

    Pickle is considered an unsafe format, as the action of loading a Pickle file can
    trigger the execution of arbitrary code. This has never been a concern for torch
    for R users, since the Pickle parser that is included in LibTorch only supports a subset
    of the Pickle format, which doesn’t include executing code.

    However, the file format has additional advantages over other commonly used formats, including:

    • Support for lazy loading: You can choose to read a subset of the tensors stored in the file.

    • Zero copy: Reading the file does not require more memory than the file itself.
      (Technically the current R implementation does makes a single copy, but that can
      be optimized out if we really need it at some point).

    • Simple: Implementing the file format is simple, and doesn’t require complex dependencies.
      This means that it’s a good format for exchanging tensors between ML frameworks and
      between different programming languages. For instance, you can write a safetensors file
      in R and load it in Python, and vice-versa.

    There are additional advantages compared to other file formats common in this space, and
    you can see a comparison table here.

    Format

    The safetensors format is described in the figure below. It’s basically a header file
    containing some metadata, followed by raw tensor buffers.

    Diagram describing the safetensors file format.
    Diagram describing the safetensors file format.

    Basic usage

    safetensors can be installed from CRAN using:

    install.packages("safetensors")

    We can then write any named list of torch tensors:

    library(torch)
    library(safetensors)
    
    tensors <- list(
      x = torch_randn(10, 10),
      y = torch_ones(10, 10)
    )
    
    str(tensors)
    #> List of 2
    #>  $ x:Float [1:10, 1:10]
    #>  $ y:Float [1:10, 1:10]
    
    tmp <- tempfile()
    safe_save_file(tensors, tmp)

    It’s possible to pass additional metadata to the saved file by providing a metadata
    parameter containing a named list.

    Reading safetensors files is handled by safe_load_file, and it returns the named
    list of tensors along with the metadata attribute containing the parsed file header.

    tensors <- safe_load_file(tmp)
    str(tensors)
    #> List of 2
    #>  $ x:Float [1:10, 1:10]
    #>  $ y:Float [1:10, 1:10]
    #>  - attr(*, "metadata")=List of 2
    #>   ..$ x:List of 3
    #>   .. ..$ shape       : int [1:2] 10 10
    #>   .. ..$ dtype       : chr "F32"
    #>   .. ..$ data_offsets: int [1:2] 0 400
    #>   ..$ y:List of 3
    #>   .. ..$ shape       : int [1:2] 10 10
    #>   .. ..$ dtype       : chr "F32"
    #>   .. ..$ data_offsets: int [1:2] 400 800
    #>  - attr(*, "max_offset")= int 929

    Currently, safetensors only supports writing torch tensors, but we plan to add
    support for writing plain R arrays and tensorflow tensors in the future.

    Future directions

    The next version of torch will use safetensors as its serialization format,
    meaning that when calling torch_save() on a model, list of tensors, or other
    types of objects supported by torch_save, you will get a valid safetensors file.

    This is an improvement over the previous implementation because:

    1. It’s much faster. More than 10x for medium sized models. Could be even more for large files.
      This also improves the performance of parallel dataloaders by ~30%.

    2. It enhances cross-language and cross-framework compatibility. You can train your model
      in R and use it in Python (and vice-versa), or train your model in tensorflow and run it
      with torch.

    If you want to try it out, you can install the development version of torch with:

    remotes::install_github("mlverse/torch")

    Photo by Nick Fewings on Unsplash

    Enjoy this blog? Get notified of new posts by email:

    Posts also available at r-bloggers

    Reuse

    Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don’t fall under this license and can be recognized by a note in their caption: “Figure from …”.

    Citation

    For attribution, please cite this work as

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

    BibTeX citation

    @misc{safetensors,
      author = {Falbel, Daniel},
      title = {Posit AI Blog: safetensors 0.1.0},
      url = {},
      year = {2023}
    }



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    Posit AI Blog: Introducing the text package

    July 9, 2026

    The Download: worms fight pollution, and geoengineering faces reality

    July 8, 2026

    Guidelines for Respectful Use of AI – O’Reilly

    July 7, 2026

    Expanding our Heat Resilience data to 50+ global cities

    July 6, 2026

    2026 BAIR Graduate Showcase – The Berkeley Artificial Intelligence Research Blog

    July 5, 2026

    Microsoft Frontier Company: AI engineering that amplifies and protects your intelligence

    July 4, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202560 Views

    Hard-braking events as indicators of road segment crash risk

    January 14, 202631 Views

    Redefining AI efficiency with extreme compression

    March 25, 202629 Views
    Don't Miss

    From answer to act: the next phase of Artificial Intelligence (AI) in banking and financial services 

    July 9, 2026

    Recent moves by Temenos, FIS, and Backbase point to a significant shift in banking technology strategy. Over the…

    Posit AI Blog: Introducing the text package

    July 9, 2026

    Cut costs and simplify operations with writable warm storage in Amazon OpenSearch Service

    July 9, 2026

    Data centre delays expose AI cloud power limits

    July 9, 2026
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    From answer to act: the next phase of Artificial Intelligence (AI) in banking and financial services 

    July 9, 2026

    Posit AI Blog: Introducing the text package

    July 9, 2026

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.