Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Make InferenceSession Clone-able #48

Closed
Tracked by #81
philpax opened this issue Mar 21, 2023 · 1 comment
Closed
Tracked by #81

Make InferenceSession Clone-able #48

philpax opened this issue Mar 21, 2023 · 1 comment
Assignees
Labels
issue:enhancement New feature or request

Comments

@philpax
Copy link
Collaborator

philpax commented Mar 21, 2023

In one of my test applications, I use an InferenceSession to load in a prompt that I later reuse. However, I realised while doing this that you can't actually clone an InferenceSession in memory (and I think it should be possible?), so I had to serialize the session to a Vec<u8> and rehydrate it when I needed to infer from it.

I think this should be easy enough to fix, but we should check that there aren't any weird assumptions that we're violating if we do so. (I assume this would also allocate another ctx, but that should be fine)

@setzer22
Copy link
Collaborator

setzer22 commented Mar 21, 2023

Yup, I don't see any problems here (other than this just hasn't been implemented yet) 😄

This might require some careful handling of the underlying ggml context. Make sure a new context is allocated and any tensor data is copied over to the new context. For this, you might need some C-like pointer fiddling and maybe expose a few more GGML functions. Simply cloning the pointers would result in the wrong behavior, and most likely UB. But from your question I think you already accounted for that 👍

@philpax philpax added the issue:enhancement New feature or request label Mar 24, 2023
@philpax philpax mentioned this issue Mar 26, 2023
7 tasks
@philpax philpax self-assigned this Mar 27, 2023
@philpax philpax closed this as completed in 086e7db Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue:enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants