pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::HfCheckpoint Class Reference

A Hugging Face checkpoint directory's weights: model.safetensors, or the shards listed by model.safetensors.index.json (IO-5). Shards are memory-mapped, so opening a checkpoint reads only headers, and a tensor's bytes are paged in when it is read. More...

#include <hf_model.hpp>

Public Member Functions

const std::vector< std::string > & names () const
 Every tensor name, sorted.
 
bool contains (const std::string &name) const
 
const std::string & shard_of (const std::string &name) const
 The shard file holding name.
 
const SafetensorsTensorInfo & info (const std::string &name) const
 name's header entry (dtype, shape).
 
Tensor tensor (const std::string &name, DeviceBackend *backend) const
 Reads name into a Tensor; see SafetensorsFile::tensor for the dtypes it converts.
 
std::vector< std::string > shards () const
 The shard files, in the order first listed.
 

Static Public Member Functions

static HfCheckpoint Open (const std::string &directory)
 Opens directory: the index if there is one, otherwise the single file.
 

Detailed Description

A Hugging Face checkpoint directory's weights: model.safetensors, or the shards listed by model.safetensors.index.json (IO-5). Shards are memory-mapped, so opening a checkpoint reads only headers, and a tensor's bytes are paged in when it is read.

Member Function Documentation

◆ contains()

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

◆ info()

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

name's header entry (dtype, shape).

Exceptions
std::invalid_argumentif there's none.

◆ names()

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

Every tensor name, sorted.

◆ Open()

static HfCheckpoint pulsatrix::HfCheckpoint::Open ( const std::string &  directory)
static

Opens directory: the index if there is one, otherwise the single file.

Exceptions
std::runtime_errorif neither file exists, or a file can't be read.
std::invalid_argumentif the index is malformed, names a shard outside the directory (any path separator or ..), lists a tensor its shard doesn't hold, or a shard holds a tensor the index doesn't list; or a shard isn't valid safetensors.

◆ shard_of()

const std::string & pulsatrix::HfCheckpoint::shard_of ( const std::string &  name) const

The shard file holding name.

Exceptions
std::invalid_argumentif there's no such tensor.

◆ shards()

std::vector< std::string > pulsatrix::HfCheckpoint::shards ( ) const

The shard files, in the order first listed.

◆ tensor()

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

Reads name into a Tensor; see SafetensorsFile::tensor for the dtypes it converts.


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