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

Method state_write_data

subprojects/llama.cpp/src/llama-context.cpp:2491–2567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2489}
2490
2491size_t llama_context::state_write_data(llama_io_write_i & io) {
2492 LLAMA_LOG_DEBUG("%s: writing state\n", __func__);
2493
2494 // write model info
2495 {
2496 LLAMA_LOG_DEBUG("%s: - writing model info\n", __func__);
2497
2498 const std::string arch_str = llm_arch_name(model.arch);
2499 io.write_string(arch_str);
2500 // TODO: add more model-specific info which should prevent loading the session file if not identical
2501 }
2502
2503 // write output ids
2504 {
2505 LLAMA_LOG_DEBUG("%s: - writing output ids\n", __func__);
2506
2507 const auto n_outputs = this->n_outputs;
2508 const auto & output_ids = this->output_ids;
2509
2510 std::vector<int32_t> w_output_pos;
2511
2512 w_output_pos.resize(n_outputs);
2513
2514 // build a more compact representation of the output ids
2515 for (size_t i = 0; i < n_batch(); ++i) {
2516 // map an output id to a position in the batch
2517 int64_t pos = output_ids[i];
2518 if (pos >= 0) {
2519 GGML_ASSERT(pos < n_outputs);
2520 w_output_pos[pos] = i;
2521 }
2522 }
2523
2524 io.write(&n_outputs, sizeof(n_outputs));
2525
2526 if (n_outputs) {
2527 io.write(w_output_pos.data(), n_outputs * sizeof(int32_t));
2528 }
2529 }
2530
2531 // [TAG_CONTEXT_STATE_LOGITS]
2532 // write logits
2533 {
2534 LLAMA_LOG_DEBUG("%s: - writing logits\n", __func__);
2535
2536 const uint64_t logits_size = std::min((uint64_t) this->logits_size, (uint64_t) n_outputs * model.vocab.n_tokens());
2537
2538 io.write(&logits_size, sizeof(logits_size));
2539
2540 if (logits_size) {
2541 io.write(logits, logits_size * sizeof(float));
2542 }
2543 }
2544
2545 // write embeddings
2546 {
2547 LLAMA_LOG_DEBUG("%s: - writing embeddings\n", __func__);
2548

Callers

nothing calls this directly

Calls 9

llm_arch_nameFunction · 0.85
minFunction · 0.85
write_stringMethod · 0.80
writeMethod · 0.65
resizeMethod · 0.45
dataMethod · 0.45
n_tokensMethod · 0.45
state_writeMethod · 0.45
n_bytesMethod · 0.45

Tested by

no test coverage detected