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

Add ChatML special tokens to GPT-4 tokenizer #689

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 10 additions & 1 deletion llmfoundry/tokenizers/tiktoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ def __init__(self,
self.model_name = model_name
self.encoding_name = encoding_name

if self.model_name is not None:
if self.model_name == 'gpt-4-chatml':
# this is the gpt-4 tokenizer with two additional special tokens
from tiktoken_ext.openai_public import cl100k_base

encoding_kwargs = cl100k_base()
encoding_kwargs['name'] = encoding_kwargs['name'].replace('base', 'chat')
encoding_kwargs['special_tokens']['<|im_start|>'] = 100261
encoding_kwargs['special_tokens']['<|im_end|>'] = 100262
self.encoding = tiktoken.Encoding(**encoding_kwargs)
elif self.model_name is not None:
self.encoding = tiktoken.encoding_for_model( # type: ignore (thirdParty)
self.model_name)
elif self.encoding_name is not None:
Expand Down
Loading