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

Conversational dataset support for DPOTrainer #2131

Merged
merged 39 commits into from
Oct 2, 2024

Conversation

qgallouedec
Copy link
Member

@qgallouedec qgallouedec commented Sep 26, 2024

What does this PR do?

Part of #2071

It includes:

  • Overwriting the default learning rate of TrainingArguments, so that the user can just use it with the default values. (same as [KTO] learning rate recomentations for kto #2070)
  • Extending extract_prompt to support standard dataset.
  • Add some doc about vision datasets
  • Add script for RLAIF-V dataset generation

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment on lines +291 to +293
if example["chosen"][idx] != example["rejected"][idx]:
if example["chosen"][idx - 1] == " ": # remove space before the prompt
idx -= 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str1 = "I am Quentin"
str2 = "I am in Lyon"
# What we want:
prompt = "I am"
# What we don't want:
prompt = "I am "

That's why, when the prompt ends with a space, we take idx-1 instead.

@qgallouedec qgallouedec marked this pull request as ready for review September 30, 2024 12:25
Copy link
Member

@lewtun lewtun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice clean up of the DPO preprocessing and docs 🔥. Great stuff @qgallouedec !

I know we don't currently have any proper regression tests, but WDYT about running the dpo.py script on main and this branch to sanity check the margins / loss look ok before merging?

docs/source/dataset_formats.mdx Show resolved Hide resolved
docs/source/dpo_trainer.mdx Outdated Show resolved Hide resolved

Note that the `beta` is the temperature parameter for the DPO loss, typically something in the range of `0.1` to `0.5`. We ignore the reference model as `beta` -> 0.
To see how the [trained model](https://huggingface.co/trl-lib/dpo-qwen2) performs, use the following code to generate completions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about using trl chat here as a nice demo to show users it exists?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

image

docs/source/dpo_trainer.mdx Show resolved Hide resolved
trl/trainer/dpo_config.py Show resolved Hide resolved
docs/source/dpo_trainer.mdx Outdated Show resolved Hide resolved
docs/source/dpo_trainer.mdx Outdated Show resolved Hide resolved
@qgallouedec
Copy link
Member Author

qgallouedec commented Oct 2, 2024

accelerate launch examples/scripts/dpo.py \
    --dataset_name trl-lib/ultrafeedback_binarized \
    --model_name_or_path Qwen/Qwen2-0.5B-Instruct \
    --learning_rate 5.0e-7 \
    --num_train_epochs 1 \
    --per_device_train_batch_size 2 \
    --gradient_accumulation_steps 8 \
    --gradient_checkpointing \
    --logging_steps 25 \
    --eval_strategy steps \
    --eval_steps 50 \
    --output_dir Qwen2-0.5B-DPO-main \
    --no_remove_unused_columns

https://wandb.ai/huggingface/huggingface/runs/b499t4i2
https://wandb.ai/huggingface/huggingface/runs/jqdy51ld

Screenshot 2024-10-02 at 09 41 25

@qgallouedec qgallouedec merged commit 78249d9 into main Oct 2, 2024
3 checks passed
@qgallouedec qgallouedec deleted the dpo-conversational-dataset branch October 2, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants