Skip to content

Commit

Permalink
Revert tokenizer changes in train.py (lm-sys#2186)
Browse files Browse the repository at this point in the history
  • Loading branch information
merrymercy authored Aug 8, 2023
1 parent 20f1d6d commit bdac99a
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions fastchat/train/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def preprocess(
padding="max_length",
max_length=tokenizer.model_max_length,
truncation=True,
add_special_tokens=False,
).input_ids
targets = input_ids.clone()

Expand All @@ -118,21 +117,19 @@ def preprocess(
total_len = int(target.ne(tokenizer.pad_token_id).sum())

turns = conversation.split(conv.sep2)
cur_len = 0
cur_len = 1
target[:cur_len] = IGNORE_TOKEN_ID
for i, turn in enumerate(turns):
if turn == "":
break
turn_len = (
len(tokenizer(turn, add_special_tokens=False).input_ids) + 1
) # 1 is </s> token at the end
turn_len = len(tokenizer(turn).input_ids)

parts = turn.split(sep)
if len(parts) != 2:
break
parts[0] += sep
instruction_len = (
len(tokenizer(parts[0], add_special_tokens=False).input_ids) - 1
)
# "-2" is hardcoded for the LLaMA tokenizer to make the offset correct.
instruction_len = len(tokenizer(parts[0]).input_ids) - 2

# Ignore the user instructions
target[cur_len : cur_len + instruction_len] = IGNORE_TOKEN_ID
Expand Down

0 comments on commit bdac99a

Please sign in to comment.