Skip to content

Add CPOTrainer#1382

Merged
kashif merged 35 commits into
huggingface:mainfrom
fe1ixxu:cpo-trainer
Mar 22, 2024
Merged

Add CPOTrainer#1382
kashif merged 35 commits into
huggingface:mainfrom
fe1ixxu:cpo-trainer

Conversation

@fe1ixxu

@fe1ixxu fe1ixxu commented Feb 29, 2024

Copy link
Copy Markdown
Contributor

Hi! This PR wants to add CPOTrainer proposed in the paper Contrastive Preference Optimization: Pushing the Boundaries of LLM
Performance in Machine Translation

The CPO method is one of the algorithm for building the state-of-the-art LLM-based translation model: ALMA

@fe1ixxu

fe1ixxu commented Feb 29, 2024

Copy link
Copy Markdown
Contributor Author

cc @kashif @lewtun

@kashif

kashif commented Feb 29, 2024

Copy link
Copy Markdown
Collaborator

@fe1ixxu how close is the trainer in terms of code to the DPOTrainer? Can one subclass from it?

@fe1ixxu

fe1ixxu commented Feb 29, 2024

Copy link
Copy Markdown
Contributor Author

@kashif Thanks for the quick response! CPO is an approximation of DPO. The key differences between CPOTrainer and DPOTrainer are:

  • Remove the need of reference model
  • add an extra NLL loss for preferred data

I'm uncertain whether subclassing CPOTrainer from DPOTrainer is a proper idea, as DPOTrainer introduces numerous features related to reference models that are unnecessary for CPOTrainer.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@fe1ixxu

fe1ixxu commented Mar 7, 2024

Copy link
Copy Markdown
Contributor Author

Hi @kashif CPO docs has been finished now! Thanks!

@kashif kashif requested review from kashif and lewtun March 17, 2024 12:58
@fe1ixxu

fe1ixxu commented Mar 21, 2024

Copy link
Copy Markdown
Contributor Author

Hi @kashif and @lewtun, I see implementation of CPOTrainer has been finished for a while and it has passed all checks. If this looks good to you, is there any chance to merge it to the main branch? Thanks!

@lewtun lewtun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for this very nice implementation of CPO @fe1ixxu 🔥 ! I left a few small comments and a suggestion to remove a deepspeed function I don't think we need. Apart from that LGTM!

Comment thread docs/source/cpo_trainer.mdx Outdated
Comment thread docs/source/cpo_trainer.mdx Outdated
Comment thread trl/trainer/cpo_trainer.py Outdated
Comment thread trl/trainer/cpo_trainer.py
@kashif kashif merged commit d1df79f into huggingface:main Mar 22, 2024
@kashif kashif deleted the cpo-trainer branch March 22, 2024 20:32
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
* add CPOTrainer

* add docs

* fix formatting

* removed precompute_ref_log_probs arg

* remove precompute_ref_log_probs

* typos

* finish cpo trainer doc

* remove redundant lines

* typo

* formatting

* compute chosen nll loss also for enc-dec models

* fix gradient error of inplace operation for enc-dec models

* formatting

* use CPOConfig

* formatting

* use model_init_kwargs from CPOConfig

* comments in example

* fix doc string

* fix typo in docstring

* update year

* fixed typo

* use preference dataset

* fix learning rate

* move dataset_num_proc to configs

* Update cpo paper link from HF: cpo_trainer.mdx

Co-authored-by: lewtun <lewis.c.tunstall@gmail.com>

* update description for CPO: cpo_trainer.mdx

Co-authored-by: lewtun <lewis.c.tunstall@gmail.com>

* remove _prepare_deepspeed for cpo

Because CPO does not need init for reference model

* Add explanation to CPO loss

* format

* fix bug when lengths are given

* add CPOTrainer to README

* fix grammer

---------

Co-authored-by: Kashif Rasul <kashif.rasul@gmail.com>
Co-authored-by: lewtun <lewis.c.tunstall@gmail.com>
yxliu-TAMU pushed a commit to mincheolseong/ECEN743-GRPO-Project-Proposal that referenced this pull request Apr 20, 2025
* add CPOTrainer

* add docs

* fix formatting

* removed precompute_ref_log_probs arg

* remove precompute_ref_log_probs

* typos

* finish cpo trainer doc

* remove redundant lines

* typo

* formatting

* compute chosen nll loss also for enc-dec models

* fix gradient error of inplace operation for enc-dec models

* formatting

* use CPOConfig

* formatting

* use model_init_kwargs from CPOConfig

* comments in example

* fix doc string

* fix typo in docstring

* update year

* fixed typo

* use preference dataset

* fix learning rate

* move dataset_num_proc to configs

* Update cpo paper link from HF: cpo_trainer.mdx

Co-authored-by: lewtun <lewis.c.tunstall@gmail.com>

* update description for CPO: cpo_trainer.mdx

Co-authored-by: lewtun <lewis.c.tunstall@gmail.com>

* remove _prepare_deepspeed for cpo

Because CPO does not need init for reference model

* Add explanation to CPO loss

* format

* fix bug when lengths are given

* add CPOTrainer to README

* fix grammer

---------

Co-authored-by: Kashif Rasul <kashif.rasul@gmail.com>
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.

4 participants