From 389e09c2f55a9ac659fd64fada56cf750a7a378b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Tue, 14 May 2024 15:44:09 +0200 Subject: [PATCH] misc: Remove unnecessary metadata lookups (#1448) Special tokens are already mapped from metadata by llama.cpp --- llama_cpp/llama.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 4212669eb..281ee7918 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -410,8 +410,8 @@ def __init__( if self.verbose: print(f"Model metadata: {self.metadata}", file=sys.stderr) - eos_token_id = int(self.metadata.get("tokenizer.ggml.eos_token_id", self.token_eos())) - bos_token_id = int(self.metadata.get("tokenizer.ggml.bos_token_id", self.token_bos())) + eos_token_id = self.token_eos() + bos_token_id = self.token_bos() eos_token = self._model.token_get_text(eos_token_id) bos_token = self._model.token_get_text(bos_token_id) @@ -961,9 +961,9 @@ def _create_completion( completion_id: str = f"cmpl-{str(uuid.uuid4())}" created: int = int(time.time()) - prefix_token_id: int = int(self.metadata.get("tokenizer.ggml.prefix_token_id", self._model.token_prefix())) - middle_token_id: int = int(self.metadata.get("tokenizer.ggml.middle_token_id", self._model.token_middle())) - suffix_token_id: int = int(self.metadata.get("tokenizer.ggml.suffix_token_id", self._model.token_suffix())) + prefix_token_id: int = self._model.token_prefix() + middle_token_id: int = self._model.token_middle() + suffix_token_id: int = self._model.token_suffix() # If prompt is empty, initialize completion with BOS token to avoid # detokenization including a space at the beginning of the completion completion_tokens: List[int] = [] if len(prompt) > 0 else [self.token_bos()]