Skip to content

Commit

Permalink
Fix apply_chat_template function for dpo and unknown task (#30)
Browse files Browse the repository at this point in the history
* Fix `apply_chat_template` function for `dpo` and unknown `task`

* Remove duplicated `# coding=utf-8`

* Manually run `black --line-length 119`
  • Loading branch information
alvarobartt authored Nov 21, 2023
1 parent 7d6fe76 commit c9d9035
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/alignment/configs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding=utf-8
# coding=utf-8
# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
12 changes: 7 additions & 5 deletions src/alignment/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding=utf-8
# coding=utf-8
# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -72,12 +71,15 @@ def _strip_prefix(s, pattern):
example["text_prompt"] = tokenizer.apply_chat_template(
prompt_messages, tokenize=False, add_generation_prompt=True
)

example["text_chosen"] = _strip_prefix(example["text_chosen"], assistant_prefix)
example["text_rejected"] = _strip_prefix(example["text_rejected"], assistant_prefix)
example["text_chosen"] = _strip_prefix(example["text_chosen"], assistant_prefix)
example["text_rejected"] = _strip_prefix(example["text_rejected"], assistant_prefix)
else:
raise ValueError(
f"Could not format example as dialogue for `dpo` task! Require `[chosen, rejected]` keys but found {list(example.keys())}"
)
else:
raise ValueError(
f"Could not format example as dialogue for `dpo` task! Require `[chosen, rejected]` keys but found {list(example.keys())}"
f"Task {task} not supported, please ensure that the provided task is one of {['sft', 'generation', 'rm', 'dpo']}"
)
return example

Expand Down
1 change: 0 additions & 1 deletion src/alignment/model_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding=utf-8
# coding=utf-8
# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down

0 comments on commit c9d9035

Please sign in to comment.