Skip to content
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

Support GLM Edge and ModernBERT #356

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion python/openvino_tokenizers/hf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def tokenization_model(self) -> None:
"TemplateProcessing": CombineSegmentsStep.from_hf_json_template_postprocessor,
"BertProcessing": CombineSegmentsStep.from_hf_json_bert_postprocessor,
"RobertaProcessing": CombineSegmentsStep.from_hf_json_roberta_processor,
"ByteLevel": lambda *args: list(), # return no handle for ByteLevel so add_steps skips it
}

def post_tokenization(self) -> None:
Expand Down Expand Up @@ -315,7 +316,7 @@ def post_tokenization(self) -> None:
post_processor_json, self.number_of_inputs, self.add_special_tokens
)

self.num_of_added_tokens += combine_segments_step.number_of_added_tokens
self.num_of_added_tokens += getattr(combine_segments_step, "number_of_added_tokens", 0)

self.add_truncation()
self.pipeline.add_steps(combine_segments_step)
Expand Down
7 changes: 6 additions & 1 deletion python/openvino_tokenizers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ def unicode_to_bytes() -> Dict[str, int]:

def apply_unicode_to_bytes(token: str) -> str:
bytes_encoder = unicode_to_bytes()
return bytes(bytes_encoder[char] for char in token)
try:
return bytes(bytes_encoder[char] for char in token)
except KeyError:
# tokens that was not bytes-to-chars encoded
# ModernBERT adds such tokens to the vocab directly, which is wrong, but we need to handle it
return token


def get_hf_tokenizer_attribute(
Expand Down
Loading