| 1830 | } |
| 1831 | |
| 1832 | size_t llama_context::state_read_data(llama_io_read_i & io) { |
| 1833 | LLAMA_LOG_DEBUG("%s: reading state\n", __func__); |
| 1834 | |
| 1835 | // read model info |
| 1836 | { |
| 1837 | LLAMA_LOG_DEBUG("%s: - reading model info\n", __func__); |
| 1838 | |
| 1839 | const std::string cur_arch_str = llm_arch_name(model.arch); |
| 1840 | |
| 1841 | std::string arch_str; |
| 1842 | io.read_string(arch_str); |
| 1843 | if (cur_arch_str != arch_str) { |
| 1844 | throw std::runtime_error(format("wrong model arch: '%s' instead of '%s'", arch_str.c_str(), cur_arch_str.c_str())); |
| 1845 | } |
| 1846 | // TODO: add more info which needs to be identical but which is not verified otherwise |
| 1847 | } |
| 1848 | |
| 1849 | // read output ids |
| 1850 | { |
| 1851 | LLAMA_LOG_DEBUG("%s: - reading output ids\n", __func__); |
| 1852 | |
| 1853 | auto n_outputs = this->n_outputs; |
| 1854 | io.read_to(&n_outputs, sizeof(n_outputs)); |
| 1855 | |
| 1856 | if (n_outputs > output_reserve(n_outputs)) { |
| 1857 | throw std::runtime_error("could not reserve outputs"); |
| 1858 | } |
| 1859 | |
| 1860 | std::vector<int32_t> output_pos; |
| 1861 | |
| 1862 | if (n_outputs) { |
| 1863 | output_pos.resize(n_outputs); |
| 1864 | io.read_to(output_pos.data(), n_outputs * sizeof(int32_t)); |
| 1865 | |
| 1866 | for (int32_t i = 0; i < (int32_t) output_pos.size(); ++i) { |
| 1867 | int32_t id = output_pos[i]; |
| 1868 | if ((uint32_t) id >= n_batch()) { |
| 1869 | throw std::runtime_error(format("invalid output id, %d does not fit in batch size of %u", id, n_batch())); |
| 1870 | } |
| 1871 | this->output_ids[id] = i; |
| 1872 | } |
| 1873 | |
| 1874 | this->n_outputs = n_outputs; |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | // read logits |
| 1879 | { |
| 1880 | LLAMA_LOG_DEBUG("%s: - reading logits\n", __func__); |
| 1881 | |
| 1882 | uint64_t logits_size; |
| 1883 | io.read_to(&logits_size, sizeof(logits_size)); |
| 1884 | |
| 1885 | if (this->logits_size < logits_size) { |
| 1886 | throw std::runtime_error("logits buffer too small"); |
| 1887 | } |
| 1888 | |
| 1889 | if (logits_size) { |
nothing calls this directly
no test coverage detected