MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / gguf_write_out

Function gguf_write_out

subprojects/llama.cpp/ggml/src/gguf.cpp:1366–1402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1364
1365template <typename writer_t>
1366static void gguf_write_out(const struct gguf_context * ctx, writer_t & gw, bool only_meta) {
1367 const int64_t n_kv = gguf_get_n_kv(ctx);
1368 const int64_t n_tensors = gguf_get_n_tensors(ctx);
1369
1370 // write header
1371 gw.write(GGUF_MAGIC[0]);
1372 gw.write(GGUF_MAGIC[1]);
1373 gw.write(GGUF_MAGIC[2]);
1374 gw.write(GGUF_MAGIC[3]);
1375 gw.write(ctx->version);
1376 gw.write(n_tensors);
1377 gw.write(n_kv);
1378
1379 // write key-value pairs
1380 for (int64_t i = 0; i < n_kv; ++i) {
1381 gw.write(ctx->kv[i]);
1382 }
1383
1384 // write tensor info
1385 for (int64_t i = 0; i < n_tensors; ++i) {
1386 gw.write_tensor_meta(ctx->info[i]);
1387 }
1388
1389 // we require the data section to be aligned
1390 gw.pad(ctx->alignment);
1391
1392 if (only_meta) {
1393 return;
1394 }
1395
1396 const size_t offset_data = gw.written_bytes;
1397
1398 // write tensor data
1399 for (int64_t i = 0; i < n_tensors; ++i) {
1400 gw.write_tensor_data(ctx->info[i], offset_data, ctx->alignment);
1401 }
1402}
1403
1404void gguf_write_to_buf(const struct gguf_context * ctx, std::vector<int8_t> & buf, bool only_meta) {
1405 gguf_writer_buf gw(buf);

Callers 2

gguf_write_to_bufFunction · 0.85
gguf_write_to_fileFunction · 0.85

Calls 6

gguf_get_n_kvFunction · 0.85
gguf_get_n_tensorsFunction · 0.85
write_tensor_metaMethod · 0.80
writeMethod · 0.65
padMethod · 0.45
write_tensor_dataMethod · 0.45

Tested by

no test coverage detected