-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kushalkodnad/tokenizer-registry] Introduce new registry for tokenize…
…rs (#1386)
- Loading branch information
1 parent
cefd616
commit 51949c4
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
# Copyright 2022 MosaicML LLM Foundry authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from llmfoundry.registry import tokenizers | ||
from llmfoundry.tokenizers.tiktoken import TiktokenTokenizerWrapper | ||
|
||
tokenizers.register('tiktoken', func=TiktokenTokenizerWrapper) | ||
|
||
__all__ = [ | ||
'TiktokenTokenizerWrapper', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2024 MosaicML LLM Foundry authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import Any, Dict, Optional | ||
|
||
from transformers import PreTrainedTokenizer | ||
|
||
from llmfoundry.registry import tokenizers | ||
from llmfoundry.utils import build_tokenizer | ||
|
||
|
||
class DummyTokenizer(PreTrainedTokenizer): | ||
"""A dummy tokenizer that inherits from ``PreTrainedTokenizer``.""" | ||
|
||
def __init__( | ||
self, | ||
model_name: Optional[str] = 'dummy', | ||
**kwargs: Optional[Dict[str, Any]], | ||
): | ||
"""Dummy constructor that has no real purpose.""" | ||
super().__init__( | ||
model_name=model_name, | ||
eos_token='0', | ||
pad_token='1', | ||
**kwargs, | ||
) | ||
|
||
def get_vocab(self) -> Dict[str, int]: | ||
return {} | ||
|
||
|
||
def test_tokenizer_registry(): | ||
tokenizers.register('dummy', func=DummyTokenizer) | ||
tokenizer = build_tokenizer(tokenizer_name='dummy', tokenizer_kwargs={}) | ||
assert type(tokenizer) == DummyTokenizer |