Added dynamic context size. This is perfect for servers running llama models as a service. #13295
+54
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The context size which is used to allocate the space for model execution and KV caches, cannot be modified once the model and context params are initialized. This can be bad for servers running models as the context sizes are bound to increase overtime.
With dynamic context size, there is no need to restart the servers once the context size exceeds.
Dynamic context size is achieved by modifying the size of n_ctx in cparams followed by resetting the previous memory to create new memory using
memory.reset(model.create_memory(params_mem, cparams));
.As new memory is created, the earlier context is deleted, the best way to save and load the state to preserve.
I will add load state feature as a default while performing this operation in next commit.