tenzr:
:SafetensorsFile¶
Read-only memory-mapped view of a safetensors file exposing its tensors, descriptors, and metadata.
#include <safetensors.h>
Public Functions¶
| Name | |
|---|---|
| SafetensorsFile(const std::string & filepath) | |
| ~SafetensorsFile() Unmap the file and close its descriptor. |
|
| SafetensorsFile(const SafetensorsFile & ) =delete | |
| SafetensorsFile & | operator=(const SafetensorsFile & ) =delete |
| SafetensorsFile(SafetensorsFile && other) | |
| SafetensorsFile & | operator=(SafetensorsFile && other) |
| std::vector< std::string > | TensorNames() const Names of all tensors in the file. |
| bool | HasTensor(const std::string & name) const |
| const TensorDescriptor & | Descriptor(const std::string & name) const |
| const std::unordered_map< std::string, TensorDescriptor > & | Descriptors() const All tensor descriptors keyed by name. |
| const std::unordered_map< std::string, std::string > & | Metadata() const File metadata key/value pairs. |
| Tensor | LoadTensor(const std::string & name) const |
| std::unordered_map< std::string, Tensor > | LoadAll() const Load every tensor in the file, keyed by name. |
Public Functions Documentation¶
function SafetensorsFile¶
Parameters:
- filepath Path to the file.
Open and memory-map a safetensors file, parsing its header eagerly.
function ~SafetensorsFile¶
Unmap the file and close its descriptor.
function SafetensorsFile¶
function operator=¶
function SafetensorsFile¶
Parameters:
- other File to move from.
Move-construct a file mapping, leaving other closed.
function operator=¶
function TensorNames¶
Names of all tensors in the file.
Return: Tensor name list.
Names of all tensors in the file.
function HasTensor¶
Parameters:
- name Tensor name.
- name Tensor name.
Return:
- True when the tensor is present.
- true when present.
Whether a named tensor exists. Test whether the file contains a tensor named name.
function Descriptor¶
Parameters:
- name Tensor name.
- name Tensor name.
Return:
- The tensor's descriptor.
- Reference to the tensor descriptor.
Descriptor for a named tensor. Descriptor for a named tensor, throwing when absent.
function Descriptors¶
All tensor descriptors keyed by name.
function Metadata¶
File metadata key/value pairs.
function LoadTensor¶
Parameters:
- name Tensor name.
- name Tensor name.
Return:
- The loaded tensor.
- The loaded tensor.
Load a named tensor. Copy a named tensor's payload out of the mapping into a pooled buffer.
function LoadAll¶
Load every tensor in the file, keyed by name.
Return: Named tensors, keyed by tensor name.
Load every tensor in the file.