-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
robust incremental decode for leading space (#581)
* robust incremental decode for leading space * speed up lookup as prefix_space_tokens is shorter than no_prefix_space_tokens * add UT and fix qwen stuff
- Loading branch information
Showing
2 changed files
with
48 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
|
||
from lmdeploy.tokenizer import HuggingFaceTokenizer | ||
|
||
|
||
@pytest.mark.parametrize('model_path', [ | ||
'internlm/internlm-chat-7b', 'Qwen/Qwen-7B-Chat', | ||
'baichuan-inc/Baichuan-7B', 'codellama/CodeLlama-7b-hf', | ||
'upstage/SOLAR-0-70b-16bit' | ||
]) | ||
@pytest.mark.parametrize( | ||
'input', ['hi, this is a test 😆😆! ' * 5, '為什麼我還在用繁體字 😆😆 gg! ' * 5]) | ||
def test_tokenizer(model_path, input): | ||
tokenizer = HuggingFaceTokenizer(model_path) | ||
encoded = tokenizer.encode(input) | ||
output = '' | ||
offset = 0 | ||
for i in range(1, len(encoded) + 1): | ||
decoded = tokenizer.decode(encoded[:i], offset) | ||
if decoded.endswith('�'): | ||
continue | ||
output += decoded | ||
offset = i | ||
assert input == output, 'input string should equal to output after enc-dec' |