MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / gguf_parse_meta

Function gguf_parse_meta

tests/gguf-model-data.cpp:225–371  ·  view source on GitHub ↗

Follows the same header -> KV -> tensor parsing sequence as gguf() huggingface/gguf

Source from the content-addressed store, hash-verified

223
224// Follows the same header -> KV -> tensor parsing sequence as gguf() huggingface/gguf
225static std::optional<gguf_remote_model> gguf_parse_meta(const std::vector<char> & buf) {
226 gguf_buf_reader r(buf);
227
228 // Header: magic(4) + version(4) + tensor_count(8) + kv_count(8) = 24 bytes minimum
229 uint32_t magic_raw;
230 if (!r.read_val(magic_raw)) {
231 return std::nullopt;
232 }
233 if (memcmp(&magic_raw, "GGUF", 4) != 0) {
234 fprintf(stderr, "gguf_parse_meta: invalid magic\n");
235 return std::nullopt;
236 }
237
238 uint32_t version;
239 if (!r.read_val(version)) {
240 return std::nullopt;
241 }
242 if (version < 2 || version > 3) {
243 fprintf(stderr, "gguf_parse_meta: unsupported version %u\n", version);
244 return std::nullopt;
245 }
246
247 int64_t tensor_count_raw;
248 int64_t kv_count_raw;
249 if (!r.read_val(tensor_count_raw)) {
250 return std::nullopt;
251 }
252 if (!r.read_val(kv_count_raw)) {
253 return std::nullopt;
254 }
255
256 uint64_t tensor_count = (uint64_t)tensor_count_raw;
257 uint64_t kv_count = (uint64_t)kv_count_raw;
258
259 gguf_remote_model model;
260
261 std::string arch_prefix;
262
263 // Parse KV pairs
264 for (uint64_t i = 0; i < kv_count; i++) {
265 std::string key;
266 if (!r.read_str(key)) {
267 return std::nullopt;
268 }
269
270 int32_t vtype;
271 if (!r.read_val(vtype)) {
272 return std::nullopt;
273 }
274
275 if (key == "general.architecture" && vtype == GGUF_TYPE_STRING) {
276 if (!r.read_str(model.architecture)) {
277 return std::nullopt;
278 }
279 arch_prefix = model.architecture + ".";
280 continue;
281 }
282

Callers 2

fetch_and_parseFunction · 0.85
fetch_or_cachedFunction · 0.85

Calls 6

gguf_read_uint32_valFunction · 0.85
gguf_skip_valueFunction · 0.85
read_valMethod · 0.80
read_strMethod · 0.80
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected