|
TinyLlama.cpp 1.0
A lightweight C++ implementation of the TinyLlama language model
|
Represents a memory-mapped SafeTensors file (shard). More...
#include <safetensors_loader.h>

Public Member Functions | |
| Shard (const std::string &fp) | |
| Construct and memory-map a shard file. | |
| ~Shard () | |
| Destructor. Cleans up memory mapping and file handles. | |
| Shard (Shard &&other) noexcept | |
| Move constructor. | |
| Shard & | operator= (Shard &&other) noexcept |
| Move assignment operator. | |
| const uint8_t * | get_tensor_raw_data (size_t local_offset, size_t n_bytes) const |
| Get a pointer to the raw tensor data within this shard. | |
Public Attributes | |
| std::string | file_path |
| Path to the shard file. | |
| void * | mapped_data = nullptr |
| Pointer to the memory-mapped data. | |
| size_t | file_size = 0 |
| Size of the mapped file in bytes. | |
| uint64_t | metadata_size = 0 |
| Size of the metadata block in bytes. | |
| const uint8_t * | metadata_ptr = nullptr |
| Pointer to the start of the metadata block. | |
| const uint8_t * | tensor_data_block_ptr = nullptr |
| Pointer to the start of the tensor data block. | |
| int | fd_ = -1 |
Represents a memory-mapped SafeTensors file (shard).
Handles opening, memory-mapping, and cleanup for a single SafeTensors file. Used internally by SafeTensorsLoader to support sharded models.
Definition at line 42 of file safetensors_loader.h.
|
explicit |
Construct and memory-map a shard file.
| fp | Path to the shard file. |
| std::runtime_error | on failure. |
Definition at line 85 of file safetensors_loader.cpp.
References Logger::debug(), fd_, file_path, file_size, Logger::info(), mapped_data, metadata_ptr, metadata_size, and tensor_data_block_ptr.
| Shard::~Shard | ( | ) |
Destructor. Cleans up memory mapping and file handles.
Definition at line 167 of file safetensors_loader.cpp.
References Logger::debug(), Logger::error(), fd_, file_path, file_size, and mapped_data.
|
noexcept |
Move constructor.
Definition at line 204 of file safetensors_loader.cpp.
| const uint8_t * Shard::get_tensor_raw_data | ( | size_t | local_offset, |
| size_t | n_bytes | ||
| ) | const |
Get a pointer to the raw tensor data within this shard.
| local_offset | Offset from the start of the tensor data block. |
| n_bytes | Number of bytes to access. |
| std::out_of_range | if the requested range is invalid. |
Definition at line 261 of file safetensors_loader.cpp.
References file_path, file_size, mapped_data, metadata_size, and tensor_data_block_ptr.
Referenced by SafeTensorsLoader::get_tensor_bytes().
Move assignment operator.
Definition at line 231 of file safetensors_loader.cpp.
| int Shard::fd_ = -1 |
File descriptor for memory mapping
Definition at line 77 of file safetensors_loader.h.
| std::string Shard::file_path |
Path to the shard file.
Definition at line 46 of file safetensors_loader.h.
Referenced by get_tensor_raw_data(), SafeTensorsLoader::parse_shard_metadata(), Shard(), and ~Shard().
| size_t Shard::file_size = 0 |
Size of the mapped file in bytes.
Definition at line 56 of file safetensors_loader.h.
Referenced by get_tensor_raw_data(), Shard(), and ~Shard().
| void* Shard::mapped_data = nullptr |
Pointer to the memory-mapped data.
Definition at line 51 of file safetensors_loader.h.
Referenced by get_tensor_raw_data(), Shard(), and ~Shard().
| const uint8_t* Shard::metadata_ptr = nullptr |
Pointer to the start of the metadata block.
Definition at line 66 of file safetensors_loader.h.
Referenced by SafeTensorsLoader::parse_shard_metadata(), and Shard().
| uint64_t Shard::metadata_size = 0 |
Size of the metadata block in bytes.
Definition at line 61 of file safetensors_loader.h.
Referenced by get_tensor_raw_data(), SafeTensorsLoader::parse_shard_metadata(), and Shard().
| const uint8_t* Shard::tensor_data_block_ptr = nullptr |
Pointer to the start of the tensor data block.
Definition at line 71 of file safetensors_loader.h.
Referenced by get_tensor_raw_data(), and Shard().