| 1732 | } |
| 1733 | |
| 1734 | size_t llama_context::state_seq_save_file(llama_seq_id seq_id, const char * filepath, const llama_token * tokens, size_t n_token_count) { |
| 1735 | llama_file file(filepath, "wb"); |
| 1736 | |
| 1737 | file.write_u32(LLAMA_STATE_SEQ_MAGIC); |
| 1738 | file.write_u32(LLAMA_STATE_SEQ_VERSION); |
| 1739 | |
| 1740 | // save the prompt |
| 1741 | file.write_u32((uint32_t) n_token_count); |
| 1742 | file.write_raw(tokens, sizeof(llama_token) * n_token_count); |
| 1743 | |
| 1744 | // save the context state using stream saving |
| 1745 | llama_io_write_file io(&file); |
| 1746 | state_seq_write_data(io, seq_id); |
| 1747 | |
| 1748 | const size_t res = file.tell(); |
| 1749 | GGML_ASSERT(res == sizeof(uint32_t) * 3 + sizeof(llama_token) * n_token_count + io.n_bytes()); |
| 1750 | |
| 1751 | return res; |
| 1752 | } |
| 1753 | |
| 1754 | size_t llama_context::state_write_data(llama_io_write_i & io) { |
| 1755 | LLAMA_LOG_DEBUG("%s: writing state\n", __func__); |
no test coverage detected