Skip to content

Reducing the time needed to reload a piece of text into the model by caching the state #202

Closed

Description

@niansa

Hey!

Is it possible to add a way of dumping the current state into a file, so it can then be reloaded later? This would avoid the time needed to reload a long prompt over and over again.

Thanks
Niansa

Activity

  1. bitRAKE commented on Mar 16, 2023

    @bitRAKE
    Contributor

    #174 also asked this, or do you have something else in mind?

  2. added
    duplicateThis issue or pull request already exists
    on Mar 16, 2023
  3. jart commented on Mar 16, 2023

    @jart
    Contributor

    Thank you for using llama.cpp and thank you for sharing your feature request! You'll be excited to hear that what you're requesting is my top priority right now. I'm using #91 as the best place to discuss this, since the solution will entail using mmap(). Everyone is welcome to participate in helping us find the best solution. I believe mmap() will reduce startup latency to effectively zero, for everyone, and it'll work on nearly every platform on earth, including Windows, which has a nearly equivalent API.

  4. j-f1 commented on Mar 16, 2023

    @j-f1
    Contributor

    I think this is a different issue — that one is about changing how the model is loaded, this one is about reducing the time needed to reload a piece of text into the model by caching the state.

  5. jart commented on Mar 16, 2023

    @jart
    Contributor

    As you wish. Re-opening.

  6. reopened this on Mar 16, 2023
  7. added
    enhancementNew feature or request
    and removed
    duplicateThis issue or pull request already exists
    on Mar 16, 2023
  8. niansa commented on Mar 16, 2023

    @niansa
    ContributorAuthor

    #174 also asked this, or do you have something else in mind?

    Basically yes, except that interactive user input and generated results should be saved too. So basically you can save and stop and just continue where the model/you've left off later or on another PC.

  9. bitRAKE commented on Mar 16, 2023

    @bitRAKE
    Contributor

    I can't find it now, but @ggerganov said save/restore of the k&v tensors would preserve the state, iirc.
    https://github.com/ggerganov/llama.cpp/blob/721311070e31464ac12bef9a4444093eb3eaebf7/main.cpp#L79-L82

  10. jarcen commented on Mar 16, 2023

    @jarcen

    @bitRAKE Yes, those are transformer's hidden state, preserving them is sufficient. Now, the question is how to edit them properly.
    I'm also interested in removing n first elements to deal with context memory filling up.

  11. changed the title [-]"Saving" current state?[/-] [+]Reducing the time needed to reload a piece of text into the model by caching the state[/+] on Mar 17, 2023
  12. sgoll commented on Mar 30, 2023

    @sgoll

    This issue is a duplicate of #64, isn't it? Since llama-rs did essentially the same thing, first in rustformers/llm#14, then with a slightly different interface in rustformers/llm#38, this is definitely feasible and would be really useful.

    May I suggest to close this issue and continue discussion in #64?

    One use case that would benefit greatly from session (KV) caching is story generation: start with an initial prompt and then continue down the most promising alternatives that are being generated.

  13. ggerganov commented on Mar 30, 2023

    @ggerganov
    Member

    Yes, it is the same

  14. added a commit that references this issue on Jun 9, 2026
    32b1f19
  15. added a commit that references this issue on Jul 21, 2026
  16. added 2 commits that reference this issue on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions