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 Sequence-Level KD #2220

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update dpo.py
Add the third issue fixs
  • Loading branch information
mst272 authored Aug 16, 2024
commit 36b6a6b922aa0972c72ba402197f36b2af0b5c96
10 changes: 8 additions & 2 deletions examples/scripts/dpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,20 @@
ds[key] = ds[key].select(range(50))

def process(row):
# judge the third issue.
chat_right = True
# judge chat template
prompt = row["chosen"][:-1]
chosen = [row["chosen"][-1]]
test_prompt = tokenizer.apply_chat_template(prompt, tokenize=False)
test_chosen = tokenizer.apply_chat_template(chosen, tokenize=False)
try:
test_chosen = tokenizer.apply_chat_template(chosen, tokenize=False)
except Exception as e:
chat_right = False
conversation = copy.deepcopy(prompt)
conversation.append(row["chosen"][-1])
if tokenizer.apply_chat_template(conversation) == test_prompt + test_chosen:
# the chat_right is for the third issue, the subsequent checks is for the first and second issues.
if chat_right and tokenizer.apply_chat_template(conversation) == test_prompt + test_chosen:
row["prompt"] = tokenizer.apply_chat_template(row["chosen"][:-1], tokenize=False)
row["chosen"] = tokenizer.apply_chat_template([row["chosen"][-1]], tokenize=False)
row["rejected"] = tokenizer.apply_chat_template([row["rejected"][-1]], tokenize=False)
Expand Down