pulsatrix
Loading...
Searching...
No Matches
pulsatrix::SafetensorsFile Class Reference

A parsed, fully validated safetensors file held in memory. More...

#include <safetensors.hpp>

Public Member Functions

const std::vector< std::string > & names () const
 Tensor names in storage order (by data offset).
 
bool contains (const std::string &name) const
 
const SafetensorsTensorInfo & info (const std::string &name) const
 The header entry for name.
 
const std::map< std::string, std::string > & metadata () const
 The __metadata__ string map (empty if the file has none).
 
std::pair< const uint8_t *, size_t > bytes (const std::string &name) const
 The raw little-endian bytes of name, as {pointer, size}, valid while this object lives. For dtypes that don't convert to a Tensor yet.
 
Tensor tensor (const std::string &name, DeviceBackend *backend) const
 Copies tensor name into a new Tensor on backend's device.
 

Static Public Member Functions

static SafetensorsFile Read (const std::string &path)
 Reads and validates a file.
 
static SafetensorsFile Parse (std::vector< uint8_t > bytes)
 Validates a file's bytes.
 

Detailed Description

A parsed, fully validated safetensors file held in memory.

Member Function Documentation

◆ bytes()

std::pair< const uint8_t *, size_t > pulsatrix::SafetensorsFile::bytes ( const std::string &  name) const

The raw little-endian bytes of name, as {pointer, size}, valid while this object lives. For dtypes that don't convert to a Tensor yet.

Exceptions
std::invalid_argumentif there is no tensor called name.

◆ contains()

bool pulsatrix::SafetensorsFile::contains ( const std::string &  name) const
inline

◆ info()

const SafetensorsTensorInfo & pulsatrix::SafetensorsFile::info ( const std::string &  name) const

The header entry for name.

Exceptions
std::invalid_argumentif there is none.

◆ metadata()

const std::map< std::string, std::string > & pulsatrix::SafetensorsFile::metadata ( ) const
inline

The __metadata__ string map (empty if the file has none).

◆ names()

const std::vector< std::string > & pulsatrix::SafetensorsFile::names ( ) const
inline

Tensor names in storage order (by data offset).

◆ Parse()

static SafetensorsFile pulsatrix::SafetensorsFile::Parse ( std::vector< uint8_t >  bytes)
static

Validates a file's bytes.

Exceptions
std::invalid_argumentif they are not a valid safetensors file.

◆ Read()

static SafetensorsFile pulsatrix::SafetensorsFile::Read ( const std::string &  path)
static

Reads and validates a file.

Exceptions
std::runtime_errorif the file can't be opened or read.
std::invalid_argumentif its contents are not a valid safetensors file.

◆ tensor()

Tensor pulsatrix::SafetensorsFile::tensor ( const std::string &  name,
DeviceBackend *  backend 
) const

Copies tensor name into a new Tensor on backend's device.

Exceptions
std::invalid_argumentif there is no tensor called name, or its dtype isn't F32 (converting F16/BF16 is roadmap IO-6).

The documentation for this class was generated from the following file: