An open API service indexing awesome lists of open source software.

https://github.com/mlverse/safetensors

Safetensors File Format
https://github.com/mlverse/safetensors

Last synced: 12 months ago
JSON representation

Safetensors File Format

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# safetensors

[![R-CMD-check](https://github.com/mlverse/safetensors/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mlverse/safetensors/actions/workflows/R-CMD-check.yaml)

safetensors is a pure R implementation of the [safetensors](https://github.com/huggingface/safetensors) file format.

Currently only reading files is supported.

## Installation

safetensors can be installed from CRAN with:

``` r
install.packages("safetensors")
```

The development version of safetensors from [GitHub](https://github.com/) with:

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

## Example

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

```{r}
library(torch)
library(safetensors)

tensors <- list(
x = torch_randn(10, 10),
y = torch_ones(10, 10)
)

str(tensors)

tmp <- tempfile()
safe_save_file(tensors, tmp)

tensors <- safe_load_file(tmp)
str(tensors)
```