Skip to content

Refactor Online DPO#1839

Merged
lewtun merged 103 commits intomainfrom
online-dpo-llmjudge
Aug 28, 2024
Merged

Refactor Online DPO#1839
lewtun merged 103 commits intomainfrom
online-dpo-llmjudge

Conversation

@vwxyzjn
Copy link
Contributor

@vwxyzjn vwxyzjn commented Jul 17, 2024

This PR refactors the OnlineDPOTrainer to have an API that is closer to that of the offlineDPOTrainer. It also introduces a LogCompletionsCallback that produces a table of completions on WandB

@vwxyzjn vwxyzjn requested a review from qgallouedec July 17, 2024 03:04
@qgallouedec
Copy link
Member

qgallouedec commented Jul 18, 2024

After this one is merged #1598 we'll probably only need to do

 trainer = OnlineDPOTrainer(..., judge=OpenAIJudge())

EDIT: The PR has gone in another direction, we'll integrate the judges later.

@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.

Base automatically changed from online-trainer-refactor to main July 18, 2024 18:35
@lewtun
Copy link
Member

lewtun commented Aug 27, 2024

I've tested the code works as intended for the TL;DR experiments of 1B and 2.8B and 6.9B:

# 1B - fits with DDP
accelerate launch --config_file examples/accelerate_configs/multi_gpu.yaml \
    examples/scripts/dpo_online.py \
    --model_name_or_path trl-lib/pythia-1b-deduped-tldr-sft  \
    --reward_model_path trl-lib/pythia-1b-deduped-tldr-rm \
    --dataset_name trl-lib/tldr \
    --learning_rate 5.0e-7 \
    --output_dir pythia-1b-deduped-tldr-online-dpo \
    --beta 0.1 \
    --per_device_train_batch_size 8 \
    --gradient_accumulation_steps 2 \
    --num_train_epochs 3 \
    --max_new_tokens 53 \
    --warmup_ratio 0.1 \
    --missing_eos_penalty 1.0 \
    --logging_steps 20 \
    --save_steps 0.1 \
    --push_to_hub

# 2.8B - fits with ZeRO-2
accelerate launch --config_file examples/accelerate_configs/deepspeed_zero2.yaml \
    examples/scripts/dpo_online.py \
    --model_name_or_path trl-lib/pythia-2.8b-deduped-tldr-sft  \
    --reward_model_path trl-lib/pythia-2.8b-deduped-tldr-rm \
    --dataset_name trl-lib/tldr \
    --learning_rate 5.0e-7 \
    --output_dir pythia-2.8b-deduped-tldr-online-dpo \
    --beta 0.1 \
    --per_device_train_batch_size 8 \
    --gradient_accumulation_steps 2 \
    --num_train_epochs 3 \
    --max_new_tokens 53 \
    --warmup_ratio 0.1 \
    --missing_eos_penalty 1.0 \
    --bf16 \
    --logging_steps 20 \
    --save_steps 0.1 \
    --push_to_hub

# 6.9B - fits with ZeRO-2 and gradient checkpointing
accelerate launch --config_file examples/accelerate_configs/deepspeed_zero2.yaml \
    examples/scripts/dpo_online.py \
    --model_name_or_path trl-lib/pythia-6.9b-deduped-tldr-sft  \
    --reward_model_path trl-lib/pythia-6.9b-deduped-tldr-rm \
    --dataset_name trl-lib/tldr \
    --learning_rate 5.0e-7 \
    --output_dir pythia-6.9b-deduped-tldr-online-dpo \
    --beta 0.1 \
    --per_device_train_batch_size 4 \
    --gradient_accumulation_steps 4 \
    --num_train_epochs 3 \
    --max_new_tokens 53 \
    --warmup_ratio 0.1 \
    --missing_eos_penalty 1.0 \
    --bf16 \
    --gradient_checkpointing \
    --logging_steps 20 \
    --save_steps 0.1 \
    --push_to_hub

What is currently not working is the ZeRO-3, which produces a deadlock in the LogCompletionsCallback. I am not sure exactly why this is happening, but we can leave it for a follow-up PR

lewtun and others added 2 commits August 27, 2024 20:24
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
Copy link
Collaborator

@edbeeching edbeeching left a comment

Choose a reason for hiding this comment

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

One minor comment, otherwise LGTM. Thanks.

@lewtun lewtun merged commit e755eee into main Aug 28, 2024
@lewtun lewtun deleted the online-dpo-llmjudge branch August 28, 2024 13:39
yxliu-TAMU pushed a commit to mincheolseong/ECEN743-GRPO-Project-Proposal that referenced this pull request Apr 20, 2025
* online dpo trainer based on rloo trainer

* push changes

* refactor

* use `batch_generation` method

* precommit

* remove breakpoint()

* quick refactor

* push the current changes

* quick change

* refactor

* use the config name as the experiment name

* fix logging

* update online DPO docs

* use llm as a judge

* quick change

* quick fix

* cache changes

* new semantics

* style and arg order change

* rm duplicated num_epochs

* rm plot script

* num_epoch

* revert some changes

* revert changes

* revert whitespace

* rm whitespace

* revert change

* policy->model

* optional judge and reward model

* cleaning online dpo script

* warning when both reward mdoel and judge provided

* return -1 when the judge fails

* dataset num proc

* add judges in online dpo; fix collate and process within the trainer

* lr_scheduler.step() after optimizer step

* update odpo test

* reduce nestiness

* allow pickle

* generation config typing

* online dpo llm judge

* fix data collator pad token

* add space

* fix pref score

* -1 for judges

* self.model_wrapped = self.model

* onlinedpo inherits from training arguments

* num_epoch -> num_steps_in_epochs

* update -> epoch

* epoch -> step; step_in_epoch -> ppo_epoch; rm run_name

* num_steps_in_epoch -> num_ppo_epochs

* epoch_idx -> ppo_epoch_idx

* make init consistent with dpo

* try another option

* progress...

* odpo

* current progress

* log and other changes

* rename for legacy

* rename for legacy

* rename and move truncate

* rename

* new config

* LogCompletionsCallback

* style

* rename trainer

* truncate right in utils

* update example

* reward model path

* properly log

* fix example

* add generation prompt and log special tokens

* true penalty

* defaults from the paper

* Remove MPS (huggingface#1983)

* Set KV cache false when gradient checkpointing is enabled (huggingface#1984)

* Remove MPS

* Fix

* Various tweask

* Remove padding from table

* Clean up

* Fix test

* Revert log freq

* Fix docs

* Fix tests aain!

* Fix typo

* Revert

* Fix regression

* Apply suggestions from code review

Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>

* Fix DPO config test

* Fix doc tree

* Clean docs moar

* Add docstring

* raise NotImplemented error for judge

* Refactor cache clearning

---------

Co-authored-by: Michael Noukhovitch <mnoukhov@gmail.com>
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
Co-authored-by: Quentin Gallouédec <quentin.gallouedec@huggingface.co>
Co-authored-by: lewtun <lewis.c.tunstall@gmail.com>
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.

7 participants