Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Save internal state to disk #827

Closed
ngxson opened this issue Apr 7, 2023 · 2 comments
Closed

[Question] Save internal state to disk #827

ngxson opened this issue Apr 7, 2023 · 2 comments

Comments

@ngxson
Copy link
Collaborator

ngxson commented Apr 7, 2023

Hi,

Thanks for your hard work on this project.

I've been playing with the code since few days. I'm trying to find a way to save the internal state of the model (or its context) that can be reused later. But until now it still doesn't work. I don't know if I'm missing something (I'm not good at all when talking about machine learning, I'm working more on system development.)

Here what I tried (inspired from code of main.cpp)

  1. Load the model using llama_init_from_file
  2. Call llama_eval on a prompt, for example " Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n"
  3. Call llama_eval on a instruction, for example "### Instruction: Hi, I'm Xuan Son."
  4. Save the kv_self buffer using llama_get_kv_cache => Expected: the saved data contains information about my name
  5. Ask for what is my name?, the model correctly response that my name is Xuan Son
  6. Exit the program
  7. Re-run the program
  8. Reload llama_init_from_file then kv_cache using llama_set_kv_cache => Expected: the loaded data contains information about my name
  9. Ask for what is my name?, the model responses with nonsense words just love with 12 want some you, he saids
@chrfalch
Copy link
Contributor

chrfalch commented Apr 7, 2023

You need to save the n_past value and (if used) the n_tokens_past (used for repeat penalty calculations). You can see an example here: #730 (comment)

@ngxson
Copy link
Collaborator Author

ngxson commented Apr 8, 2023

I forgot to save last_n (or n_past). Thank you for pointing it out!

It works like a charm now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants