]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
convert-hf : change assert to exception (#8015)
author0xspringtime <redacted>
Sat, 22 Jun 2024 13:37:41 +0000 (09:37 -0400)
committerGitHub <redacted>
Sat, 22 Jun 2024 13:37:41 +0000 (15:37 +0200)
convert-hf-to-gguf.py

index a6751cc80e682a46f44dd067c178c62a6d44e31c..166e5ded2f90f50c9e5a3036dc77879d041a2413 100755 (executable)
@@ -967,7 +967,13 @@ class XverseModel(Model):
         from transformers import AutoTokenizer
         tokenizer = AutoTokenizer.from_pretrained(dir_model)
         vocab_size = hparams.get("vocab_size", len(tokenizer.vocab))
-        assert max(tokenizer.vocab.values()) < vocab_size
+        # Since we are checking the maximum index, we need to ensure it's strictly less than vocab_size,
+        # because vocab_size is the count of items, and indexes start at 0.
+        max_vocab_index = max(tokenizer.get_vocab().values())
+        if max_vocab_index >= vocab_size:
+            raise ValueError("Vocabulary size exceeds expected maximum size.")
+
+
 
         reverse_vocab: dict[int, str] = {id_: encoded_tok for encoded_tok, id_ in tokenizer.vocab.items()}
         added_vocab = tokenizer.get_added_vocab()