convert : fix broken sentencepiece vocab (#14416)

This commit is contained in:
Sigbjørn Skjæret 2025-06-27 10:42:19 +02:00 committed by GitHub
parent 8846aace49
commit f667f1e624
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -936,7 +936,11 @@ class TextModel(ModelBase):
scores: list[float] = [-10000.0] * vocab_size
toktypes: list[int] = [SentencePieceTokenTypes.UNUSED] * vocab_size
for token_id in range(vocab_size):
for token_id in range(tokenizer.vocab_size()):
if token_id >= vocab_size:
logger.warning(f'ignore tokens from {token_id}: id is out of range, max={vocab_size - 1}')
break
piece = tokenizer.IdToPiece(token_id)
text = piece.encode("utf-8")
score = tokenizer.GetScore(token_id)
@ -951,10 +955,6 @@ class TextModel(ModelBase):
elif tokenizer.IsByte(token_id):
toktype = SentencePieceTokenTypes.BYTE
if token_id >= vocab_size:
logger.warning(f'ignore tokens from {token_id}: id is out of range, max={vocab_size - 1}')
break
tokens[token_id] = text
scores[token_id] = score
toktypes[token_id] = toktype