| safetensors | R Documentation |
Low level control over safetensors files
Low level control over safetensors files
Allows opening a connection to a safetensors file and query the tensor names, metadata, etc. Opening a connection only reads the file metadata into memory. This allows for more fined grained control over reading.
conthe connection object with the file
metadataan R list containing the metadata header in the file
frameworkthe framework used to return the tensors
argsadditional arguments for tensor creation
max_offsetthe largest offset boundary that was visited. Mainly used in torch to find the end of the safetensors file.
new()Opens the connection with the file
safetensors$new(path, ..., framework)
pathPath to the file to load
...(any)
Additional, framework dependent, arguments to pass to use when creating the tensor.
For torch, this is the device, for pjrt the client.
frameworkFramework to load the data into. Currently supports "torch" and "pjrt"
keys()Get the keys (tensor names) in the file
safetensors$keys()
get_tensor()Get a tensor from its name
safetensors$get_tensor(name)
nameName of the tensor to load
clone()The objects of this class are cloneable with this method.
safetensors$clone(deep = FALSE)
deepWhether to make a deep clone.
if (rlang::is_installed("torch") && torch::torch_is_installed()) {
tensors <- list(x = torch::torch_randn(10, 10))
temp <- tempfile()
safe_save_file(tensors, temp)
f <- safetensors$new(temp, framework = "torch")
f$get_tensor("x")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.