| 2469 | } |
| 2470 | |
| 2471 | 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) { |
| 2472 | llama_file file(filepath, "wb"); |
| 2473 | |
| 2474 | file.write_u32(LLAMA_STATE_SEQ_MAGIC); |
| 2475 | file.write_u32(LLAMA_STATE_SEQ_VERSION); |
| 2476 | |
| 2477 | // save the prompt |
| 2478 | file.write_u32((uint32_t) n_token_count); |
| 2479 | file.write_raw(tokens, sizeof(llama_token) * n_token_count); |
| 2480 | |
| 2481 | // save the context state using stream saving |
| 2482 | llama_io_write_file io(&file); |
| 2483 | state_seq_write_data(io, seq_id, 0); |
| 2484 | |
| 2485 | const size_t res = file.tell(); |
| 2486 | GGML_ASSERT(res == sizeof(uint32_t) * 3 + sizeof(llama_token) * n_token_count + io.n_bytes()); |
| 2487 | |
| 2488 | return res; |
| 2489 | } |
| 2490 | |
| 2491 | size_t llama_context::state_write_data(llama_io_write_i & io) { |
| 2492 | LLAMA_LOG_DEBUG("%s: writing state\n", __func__); |
no test coverage detected