SafeTensors
Read and write the SafeTensors binary format.
| Function | Description |
|---|---|
load filePath | Load all tensors from a .safetensors file. |
loadMeta filePath | Load only the header metadata from a .safetensors file. |
loadMetaFromStream stream | Parse the SafeTensors header from an open stream. |
| Returns (headerSize, tensorMetadata). | |
loadSelected filePath names | Load only the tensors whose names are in the given set. |
save tensors filePath | Save tensors to a .safetensors file. |
load
load filePath
Load all tensors from a .safetensors file.
Parameters
filePath:string
Returns Map<string, Tensor>
loadMeta
loadMeta filePath
Load only the header metadata from a .safetensors file.
Parameters
filePath:string
Returns Map<string, TensorMeta>
loadMetaFromStream
loadMetaFromStream stream
Parse the SafeTensors header from an open stream. Returns (headerSize, tensorMetadata).
Parameters
stream:Stream
Returns int64 * Map<string, TensorMeta>
loadSelected
loadSelected filePath names
Load only the tensors whose names are in the given set.
Parameters
filePath:stringnames:Set<string>
Returns Map<string, TensorMeta> * Map<string, Tensor>
save
save tensors filePath
Save tensors to a .safetensors file.
Parameters
tensors:Map<string, Tensor>filePath:string