Skip to content

fix: converter hf now handles byte characters. Closes #188 #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion converter/convert-tokenizer-hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ def resolveLlamaTokenizer(self):
t = processor.id_to_piece(i)
s = processor.get_score(i)
t = t.replace('▁', ' ') # sentencepiece uses this character as whitespace
b = t.encode('utf-8')
# Check for byte characters
if len(t) == 6 and t.startswith('<0x') and t.endswith('>'):
# For example, "<0x0A>"" is a newline character
b = bytearray.fromhex(t[3:-1])
else:
b = t.encode('utf-8')
self.tokens.append(b)
self.scores.append(s)

Expand Down