Skip to content

Commit

Permalink
update bos token.
Browse files Browse the repository at this point in the history
  • Loading branch information
shibing624 committed Apr 27, 2024
1 parent 39ba562 commit 2336bfe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions supervised_finetuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,21 @@ def main():
tokenizer = tokenizer_class.from_pretrained(tokenizer_name_or_path, **tokenizer_kwargs)
prompt_template = get_conv_template(script_args.template_name)
if tokenizer.eos_token_id is None:
tokenizer.eos_token = prompt_template.stop_str # eos token is required for SFT
logger.info("Add eos token: {}".format(tokenizer.eos_token))
tokenizer.eos_token = prompt_template.stop_str # eos token is required
tokenizer.add_special_tokens({"eos_token": tokenizer.eos_token})
logger.info(f"Add eos_token: {tokenizer.eos_token}, eos_token_id: {tokenizer.eos_token_id}")
if tokenizer.bos_token_id is None:
tokenizer.add_special_tokens({"bos_token": tokenizer.eos_token})
tokenizer.bos_token_id = tokenizer.eos_token_id
logger.info(f"Add bos_token: {tokenizer.bos_token}, bos_token_id: {tokenizer.bos_token_id}")
if tokenizer.pad_token_id is None:
if tokenizer.unk_token_id is not None:
tokenizer.pad_token = tokenizer.unk_token
else:
tokenizer.pad_token = tokenizer.eos_token
logger.info("Add pad token: {}".format(tokenizer.pad_token))

logger.info(f"Add pad_token: {tokenizer.pad_token}, pad_token_id: {tokenizer.pad_token_id}")
logger.debug(f"Tokenizer: {tokenizer}")

IGNORE_INDEX = LabelSmoother.ignore_index if data_args.ignore_pad_token_for_loss else tokenizer.pad_token_id

# Get datasets
Expand Down

0 comments on commit 2336bfe

Please sign in to comment.