From ac4f0d875a23ad85829b8e39ae15c7fb1c8b521d Mon Sep 17 00:00:00 2001 From: m-from-space <76992439+m-from-space@users.noreply.github.com> Date: Wed, 16 Jul 2025 10:53:59 +0200 Subject: [PATCH] Update llama.py Set a random initial seed if using -1 as the seed argument (like stated in the API reference) --- llama_cpp/llama.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 2e93670e6..2124fcdaa 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -304,7 +304,11 @@ def __init__( self.n_threads_batch = n_threads_batch or multiprocessing.cpu_count() # Used by the sampler - self._seed = seed or llama_cpp.LLAMA_DEFAULT_SEED + if seed == -1: + # set a random seed + self._seed = random.randint(0, 2 ** 32) + else: + self._seed = seed or llama_cpp.LLAMA_DEFAULT_SEED # Context Params self.context_params = llama_cpp.llama_context_default_params()