Skip to content

Commit 2b2afad

Browse files
o7siCISC
andauthored
convert : fix encoding of WPM vocab for BERT models (ggml-org#18500)
* convert: avoid token collision when stripping ## prefix * convert: use token types for BERT special tokens check * Update convert_hf_to_gguf.py Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
1 parent f4f5019 commit 2b2afad

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

convert_hf_to_gguf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,13 +5287,14 @@ def set_vocab(self):
52875287
self.gguf_writer.add_token_type_count(self.hparams.get("type_vocab_size", 1))
52885288

52895289
# convert to phantom space vocab
5290-
def phantom(tok):
5291-
if tok.startswith("[") and tok.endswith("]"):
5290+
def phantom(tok, toktype):
5291+
if toktype == gguf.TokenType.CONTROL:
52925292
return tok
52935293
if tok.startswith("##"):
52945294
return tok[2:]
52955295
return "\u2581" + tok
5296-
tokens = list(map(phantom, tokens))
5296+
assert len(tokens) == len(toktypes)
5297+
tokens = list(map(phantom, tokens, toktypes))
52975298

52985299
# add vocab to gguf
52995300
self.gguf_writer.add_tokenizer_model("bert")

0 commit comments

Comments
 (0)