From 402ea21406fa649b041676c195f1c7363b966548 Mon Sep 17 00:00:00 2001 From: Daniele Morotti <58258368+DanieleMorotti@users.noreply.github.com> Date: Fri, 15 Dec 2023 12:14:32 +0100 Subject: [PATCH] Bug fixed with n_ctx=0 If the n_ctx is set to 0 the code should use the maximum context length of the selected model, but it didn't work. There was a problem with the initialization of this parameter and a related problem with 'n_batch'. --- llama_cpp/llama.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 292378d50..583416598 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -923,6 +923,12 @@ def __init__( self._model = _LlamaModel( path_model=self.model_path, params=self.model_params, verbose=self.verbose ) + # Set the default value for the context and correct the batch + if n_ctx == 0: + n_ctx = self._model.n_ctx_train() + self.n_batch = min(n_ctx, n_batch) + self.context_params.n_ctx = self._model.n_ctx_train() + self.context_params.n_batch = self.n_batch self._ctx = _LlamaContext( model=self._model,