-
Notifications
You must be signed in to change notification settings - Fork 33.8k
[vllm + v5 fix] handle TokenizersBackend fallback properly for v5 #44255
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
Changes from 27 commits
7db5290
5ef0061
7be0c57
1d22701
43a07e1
ffb5f09
c1a3a0d
4307831
1bbe257
b5d0bad
b7547e4
f5fd840
2b9efdf
e141166
ae25381
77120a2
3b053b0
a5542cc
95bba6c
7d46f77
be29c60
53753c3
4745745
cbda0ca
e5c8a2f
8bf6df0
df12cc4
08b91c6
a7c2435
d5e9aba
ceeb319
b512fc7
0c95842
34d83ed
5c8af86
4d06871
2159e92
db0c5b5
31ff32d
083ec50
a4fc098
2710fad
969c0fc
47a772a
8039c2b
e3d3025
6edc1d3
dade5e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -635,6 +635,54 @@ class SpmConverter(Converter): | |
| SpmExtractor = SentencePieceExtractor | ||
| special_tokens = {} | ||
|
|
||
| @staticmethod | ||
| def build_tokenizer_from_spm_proto(proto, vocab, merges=None): | ||
| """ | ||
| Similar to convert_from_spm method, but used only when there is no `model_type` class, i.e. there is no matching class in `TOKENIZERS_MAPPING` and we just create a tokenizer instead of extracting stuff from the sentencepiece file | ||
| """ | ||
| byte_fallback = proto.trainer_spec.byte_fallback | ||
| unk_piece = proto.trainer_spec.unk_piece | ||
| precompiled_charsmap = proto.normalizer_spec.precompiled_charsmap | ||
|
|
||
| # model | ||
| if isinstance(vocab, dict): | ||
| tokenizer = Tokenizer( | ||
| BPE( | ||
| vocab=vocab, | ||
| merges=merges or [], | ||
| unk_token=unk_piece, | ||
| fuse_unk=True, | ||
| byte_fallback=byte_fallback, | ||
| dropout=None, | ||
| ) | ||
| ) | ||
| elif isinstance(vocab, list) and vocab and isinstance(vocab[0], (tuple, list)): | ||
| tokenizer = Tokenizer( | ||
| Unigram( | ||
| vocab=vocab, | ||
| unk_id=proto.trainer_spec.unk_id, | ||
| byte_fallback=byte_fallback, | ||
| ) | ||
| ) | ||
| else: | ||
| return None | ||
|
|
||
| # normalizer | ||
| _normalizers = [normalizers.Replace(" ", "▁")] | ||
| if precompiled_charsmap: | ||
| _normalizers.insert(0, normalizers.Precompiled(precompiled_charsmap)) | ||
| tokenizer.normalizer = normalizers.Sequence(_normalizers) | ||
|
|
||
| # decoder | ||
| if byte_fallback: | ||
| tokenizer.decoder = decoders.Sequence( | ||
| [decoders.Replace("▁", " "), decoders.ByteFallback(), decoders.Fuse()] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split digits, split on whitespace etc could be etracted as well! |
||
| ) | ||
| else: | ||
| tokenizer.decoder = decoders.Sequence([decoders.Replace("▁", " ")]) | ||
|
|
||
| return tokenizer | ||
|
|
||
| @classmethod | ||
| def convert_from_spm(cls, vocab=None, **kwargs): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,13 +80,7 @@ def __init__( | |
|
|
||
| # Set normalizer and pre-tokenizer to mimic OpenAI GPT behavior | ||
| # OpenAI GPT uses BERT BasicTokenizer with lower_case=True | ||
| self._tokenizer.normalizer = normalizers.Sequence( | ||
| [ | ||
| normalizers.NFD(), | ||
| normalizers.Lowercase(), | ||
| normalizers.StripAccents(), | ||
| ] | ||
| ) | ||
| self._tokenizer.normalizer = normalizers.BertNormalizer(lowercase=True) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch |
||
|
|
||
| self._tokenizer.pre_tokenizer = pre_tokenizers.BertPreTokenizer() | ||
| self._tokenizer.decoder = decoders.BPEDecoder(suffix="</w>") | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -normalizer: Sequence(normalizers=[Strip(strip_left=False, strip_right=True), Replace(pattern=Regex(" {2,}"), content="▁"), Precompiled(precompiled_charsmap="...")])
-pre_tokenizer: Metaspace(replacement="▁", prepend_scheme=always, split=True)
+normalizer: Precompiled(precompiled_charsmap="...")
+pre_tokenizer: Sequence(pretokenizers=[WhitespaceSplit(), Metaspace(replacement="▁", prepend_scheme=always, split=True)])is what most T5 have as an issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's only for some model not all of them (ex gpt2 uses
Ġ)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah MB, sentencepiece never used
Ġ!So ignore this comment probably