-
Notifications
You must be signed in to change notification settings - Fork 100
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
Support Closing Sessions to Free Resources and Fix Issue #140" #141
base: main
Are you sure you want to change the base?
Conversation
cdhermann
commented
Jan 5, 2025
- Allows for closing certain session and therefore freeing the associated resources
- Fixes A lot of temp files are created but not deleted #140
model.getConfig().workingDirectory().get().toString(), | ||
pageCtx.session.toString() + "-" + pageId + ".page" | ||
).toFile(); | ||
rafFile.deleteOnExit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the case where you want to keep the cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must admit, I was focused on my specific use case, which involved numerous short-lived sessions that rapidly consumed all available disk space. I hadn’t considered restarting the application and resuming a session using its session ID.
Thanks for this. I wonder if the KV cache should be marked ephemeral when the model is created? Otherwise you can never keep the cache around long term (say you want to store threads of different conversations to go back to) |
Perhaps it's possible to achieve the best of both worlds: short-lived sessions that can be deleted and long-lived sessions that can be resumed by explicitly modeling the concept of a session. E.g. something like that /**
* Represents a session with a unique ID and persistence setting.
*/
public record Session(UUID sessionId, boolean persistent) {
/**
* Creates a persistent session with the provided session ID.
*
* <p>
* This session can be resumed even after the program exits.
* </p>
*/
public Session(UUID sessionId) {
this(sessionId, true);
}
/**
* Creates an ephemeral session with a new random session ID.
*
* <p>
* All resources are freed when the session is closed.
* This session cannot be resumed later.
* </p>
*/
public Session() {
this(UUID.randomUUID(), false);
}
}
....
AbstractModel model = ModelSupport.loadModel(localModelPath, workingMemory, workingQuantization);
// Creates an ephemeral session
Session session = new Session();
Generator.Response response = model.generate(session, ctx, 0.1f, 1024, (s, f) -> {
// Handle generation callback
});
/*
* Closes the the given session
* - Persistent sessions: No deletion of the temporary files
* - Ephemeral sessions: Deletes temporary files and marks them for deletion on exit
*/
model.close(session); |
Since Jlama provides LangChain4j integration, their expectations regarding this integration should also be considered. Based on my understanding of the LangChain4j chat memory documentation, there is no default persistence. However, I must admit that I haven’t explored the LangChain4j integration and its usage in depth yet. |
Correct, in this case it would always be ephemeral. But for Jlama I want to handle stored sessions. I can take a crack at fixing this based on your PR! |