Skip to content

tenzr::io

Classes

Name
class tenzr:🇮🇴:SafetensorsFile
Read-only memory-mapped view of a safetensors file exposing its tensors, descriptors, and metadata.
struct tenzr:🇮🇴:TensorDescriptor
Header metadata for one tensor in a safetensors file: name, dtype, shape, and payload byte range.

Functions

Name
void SaveSafetensors(const std::string & filepath, const std::unordered_map< std::string, Tensor > & tensors, const std::unordered_map< std::string, std::string > & metadata ={})
std::unordered_map< std::string, Tensor > LoadSafetensors(const std::string & filepath)
std::string DtypeToSafetensorsStr(DType dtype)
DType SafetensorsStrToDtype(const std::string & str)

Functions Documentation

function SaveSafetensors

void SaveSafetensors(
    const std::string & filepath,
    const std::unordered_map< std::string, Tensor > & tensors,
    const std::unordered_map< std::string, std::string > & metadata ={}
)

Parameters:

  • filepath Destination path.
  • tensors Tensors to write, keyed by name.
  • metadata Optional file metadata.
  • filepath Destination path.
  • tensors Named tensors to serialize.
  • metadata Optional string metadata stored under metadata.

Write tensors to a safetensors file. Write tensors and metadata to a safetensors file, materializing lazy tensors first.

function LoadSafetensors

std::unordered_map< std::string, Tensor > LoadSafetensors(
    const std::string & filepath
)

Parameters:

  • filepath Path to the file.
  • filepath Path to the file.

Return:

  • Tensors keyed by name.
  • Named tensors, keyed by tensor name.

Read every tensor from a safetensors file. Load all tensors from a safetensors file.

function DtypeToSafetensorsStr

static std::string DtypeToSafetensorsStr(
    DType dtype
)

function SafetensorsStrToDtype

static DType SafetensorsStrToDtype(
    const std::string & str
)