Skip to content

spec token map lazy. #2715

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

Merged
merged 1 commit into from
Jul 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fastdeploy/input/ernie_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def __init__(
self.sp_model = spm.SentencePieceProcessor()
self.sp_model.Load(vocab_file)
# pre-process map-type all spec token for decode accelerate.
self.all_spec_tok = set(self.all_special_tokens)

@property
def space_token(self):
Expand Down Expand Up @@ -138,8 +137,13 @@ def _convert_id_to_token(self, id):
"""doc"""
return self.sp_model.id_to_piece(id)

def spec_init(self):
if not hasattr(self, "all_spec_tok"):
self.all_spec_tok = set(self.all_special_tokens)

def convert_tokens_to_string(self, tokens):
"""Converts a sequence of tokens (string) in a single string."""
spec_init()
current_sub_tokens = []
out_string = ""
# prev_is_special = False
Expand Down Expand Up @@ -212,6 +216,7 @@ def tokenize(self, text: TextInput, **kwargs) -> List[str]:
# if isinstance(t, AddedToken)
# )

spec_init()
text, kwargs = self.prepare_for_tokenization(text, **kwargs)

# TODO: should this be in the base class?
Expand Down
Loading