| 2567 | } |
| 2568 | |
| 2569 | size_t llama_context::state_read_data(llama_io_read_i & io) { |
| 2570 | LLAMA_LOG_DEBUG("%s: reading state\n", __func__); |
| 2571 | |
| 2572 | // read model info |
| 2573 | { |
| 2574 | LLAMA_LOG_DEBUG("%s: - reading model info\n", __func__); |
| 2575 | |
| 2576 | const std::string cur_arch_str = llm_arch_name(model.arch); |
| 2577 | |
| 2578 | std::string arch_str; |
| 2579 | io.read_string(arch_str); |
| 2580 | if (cur_arch_str != arch_str) { |
| 2581 | throw std::runtime_error(format("wrong model arch: '%s' instead of '%s'", arch_str.c_str(), cur_arch_str.c_str())); |
| 2582 | } |
| 2583 | // TODO: add more info which needs to be identical but which is not verified otherwise |
| 2584 | } |
| 2585 | |
| 2586 | // read output ids |
| 2587 | { |
| 2588 | LLAMA_LOG_DEBUG("%s: - reading output ids\n", __func__); |
| 2589 | |
| 2590 | auto n_outputs = this->n_outputs; |
| 2591 | io.read_to(&n_outputs, sizeof(n_outputs)); |
| 2592 | |
| 2593 | if (n_outputs > output_reserve(n_outputs)) { |
| 2594 | throw std::runtime_error("could not reserve outputs"); |
| 2595 | } |
| 2596 | |
| 2597 | std::vector<int32_t> output_pos; |
| 2598 | |
| 2599 | if (n_outputs) { |
| 2600 | output_pos.resize(n_outputs); |
| 2601 | io.read_to(output_pos.data(), n_outputs * sizeof(int32_t)); |
| 2602 | |
| 2603 | for (int32_t i = 0; i < (int32_t) output_pos.size(); ++i) { |
| 2604 | int32_t id = output_pos[i]; |
| 2605 | if ((uint32_t) id >= n_batch()) { |
| 2606 | throw std::runtime_error(format("invalid output id, %d does not fit in batch size of %u", id, n_batch())); |
| 2607 | } |
| 2608 | this->output_ids[id] = i; |
| 2609 | } |
| 2610 | |
| 2611 | this->n_outputs = n_outputs; |
| 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | // read logits |
| 2616 | { |
| 2617 | LLAMA_LOG_DEBUG("%s: - reading logits\n", __func__); |
| 2618 | |
| 2619 | uint64_t logits_size; |
| 2620 | io.read_to(&logits_size, sizeof(logits_size)); |
| 2621 | |
| 2622 | if (this->logits_size < logits_size) { |
| 2623 | throw std::runtime_error("logits buffer too small"); |
| 2624 | } |
| 2625 | |
| 2626 | if (logits_size) { |
nothing calls this directly
no test coverage detected