Skip to content

❗ This is a read-only mirror of the CRAN R package repository. safetensors — Safetensors File Format. Homepage: https://github.com/mlverse/safetensorshttps://mlverse.github.io/safetensors/ Report bugs for this package: https://github.com/mlverse/safetensors/issues

License

Notifications You must be signed in to change notification settings

cran/safetensors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

safetensors

R-CMD-check

safetensors is a pure R implementation of the safetensors file format.

Currently only reading files is supported.

Installation

safetensors can be installed from CRAN with:

install.packages("safetensors")

The development version of safetensors from GitHub with:

# install.packages("devtools")
devtools::install_github("mlverse/safetensors")

Example

Here’s an example of writing and reading safetensors files:

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)

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

About

❗ This is a read-only mirror of the CRAN R package repository. safetensors — Safetensors File Format. Homepage: https://github.com/mlverse/safetensorshttps://mlverse.github.io/safetensors/ Report bugs for this package: https://github.com/mlverse/safetensors/issues

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages