Skip to content

Commit

Permalink
fixing an issue with tokenizer vocab_size mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCreator committed Aug 21, 2023
1 parent 5191ada commit 5b8320b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RWKV-v4neo/src/dataflow/trie_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def find_longest(self, key:bytes, idx:int=0):

class TRIE_TOKENIZER():
def __init__(self, file_name):
self.vocab_size = 65525
self.vocab_size = 65529
self.idx2token = {}
sorted = [] # must be already sorted
with open(file_name, "r", encoding="utf-8") as f:
Expand Down
11 changes: 9 additions & 2 deletions RWKV-v5/src/dataflow/trie_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def find_longest(self, key:bytes, idx:int=0):

class TRIE_TOKENIZER():
def __init__(self, file_name):
self.vocab_size = 65525
self.vocab_size = 65529
self.idx2token = {}
sorted = [] # must be already sorted
with open(file_name, "r", encoding="utf-8") as f:
Expand Down Expand Up @@ -130,7 +130,14 @@ def get_world_tokenizer():

# Provide a global function for the world tokenizer
def world_tokenizer_encode(src):
return get_world_tokenizer().encode(src)
res = get_world_tokenizer().encode(src)

# Check the result for any null, < 0, or > 65525
for i in res:
if i < 0 or i > 65529:
raise Exception(f"world_tokenizer_encode: Invalid token {i} from: {src}")

return res

########################################################################################################
# Tensor specific tokenizer
Expand Down

0 comments on commit 5b8320b

Please sign in to comment.