Skip to content

[llama] Add resegment post processing of tokenizer #2072

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

howard0su
Copy link
Collaborator

Try to adress #2023

@howard0su howard0su requested a review from slaren July 2, 2023 14:06
@howard0su
Copy link
Collaborator Author

@slaren can you give me some test cases?

Also, I rerun the test to see how many tokens would not tokenize to themselves. I got the different result than @vjeux.

@slaren
Copy link
Member

slaren commented Jul 2, 2023

I would suggest comparing the output with what sentepiecepiece produces. I don't know anything beyond what @vjeux commented.

@howard0su
Copy link
Collaborator Author

howard0su commented Jul 3, 2023

I read through the code. One thing which concerns me is this line in convert.py:
text = tokenizer.id_to_piece(i).replace("\u2581", " ").encode("utf-8")

when we replace "\u2581" with space, we lose some information.

give the original example in the related issue:
in SPM:

>>> encoder.encode("▁–")
[29871, 785]

in llama.cpp, token 785 is " ▁–" (there is a leading space). So llama cannot recognize this string is token 785. It will divide this into three chars as many other unicode chars are handling.

Need some insights from @ggerganov why we decide to do the replacement?

@mqy
Copy link
Contributor

mqy commented Jul 3, 2023

Need some insights from @ggerganov why we decide to do the replacement?

@howard0su FYI FIx parsing single-byte UTF-8 tokens by manually parsing the protobuf
Search u2581

TL;DR

@howard0su
Copy link
Collaborator Author

Sorry, I cannot find a test case that can hit the new segment code I added.

@ggerganov
Copy link
Member

ggerganov commented Jul 6, 2023

I have only brief understanding of how the tokenizer works, so won't be able to help much.
If you observe that your changes match the results of the original implementation then we can merge.

Maybe we can add even more test cases to the test-tokenizer-0 - why not even generate a bunch of random strings / bytes and verify that we produce the same tokens as the reference implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants