-
Notifications
You must be signed in to change notification settings - Fork 55
Update the example of human in the loop #247
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
141294f
+ add & update example of human in the loop
HYLcool dc599d9
* after pre-commit
HYLcool 07191d5
* modified according to gemini's comments
HYLcool eb90807
* modified according to xuchen's comments
HYLcool 22db0c7
Merge branch 'refs/heads/main' into example/human_in_the_loop
HYLcool 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 hidden or 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 hidden or 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,7 @@ | ||
| # DPO with Human in the Loop | ||
|
|
||
| This example shows the usage of DPO with human in the loop on a simple example dataset. | ||
|
|
||
| For more detailed information, please refer to the [documentation](../../docs/sphinx_doc/source/tutorial/example_data_functionalities.md#example-human-in-the-loop). | ||
|
|
||
| The config files are located in [`dpo.yaml`](dpo.yaml) and [`train_dpo.yaml`](train_dpo.yaml). The example dataset is located in [`demo_data.jsonl`](demo-data.jsonl). |
This file contains hidden or 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,10 @@ | ||
| {"prompt": "What is the capital of France?", "answer1": "Paris", "answer2": "Lyon"} | ||
| {"prompt": "Which planet is known as the Red Planet?", "answer1": "Mars", "answer2": "Venus"} | ||
| {"prompt": "What is the chemical symbol for gold?", "answer1": "Au", "answer2": "Ag"} | ||
| {"prompt": "Who wrote 'Romeo and Juliet'?", "answer1": "William Shakespeare", "answer2": "Christopher Marlowe"} | ||
| {"prompt": "What is the largest mammal on Earth?", "answer1": "Blue Whale", "answer2": "African Elephant"} | ||
| {"prompt": "In which year did World War II end?", "answer1": "1945", "answer2": "1944"} | ||
| {"prompt": "What is the square root of 64?", "answer1": "8", "answer2": "6"} | ||
| {"prompt": "Who painted the Mona Lisa?", "answer1": "Leonardo da Vinci", "answer2": "Michelangelo"} | ||
| {"prompt": "What is the main component of the Sun?", "answer1": "Hydrogen", "answer2": "Helium"} | ||
| {"prompt": "Which programming language was created by Guido van Rossum?", "answer1": "Python", "answer2": "Java"} |
This file contains hidden or 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,73 @@ | ||
| project: "dpo_example" | ||
| name: "trinity_dpo" | ||
| mode: train | ||
|
|
||
| # using task pipeline to decide the chosen and rejected from human preference | ||
| data_processor: | ||
| # task pipeline related | ||
| task_pipeline: | ||
| num_process: 1 | ||
| operators: | ||
| - name: "human_preference_annotation_mapper" | ||
| args: | ||
| # general annotation project settings | ||
| project_name_prefix: "Human_Preference_Annotation_Demo" | ||
| wait_for_annotations: true # Whether to wait for annotations to complete | ||
| timeout: 3600 # Maximum time to wait for annotations in seconds (1 hour) | ||
| poll_interval: 10 # Time between annotation status checks in seconds | ||
| max_tasks_per_batch: 10 # Maximum number of tasks in a single batch | ||
| notification_config: | ||
| enabled: false | ||
|
|
||
| # label studio connection settings | ||
| api_url: "http://localhost:7070" # Default Label Studio URL | ||
| api_key: "YOUR_API_KEY" # Your API key for label studuio authentication, which can be set when starting the label-studio service | ||
|
|
||
| # human preference annotation settings | ||
| prompt_key: "prompt" # Prompt field | ||
| answer1_key: "answer1" # First answer option | ||
| answer2_key: "answer2" # Second answer option | ||
| chosen_key: "chosen" # Chosen field | ||
| rejected_key: "rejected" # Rejected field | ||
| inputs: # the output will be set to the explorer input automatically | ||
| - 'examples/dpo_human_in_the_loop/demo-data.jsonl' | ||
| target_fields: ["prompt"] | ||
| service: | ||
| data_juicer: | ||
| auto_start: true | ||
|
|
||
| algorithm: | ||
| algorithm_type: dpo | ||
| kl_loss_fn: k1 | ||
| kl_loss_fn_args: | ||
| kl_coef: 0.1 | ||
| checkpoint_root_dir: /PATH/TO/CHECKPOINT/ | ||
| model: | ||
| model_path: /PATH/TO/MODEL | ||
| max_response_tokens: 1024 | ||
| max_model_len: 1536 | ||
| cluster: | ||
| node_num: 1 | ||
| gpu_per_node: 8 | ||
| buffer: | ||
| total_epochs: 2 | ||
| train_batch_size: 64 | ||
| trainer_input: | ||
| experience_buffer: | ||
| name: dpo_buffer | ||
| storage_type: file | ||
| enable_progress_bar: True | ||
| path: ./outputs/human_annotation_output/ # the result data after human preference annotation are stored here | ||
| format: | ||
| prompt_type: plaintext # plaintext/messages | ||
| prompt_key: prompt | ||
| chosen_key: chosen | ||
| rejected_key: rejected | ||
| synchronizer: | ||
| sync_method: 'checkpoint' | ||
| sync_interval: 30 | ||
| sync_timeout: 1200 | ||
| trainer: | ||
| trainer_type: 'verl' | ||
| trainer_config_path: 'examples/dpo_human_in_the_loop/train_dpo.yaml' | ||
| save_interval: 30 |
This file contains hidden or 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,51 @@ | ||
| actor_rollout_ref: | ||
| hybrid_engine: True | ||
| model: | ||
| external_lib: null | ||
| override_config: { } | ||
| enable_gradient_checkpointing: True | ||
| use_remove_padding: False | ||
| actor: | ||
| strategy: fsdp # This is for backward-compatibility | ||
| ppo_micro_batch_size_per_gpu: 2 | ||
| use_dynamic_bsz: False | ||
| ppo_max_token_len_per_gpu: 16384 | ||
| grad_clip: 1.0 | ||
| ppo_epochs: 1 | ||
| shuffle: False | ||
| ulysses_sequence_parallel_size: 1 # sp size | ||
| optim: | ||
| lr: 5e-7 | ||
| lr_warmup_steps_ratio: 0.03 # the total steps will be injected during runtime | ||
| min_lr_ratio: 0.1 # only useful for warmup with cosine | ||
| warmup_style: cosine # select from constant/cosine | ||
| total_training_steps: 783 | ||
| betas: [0.9, 0.95] | ||
| fsdp_config: | ||
| wrap_policy: | ||
| # transformer_layer_cls_to_wrap: None | ||
| min_num_params: 0 | ||
| param_offload: False | ||
| optimizer_offload: False | ||
| fsdp_size: -1 | ||
| ref: | ||
| fsdp_config: | ||
| param_offload: False | ||
| wrap_policy: | ||
| # transformer_layer_cls_to_wrap: None | ||
| min_num_params: 0 | ||
| # log_prob_micro_batch_size: 4 # will be deprecated, use log_prob_micro_batch_size_per_gpu | ||
| log_prob_micro_batch_size_per_gpu: 2 | ||
| log_prob_use_dynamic_bsz: ${actor_rollout_ref.actor.use_dynamic_bsz} | ||
| log_prob_max_token_len_per_gpu: ${actor_rollout_ref.actor.ppo_max_token_len_per_gpu} | ||
| ulysses_sequence_parallel_size: ${actor_rollout_ref.actor.ulysses_sequence_parallel_size} # sp size | ||
|
|
||
| trainer: | ||
| balance_batch: False | ||
| total_training_steps: 783 | ||
| # auto: find the last ckpt to resume. If can't find, start from scratch | ||
| resume_mode: auto # or auto or resume_path if | ||
| default_hdfs_dir: null | ||
| remove_previous_ckpt_in_save: False | ||
| del_local_ckpt_after_load: False | ||
| val_before_train: False |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.