Skip to contents

Loads tensors from a file in the safetensors format.

Usage

nv_read(path, device = NULL)

Arguments

path

(character(1))
Path to the safetensors file.

device

(NULL | character(1) | PJRTDevice)
The device on which to place the loaded tensors ("cpu", "cuda", ...). Default is to use the CPU.

Value

Named list of AnvilTensor objects.

Details

This is a convenience wrapper around nv_unserialize() that opens and closes a file connection.

Examples

x <- nv_tensor(array(1:6, dim = c(2, 3)))
x
#> AnvilTensor
#>  1 3 5
#>  2 4 6
#> [ CPUi32{2,3} ] 
path <- tempfile(fileext = ".safetensors")
nv_save(list(x = x), path)
nv_read(path)
#> $x
#> AnvilTensor
#>  1 3 5
#>  2 4 6
#> [ CPUi32{2,3} ] 
#>