-
Notifications
You must be signed in to change notification settings - Fork 172
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
Synthetic preference dataset #332
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8934de7
push changes
vwxyzjn 5a200b6
Support hf revision when generating
vwxyzjn 6b6d8fe
style an quality
vwxyzjn 63d360b
Merge branch 'support-revision-when-generate' into synthetic-preferen…
vwxyzjn 0452b80
Merge branch 'main' into synthetic-preference-dataset
vwxyzjn f845433
add synthetic preference dataset scripts
vwxyzjn a6ca092
deal with reference generation as part of rejection sampling as well
vwxyzjn be4dbc0
add litellm dependency
vwxyzjn 8b103cf
suppport dataset_mixer_list
vwxyzjn afbd376
Add openai api key to useful secretes
vwxyzjn 2dbae58
style and quality
vwxyzjn 362b19a
quick push
vwxyzjn 0f28139
add reference
vwxyzjn 6c5c7ea
quick update
vwxyzjn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Synthetic preference dataset | ||
|
||
This section focuses explicitly on creating synthetic preference datasets. | ||
|
||
# Debug run (use an interactive session) | ||
|
||
This code supports HF models, local models and also API-based models (e.g., `gpt-4`). For generating completions, the code now accepts one model at a time, but we're working on adding an ensemble of models. Stay tuned. | ||
|
||
```bash | ||
# 1. first sample a bunch of completions given prompts | ||
# Here is an example created dataset: https://huggingface.co/datasets/vwxyzjn/generation_1725567768 | ||
python open_instruct/rejection_sampling/generation.py \ | ||
--dataset_mixer_list HuggingFaceH4/no_robots 100 \ | ||
--dataset_splits train \ | ||
--model_name_or_path allenai/llama-3-tulu-2-8b \ | ||
--num_completions 3 \ | ||
--save_filename output/completions.jsonl \ | ||
--sanity_check \ | ||
--push_to_hub | ||
``` | ||
|
||
### Create preference pairs | ||
|
||
```bash | ||
# 2.1 do LLM as a judge to create synthetic preference dataset | ||
# Here is an example created dataset: https://huggingface.co/datasets/vwxyzjn/synthetic_preference_dataset_1725567862 | ||
python open_instruct/rejection_sampling/synthetic_preference_dataset.py \ | ||
--input_filename output/completions.jsonl \ | ||
--model gpt-4o-2024-08-06 \ | ||
--save_filename output/synthetic_preferences.jsonl \ | ||
--num_completions 3 \ | ||
--push_to_hub \ | ||
``` | ||
|
||
|
||
You can visualize the dataset via | ||
|
||
```bash | ||
python -m costa_utils.hf_viz \ | ||
--sft vwxyzjn/synthetic_preference_dataset_1725567862 \ | ||
--split train \ | ||
--sft_messages_column_name whole_conversation | ||
|
||
python -m costa_utils.hf_viz \ | ||
--preference vwxyzjn/synthetic_preference_dataset_1725567862 \ | ||
--split train \ | ||
--preference_chosen_column_name chosen \ | ||
--preference_rejected_column_name rejected | ||
``` | ||
|
||
![synthetic_preference_dataset](synthetic_preference_dataset.png) | ||
|
||
# Run through the entire dataset run | ||
|
||
To run through the entire dataset you would need a lot more GPUs to finish the generation more quickly. | ||
|
||
|
||
```bash | ||
# NOTE: the scripts below only generate 400 prompts, so it's for demonstration purposes only. The scripts are highly scalable, and you could modify its `num_prompts=400` to something else like 300000 for the tulu dataset. | ||
|
||
# you need to make sure your default beaker workspace has WANDB_API_KEY and HF_TOKEN secrets in them | ||
beaker secret write HF_TOKEN xxxxxxxxxxxx | ||
beaker secret write WANDB_API_KEY xxxxxxxxxxx | ||
|
||
# Docker mode: using caches from WEKA | ||
deploy_mode="docker_weka" bash scripts/synthetic_preference_dataset.bash | ||
|
||
# Docker mode: using caches from NFS | ||
deploy_mode="docker_nfs" bash scripts/synthetic_preference_dataset.bash | ||
|
||
# Docker mode: do not use caches | ||
deploy_mode="docker" bash scripts/synthetic_preference_dataset.bash | ||
|
||
# If you have environment setup with NFS and want to launch debug mode: | ||
deploy_mode="nfs" bash scripts/synthetic_preference_dataset.bash | ||
``` | ||
|
||
You can see a demo [here](https://drive.google.com/file/d/1dq3KG15ajpOv8tFYEZGS4tlW7G55oOYP/view?usp=sharing) | ||
|
||
<img width="1327" alt="image" src="https://github.com/user-attachments/assets/71a15671-e054-4eab-a571-715881958e74"> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also include BEAKER_TOKEN and OPENAI_API_KEY?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are included via
mason.py
open-instruct/mason.py
Lines 123 to 128 in 2dbae58