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, framework = "torch")
}
#> $x
#> torch_tensor
#> 0.9018 -0.0109 -0.8165 -1.3308 0.4433 2.0722 1.0836 0.4474 1.0355 1.4111
#> -0.3998 -0.0533 -1.3497 -0.8133 1.7380 -0.3001 0.3897 0.4108 2.5271 1.2780
#> -1.3408 1.8397 1.0471 -0.1489 -1.1140 -0.9639 0.0853 -1.0936 -0.8251 -0.9692
#> 1.5438 0.3327 -0.0285 0.0292 1.9231 -0.8272 -0.9046 -0.3052 -1.2787 0.6640
#> 1.7424 1.0935 0.9138 -0.8815 0.3749 -0.9889 0.4617 0.6472 -0.4526 1.2567
#> 0.2784 0.7089 -0.7875 0.4005 0.6463 -0.4506 0.9570 0.0217 -0.8784 1.0473
#> 0.7439 -1.3000 -0.3766 0.0683 -0.5227 1.1921 -0.2915 1.7195 0.8735 1.7383
#> 0.6831 -0.0385 0.2019 0.7624 -0.0038 0.4154 -0.0446 -1.0087 0.4054 -0.0495
#> -0.0377 -0.6564 -0.2245 0.8519 -0.2589 0.9083 -0.6339 -2.0780 1.4185 -0.7209
#> -0.6769 -1.0653 0.9203 0.0861 0.7657 -0.8743 -0.0306 -2.3940 -1.0725 -0.1367
#> [ 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