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

llama : fix session load / save #1263

Merged
merged 1 commit into from
May 1, 2023
Merged

llama : fix session load / save #1263

merged 1 commit into from
May 1, 2023

Conversation

ggerganov
Copy link
Member

@ggerganov ggerganov commented May 1, 2023

  • Moved the llama_load_session_file and llama_save_session_file definitions in the correct place in llama.cpp
  • Fixed an off-by-one bug during session load
  • Minor style refactoring

🤖 Generated by Copilot at c0335b5

Summary

🐛🗂️♻️

This pull request enhances the llama library and its example program. It implements a new session file format for llama and updates the llama.h and llama.cpp files accordingly. It also improves the code quality and functionality of the main.cpp example.

main.cpp polished
Llama sessions have new format
Autumn leaves old code

Walkthrough

  • Add new functions llama_load_session_file and llama_save_session_file to handle session data with a new file format and more error checking (link, link)
  • Remove old functions llama_load_session_file and llama_save_session_file that used a different file format and had less error handling (link)
  • Define new macros LLAMA_SESSION_MAGIC and LLAMA_SESSION_VERSION for the session file format and change existing macros LLAMA_FILE_MAGIC and LLAMA_FILE_MAGIC_UNVERSIONED to use character literals (link)
  • Fix a bug in examples/main/main.cpp where the number of generated tokens was not counted correctly and could cause an infinite loop or a wrong output (link)
  • Change the error handling and the message in examples/main/main.cpp when loading a session file, and use a boolean check instead of the function return value (link)
  • Add single quotes around the path_session variable in the message in examples/main/main.cpp for consistency and clarity (link)
  • Add a space between the type cast and the variable name in examples/main/main.cpp for coding style and readability (link)
  • Remove the REVIEW comment in examples/main/main.cpp as the decision to stop saving the session when the context is exhausted seems final (link)

@ggerganov ggerganov requested a review from ivanstepanovftw May 1, 2023 08:08
@@ -355,6 +354,7 @@ int main(int argc, char ** argv) {
n_session_consumed++;

if (n_session_consumed >= (int) session_tokens.size()) {
++i;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the "off-by-one" bug causing different outputs, observed in #1257

Copy link
Collaborator

@ivanstepanovftw ivanstepanovftw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that prompt cache outputs are the same

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

Successfully merging this pull request may close these issues.

2 participants