Learn R Programming

safetensors (version 0.1.2)

safe_save_file: Writes a list of tensors to the safetensors format

Description

Writes a list of tensors to the safetensors format

Usage

safe_save_file(tensors, path, ..., metadata = NULL)

safe_serialize(tensors, ..., metadata = NULL)

Value

The path invisibly or a raw vector.

Arguments

tensors

A named list of tensors. Currently only torch tensors are supported.

path

The path to save the tensors to. It can also be a binary connection, as eg, created with file().

...

Currently unused.

metadata

An optional string that is added to the file header. Possibly adding additional description to the weights.

Functions

  • safe_serialize(): Serializes the tensors and returns a raw vector.

Examples

Run this code
if (rlang::is_installed("torch") && torch::torch_is_installed()) {
  tensors <- list(x = torch::torch_randn(10, 10))
  temp <- tempfile()
  safe_save_file(tensors, temp)
  safe_load_file(temp)

  ser <- safe_serialize(tensors)
}

Run the code above in your browser using DataLab