Loads an safetensors file from disk.
Value
A list with tensors in the file. The metadata
attribute can be used
to find metadata the metadata header in the file.
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)
}
#> $x
#> torch_tensor
#> 0.2072 -0.5577 -0.1501 -0.4462 -1.2974 0.0244 0.5455 0.6908 -0.0031 -0.6718
#> -0.5313 -0.9946 -0.4286 -2.6868 0.3131 1.7060 0.0496 1.1079 -0.5580 0.4718
#> 1.2002 -1.7819 0.6972 0.6069 1.3346 0.7134 -0.1354 0.3684 -0.9039 -0.6552
#> -0.6017 -0.6684 1.6912 -0.1900 -1.2360 0.2299 0.9415 1.0511 2.5836 0.2551
#> -0.6523 -3.0393 -0.3380 -1.0676 0.4144 0.0834 0.0755 0.8252 -1.5039 -0.0029
#> -0.1378 0.9695 0.5761 1.0304 1.1671 -0.2170 1.4931 1.0120 -0.4797 -0.7398
#> 1.3283 1.0177 0.0541 -0.4764 -0.0251 -0.5081 -3.2452 0.9264 0.3999 -1.9790
#> 1.8302 -0.1764 -0.8855 0.2053 1.1285 -1.2683 0.9076 -0.5027 -0.1819 0.0120
#> -0.1735 -0.1867 1.6554 -1.6727 2.0333 -0.3630 -0.9080 0.5600 -0.2927 1.4176
#> -1.2952 -0.1470 -0.2031 1.0760 1.8420 -0.7486 0.4747 -0.4411 0.0045 0.1342
#> [ CPUFloatType{10,10} ]
#>
#> attr(,"metadata")
#> attr(,"metadata")$x
#> attr(,"metadata")$x$shape
#> [1] 10 10
#>
#> attr(,"metadata")$x$dtype
#> [1] "F32"
#>
#> attr(,"metadata")$x$data_offsets
#> [1] 0 400
#>
#>
#> attr(,"max_offset")
#> [1] 468