TinyLlama.cpp 1.0
A lightweight C++ implementation of the TinyLlama language model
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
GGUFData Struct Reference

Complete representation of a GGUF file's contents. More...

#include <gguf_structs.h>

Collaboration diagram for GGUFData:
Collaboration graph

Public Member Functions

 GGUFData ()
 
 ~GGUFData ()
 
 GGUFData (const GGUFData &)=delete
 
GGUFDataoperator= (const GGUFData &)=delete
 
 GGUFData (GGUFData &&other) noexcept
 
GGUFDataoperator= (GGUFData &&other) noexcept
 

Public Attributes

GGUFHeader header
 
std::map< std::string, GGUFMetadataValuemetadata
 
std::vector< GGUFTensorInfotensor_infos
 
std::map< std::string, GGUFTensorInfotensor_infos_map
 
std::vector< std::string > tokenizer_tokens
 
std::vector< float > tokenizer_scores
 
std::vector< uint32_t > tokenizer_token_types
 
std::vector< std::string > tokenizer_merges
 
int file_descriptor = -1
 
void * mapped_tensor_data = nullptr
 
size_t mapped_tensor_data_size = 0
 
uint64_t data_alignment = 32
 
size_t offset_diff_for_mmap = 0
 
std::vector< uint8_t > tensor_data
 

Static Public Attributes

static const void * MMapFailure = MAP_FAILED
 

Detailed Description

Complete representation of a GGUF file's contents.

This structure contains all the data from a GGUF file, including header information, metadata, tensor information, and the actual tensor data. It also includes tokenizer-specific data that may be present in the file.

Definition at line 80 of file gguf_structs.h.

Constructor & Destructor Documentation

◆ GGUFData() [1/3]

GGUFData::GGUFData ( )
inline

Definition at line 111 of file gguf_structs.h.

uint64_t data_alignment
size_t offset_diff_for_mmap
size_t mapped_tensor_data_size
int file_descriptor
void * mapped_tensor_data

◆ ~GGUFData()

GGUFData::~GGUFData ( )
inline

Definition at line 117 of file gguf_structs.h.

117 {
118#ifndef _WIN32
119 if (mapped_tensor_data != nullptr && mapped_tensor_data != MMapFailure) { // MMapFailure will expand to MAP_FAILED
121 }
122 if (file_descriptor != -1) {
123 close(file_descriptor);
124 }
125 file_descriptor = -1;
126#else // _WIN32
127 if (mapped_tensor_data != nullptr) { // On Windows, MapViewOfFile returns NULL on failure
128 UnmapViewOfFile(mapped_tensor_data);
129 }
130 if (h_map_file != NULL) {
131 CloseHandle(h_map_file);
132 }
133 if (h_file != INVALID_HANDLE_VALUE) {
134 CloseHandle(h_file);
135 }
136 h_file = INVALID_HANDLE_VALUE;
137 h_map_file = NULL;
138#endif
139 mapped_tensor_data = nullptr; // Common for both
140 mapped_tensor_data_size = 0; // Common for both
141 offset_diff_for_mmap = 0; // Common for both
142 }
static const void * MMapFailure

References file_descriptor, mapped_tensor_data, mapped_tensor_data_size, MMapFailure, and offset_diff_for_mmap.

◆ GGUFData() [2/3]

GGUFData::GGUFData ( const GGUFData )
delete

◆ GGUFData() [3/3]

GGUFData::GGUFData ( GGUFData &&  other)
inlinenoexcept

Definition at line 149 of file gguf_structs.h.

150 : header(other.header)
151 , metadata(std::move(other.metadata))
152 , tensor_infos(std::move(other.tensor_infos))
153 , tensor_infos_map(std::move(other.tensor_infos_map))
154 , tokenizer_tokens(std::move(other.tokenizer_tokens))
155 , tokenizer_scores(std::move(other.tokenizer_scores))
157 , tokenizer_merges(std::move(other.tokenizer_merges))
158 // Platform-specific handles
159#ifndef _WIN32
161#else
162 , h_file(other.h_file)
163 , h_map_file(other.h_map_file)
164#endif
169 , tensor_data(std::move(other.tensor_data))
170 {
171 // Leave other in a valid but safe state (resources transferred)
172#ifndef _WIN32
173 other.file_descriptor = -1;
174#else
175 other.h_file = INVALID_HANDLE_VALUE;
176 other.h_map_file = NULL;
177#endif
178 other.mapped_tensor_data = nullptr;
179 other.mapped_tensor_data_size = 0;
180 other.offset_diff_for_mmap = 0;
181 }
std::vector< GGUFTensorInfo > tensor_infos
std::vector< std::string > tokenizer_tokens
std::vector< float > tokenizer_scores
std::vector< uint8_t > tensor_data
std::vector< std::string > tokenizer_merges
std::map< std::string, GGUFMetadataValue > metadata
std::map< std::string, GGUFTensorInfo > tensor_infos_map
GGUFHeader header
std::vector< uint32_t > tokenizer_token_types

Member Function Documentation

◆ operator=() [1/2]

GGUFData & GGUFData::operator= ( const GGUFData )
delete

◆ operator=() [2/2]

GGUFData & GGUFData::operator= ( GGUFData &&  other)
inlinenoexcept

Definition at line 183 of file gguf_structs.h.

