misc: Remove unnecessary metadata lookups (#1448)

Special tokens are already mapped from metadata by llama.cpp
This commit is contained in:
Sigbjørn Skjæret 2024-05-14 15:44:09 +02:00 committed by GitHub
parent 4b54f79330
commit 389e09c2f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -410,8 +410,8 @@ class Llama:
if self.verbose: if self.verbose:
print(f"Model metadata: {self.metadata}", file=sys.stderr) print(f"Model metadata: {self.metadata}", file=sys.stderr)
eos_token_id = int(self.metadata.get("tokenizer.ggml.eos_token_id", self.token_eos())) eos_token_id = self.token_eos()
bos_token_id = int(self.metadata.get("tokenizer.ggml.bos_token_id", self.token_bos())) bos_token_id = self.token_bos()
eos_token = self._model.token_get_text(eos_token_id) eos_token = self._model.token_get_text(eos_token_id)
bos_token = self._model.token_get_text(bos_token_id) bos_token = self._model.token_get_text(bos_token_id)
@ -961,9 +961,9 @@ class Llama:
completion_id: str = f"cmpl-{str(uuid.uuid4())}" completion_id: str = f"cmpl-{str(uuid.uuid4())}"
created: int = int(time.time()) created: int = int(time.time())
prefix_token_id: int = int(self.metadata.get("tokenizer.ggml.prefix_token_id", self._model.token_prefix())) prefix_token_id: int = self._model.token_prefix()
middle_token_id: int = int(self.metadata.get("tokenizer.ggml.middle_token_id", self._model.token_middle())) middle_token_id: int = self._model.token_middle()
suffix_token_id: int = int(self.metadata.get("tokenizer.ggml.suffix_token_id", self._model.token_suffix())) suffix_token_id: int = self._model.token_suffix()
# If prompt is empty, initialize completion with BOS token to avoid # If prompt is empty, initialize completion with BOS token to avoid
# detokenization including a space at the beginning of the completion # detokenization including a space at the beginning of the completion
completion_tokens: List[int] = [] if len(prompt) > 0 else [self.token_bos()] completion_tokens: List[int] = [] if len(prompt) > 0 else [self.token_bos()]