From f1c631dc533706ed3caffe19b3c944f1665e62a4 Mon Sep 17 00:00:00 2001 From: Daniele Morotti <58258368+DanieleMorotti@users.noreply.github.com> Date: Sun, 17 Dec 2023 00:59:50 +0100 Subject: [PATCH] Bug fixed with n_ctx=0 (#1015) 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 d5cf401..15307ab 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -923,6 +923,12 @@ class Llama: 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,