183 {
184 if (this != &other) {
185 // Clean up existing resources first (using this object's current platform state)
186#ifndef _WIN32
187 if (mapped_tensor_data != nullptr && mapped_tensor_data != MMapFailure) { // MMapFailure will expand to MAP_FAILED
189 }
190 if (file_descriptor != -1) {
191 close(file_descriptor);
192 }
193#else // _WIN32
194 if (mapped_tensor_data != nullptr) {
195 UnmapViewOfFile(mapped_tensor_data);
196 }
197 if (h_map_file != NULL) {
198 CloseHandle(h_map_file);
199 }
200 if (h_file != INVALID_HANDLE_VALUE) {
201 CloseHandle(h_file);
202 }
203#endif
204
205 // Move data members
206 header = other.header;
207 metadata = std::move(other.metadata);
208 tensor_infos = std::move(other.tensor_infos);
209 tensor_infos_map = std::move(other.tensor_infos_map);
210 tokenizer_tokens = std::move(other.tokenizer_tokens);
211 tokenizer_scores = std::move(other.tokenizer_scores);
213 tokenizer_merges = std::move(other.tokenizer_merges);
214
215 // Move platform-specific handles and mmap data
216#ifndef _WIN32
218#else
219 h_file = other.h_file;
220 h_map_file = other.h_map_file;
221#endif
226 tensor_data = std::move(other.tensor_data);
227
228 // Leave other in a valid but safe state
229#ifndef _WIN32
230 other.file_descriptor = -1;
231#else
232 other.h_file = INVALID_HANDLE_VALUE;
233 other.h_map_file = NULL;
234#endif
235 other.mapped_tensor_data = nullptr;
236 other.mapped_tensor_data_size = 0;
237 other.offset_diff_for_mmap = 0;
238 }
239 return *this;
240 }

References data_alignment, file_descriptor, header, mapped_tensor_data, mapped_tensor_data_size, metadata, MMapFailure, offset_diff_for_mmap, tensor_data, tensor_infos, tensor_infos_map, tokenizer_merges, tokenizer_scores, tokenizer_token_types, and tokenizer_tokens.

Member Data Documentation

◆ data_alignment

uint64_t GGUFData::data_alignment = 32

Alignment requirement for tensor data

Definition at line 103 of file gguf_structs.h.

Referenced by load_gguf_meta(), and operator=().

◆ file_descriptor

int GGUFData::file_descriptor = -1

File descriptor for POSIX mmap

Definition at line 94 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), and ~GGUFData().

◆ header

GGUFHeader GGUFData::header

File header

Definition at line 81 of file gguf_structs.h.

Referenced by load_gguf_meta(), and operator=().

◆ mapped_tensor_data

void* GGUFData::mapped_tensor_data = nullptr

Pointer to memory-mapped tensor data block

Definition at line 101 of file gguf_structs.h.

Referenced by TinyLlamaModel::initialize_weights(), load_gguf_meta(), operator=(), and ~GGUFData().

◆ mapped_tensor_data_size

size_t GGUFData::mapped_tensor_data_size = 0

Size of the mapped tensor data block in bytes

Definition at line 102 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), and ~GGUFData().

◆ metadata

std::map<std::string, GGUFMetadataValue> GGUFData::metadata

Metadata key-value pairs

Definition at line 82 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), parse_model_config_from_gguf(), and Tokenizer::Tokenizer().

◆ MMapFailure

const void * GGUFData::MMapFailure = MAP_FAILED
static

POSIX mmap failure indicator - DECLARED here, DEFINED in .cpp

Definition at line 95 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), and ~GGUFData().

◆ offset_diff_for_mmap

size_t GGUFData::offset_diff_for_mmap = 0

Difference between aligned mmap offset and actual data start

Definition at line 104 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), and ~GGUFData().

◆ tensor_data

std::vector<uint8_t> GGUFData::tensor_data

Tensor data loaded into memory (non-mmap mode)

Definition at line 107 of file gguf_structs.h.

Referenced by TinyLlamaModel::initialize_weights(), load_gguf_meta(), and operator=().

◆ tensor_infos

std::vector<GGUFTensorInfo> GGUFData::tensor_infos

List of tensor information

Definition at line 83 of file gguf_structs.h.

Referenced by load_gguf_meta(), and operator=().

◆ tensor_infos_map

std::map<std::string, GGUFTensorInfo> GGUFData::tensor_infos_map

Map of tensor names to information

Definition at line 84 of file gguf_structs.h.

Referenced by load_gguf_meta(), and operator=().

◆ tokenizer_merges

std::vector<std::string> GGUFData::tokenizer_merges

BPE merge rules

Definition at line 90 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), parse_model_config_from_gguf(), and Tokenizer::Tokenizer().

◆ tokenizer_scores

std::vector<float> GGUFData::tokenizer_scores

Token scores for BPE

Definition at line 88 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), and Tokenizer::Tokenizer().

◆ tokenizer_token_types

std::vector<uint32_t> GGUFData::tokenizer_token_types

Token type information

Definition at line 89 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), and Tokenizer::Tokenizer().

◆ tokenizer_tokens

std::vector<std::string> GGUFData::tokenizer_tokens

Vocabulary tokens

Definition at line 87 of file gguf_structs.h.

Referenced by load_gguf_meta(), operator=(), and Tokenizer::Tokenizer().


The documentation for this struct was generated from the following files: