fixed save load state example

This commit is contained in:
l3utterfly 2023-08-03 17:21:55 +08:00
parent 81f347c19d
commit 987387859b

View file

@ -1,5 +1,6 @@
#include "common.h" #include "common.h"
#include "llama.h" #include "llama.h"
#include "llama-util.h"
#include "build-info.h" #include "build-info.h"
#include <vector> #include <vector>
@ -66,10 +67,9 @@ int main(int argc, char ** argv) {
// Save state (rng, logits, embedding and kv_cache) to file // Save state (rng, logits, embedding and kv_cache) to file
{ {
FILE *fp_write = fopen("dump_state.bin", "wb"); llama_file file("dump_state.bin", "wb");
llama_copy_state_data(ctx, state_mem); // could also copy directly to memory mapped file llama_data_file_context data_ctx(&file);
fwrite(state_mem, 1, state_size, fp_write); llama_copy_state_data(ctx, &data_ctx); // can also copy to memory buffer
fclose(fp_write);
} }
// save state (last tokens) // save state (last tokens)