Skip to content

Commit ec3b5ce

Browse files
authored
Improve detokenization performance (#1338)
1 parent 6368e77 commit ec3b5ce

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

vllm/transformers_utils/tokenizer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ def _convert_tokens_to_string_with_added_encoders(
8181
# even when the loop body is very simple.
8282
sub_texts = []
8383
current_sub_text = []
84+
all_special_tokens = set(tokenizer.all_special_tokens)
8485
for token in output_tokens:
85-
if skip_special_tokens and token in tokenizer.all_special_tokens:
86+
if skip_special_tokens and token in all_special_tokens:
8687
continue
87-
if token in tokenizer.added_tokens_encoder:
88+
if token in tokenizer.get_added_vocab():
8889
if current_sub_text:
8990
sub_text = tokenizer.convert_tokens_to_string(current_sub_text)
9091
sub_texts.append(sub_text)
@@ -129,7 +130,7 @@ def detokenize_incrementally(
129130
# The prefix text is necessary only to defeat cleanup algorithms in
130131
# the decode which decide to add a space or not depending on the
131132
# surrounding ids.
132-
if not getattr(tokenizer, "added_tokens_encoder", {}):
133+
if tokenizer.is_fast or not tokenizer.get_added_vocab():
133134
prefix_text = tokenizer.convert_tokens_to_string(
134135
output_tokens[prefix_offset:read_offset])
135136
new_text = tokenizer.convert_tokens_to_string(

0 commit comments

Comments
 (0)