Merge pull request #1436 from lvzii/main

fix tokenizer config changed after pretrain
This commit is contained in:
hoshi-hiyouga 2023-11-09 14:30:50 +08:00 committed by GitHub
commit 7ca32d8e69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -47,9 +47,13 @@ def preprocess_dataset(
kwargs = dict(add_special_tokens=True)
if hasattr(tokenizer, "add_eos_token"): # for LLaMA tokenizer
add_eos_token_flag = getattr(tokenizer, "add_eos_token")
setattr(tokenizer, "add_eos_token", True)
tokenized_examples = tokenizer(examples["prompt"], **kwargs)
# Make sure the saved tokenizer is the same as the original
if hasattr(tokenizer, "add_eos_token"): # for Baichuan2 tokenizer
setattr(tokenizer, "add_eos_token", add_eos_token_flag)
concatenated_examples = {k: list(chain(*tokenized_examples[k])) for k in tokenized_examples.keys()}
total_length = len(concatenated_examples[list(concatenated_examples.keys())[0]])
block_size = data_args.cutoff_len