safe_save_file {safetensors} | R Documentation |
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)
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 |
... |
Currently unused. |
metadata |
An optional string that is added to the file header. Possibly adding additional description to the weights. |
Value
The path invisibly or a raw vector.
Functions
-
safe_serialize()
: Serializes the tensors and returns a raw vector.
Examples
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)
}
[Package safetensors version 0.1.2 Index]