Skip to content

Commit

Permalink
convert-hf : change assert to exception (#8015)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xspringtime committed Jun 22, 2024
1 parent 5b48cd5 commit 3aa184a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion convert-hf-to-gguf.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,13 @@ def set_vocab(self):
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()
Expand Down

0 comments on commit 3aa184a

Please sign in to comment.