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

Function gguf_write_out

ggml/src/gguf.cpp:1472–1508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1470
1471template <typename writer_t>
1472static void gguf_write_out(const struct gguf_context * ctx, writer_t & gw, bool only_meta) {
1473 const int64_t n_kv = gguf_get_n_kv(ctx);
1474 const int64_t n_tensors = gguf_get_n_tensors(ctx);
1475
1476 // write header
1477 gw.write(GGUF_MAGIC[0]);
1478 gw.write(GGUF_MAGIC[1]);
1479 gw.write(GGUF_MAGIC[2]);
1480 gw.write(GGUF_MAGIC[3]);
1481 gw.write(ctx->version);
1482 gw.write(n_tensors);
1483 gw.write(n_kv);
1484
1485 // write key-value pairs
1486 for (int64_t i = 0; i < n_kv; ++i) {
1487 gw.write(ctx->kv[i]);
1488 }
1489
1490 // write tensor info
1491 for (int64_t i = 0; i < n_tensors; ++i) {
1492 gw.write_tensor_meta(ctx->info[i]);
1493 }
1494
1495 // we require the data section to be aligned
1496 gw.pad(ctx->alignment);
1497
1498 if (only_meta) {
1499 return;
1500 }
1501
1502 const size_t offset_data = gw.written_bytes;
1503
1504 // write tensor data
1505 for (int64_t i = 0; i < n_tensors; ++i) {
1506 gw.write_tensor_data(ctx->info[i], offset_data, ctx->alignment);
1507 }
1508}
1509
1510void gguf_write_to_buf(const struct gguf_context * ctx, std::vector<int8_t> & buf, bool only_meta) {
1511 gguf_writer_buf gw(buf);

Callers 2

gguf_write_to_bufFunction · 0.85
gguf_write_to_file_ptrFunction · 0.85

Calls 6

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

Tested by

no test coverage detected