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 support for HF tokenizer in global args #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 3 additions & 0 deletions megatron/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,11 @@ def _add_data_args(parser):
'GPT2BPETokenizer',
'SentencePieceTokenizer',
'GPTSentencePieceTokenizer',
'HFAutoTokenizer',
'NullTokenizer'],
help='What type of tokenizer to use.')
group.add_argument('--hf_autotokenizer_model', type=str, default=None,
help='Name of HF tokenizer model.')
group.add_argument('--tokenizer-model', type=str, default=None,
help='Sentencepiece tokenizer model.')
group.add_argument('--data-impl', type=str, default='infer',
Expand Down
3 changes: 1 addition & 2 deletions megatron/tokenizer/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from .bert_tokenization import FullTokenizer as FullBertTokenizer
from .gpt2_tokenization import GPT2Tokenizer

from transformers import AutoTokenizer

def build_tokenizer(args):
"""Initialize tokenizer."""
if args.rank == 0:
Expand Down Expand Up @@ -137,6 +135,7 @@ class _HFAutoTokenizer(AbstractTokenizer):
def __init__(self, pretrained_model_name_or_path: str):
name = "HFAutoTokenizer"
super().__init__(name)
from transformers import AutoTokenizer
self.tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path)
self.tokenizer.add_special_tokens({"pad_token": "<|padding|>"})
self.eod_id = self.tokenizer.eos_token_id
Expand Down